gum/examples/commit.sh
Mathew Payne 83db83296a
Add staged file check for commit example (#269)
* Add staged file check for commit example

* fix: stage all confirmation

---------

Co-authored-by: Maas Lalani <maas@lalani.dev>
2023-02-27 19:19:23 -05:00

29 lines
1.1 KiB
Bash
Executable file

#!/bin/sh
# This script is used to write a conventional commit message.
# It prompts the user to choose the type of commit as specified in the
# conventional commit spec. And then prompts for the summary and detailed
# description of the message and uses the values provided. as the summary and
# details of the message.
#
# If you want to add a simpler version of this script to your dotfiles, use:
#
# alias gcm='git commit -m "$(gum input)" -m "$(gum write)"'
if [ -z "$(git status -s -uno | grep -v '^ ' | awk '{print $2}')" ]; then
gum confirm "Stage all?" && git add .
fi
TYPE=$(gum choose "fix" "feat" "docs" "style" "refactor" "test" "chore" "revert")
SCOPE=$(gum input --placeholder "scope")
# Since the scope is optional, wrap it in parentheses if it has a value.
test -n "$SCOPE" && SCOPE="($SCOPE)"
# Pre-populate the input with the type(scope): so that the user may change it
SUMMARY=$(gum input --value "$TYPE$SCOPE: " --placeholder "Summary of this change")
DESCRIPTION=$(gum write --placeholder "Details of this change")
# Commit these changes if user confirms
gum confirm "Commit changes?" && git commit -m "$SUMMARY" -m "$DESCRIPTION"