Created
August 1, 2022 15:48
-
-
Save markjaquith/bbb500dfe6d1c4093d5f11f17a8e5bb9 to your computer and use it in GitHub Desktop.
git commit helper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
function maybeBail() { | |
if [[ $? -ne 0 ]]; then | |
exit 1 | |
fi | |
} | |
TYPE=$(gum choose "fix" "feat" "docs" "style" "refactor" "test" "chore" "revert") | |
maybeBail | |
SCOPE=$(gum input --prompt "Scope (optional): " --placeholder "a section of the code, perhaps") | |
maybeBail | |
# 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 --prompt "Summary: " --placeholder "short summary of this change") | |
test -n "$SUMMARY" || (print "Summary is required." && exit 1) | |
DESCRIPTION=$(gum write --placeholder "Details of this change (optional)") | |
test -n "$DESCRIPTION" && DESCRIPTION=" | |
$DESCRIPTION" | |
LINE1="$TYPE$SCOPE: $SUMMARY" | |
LINE2="$DESCRIPTION" | |
MESSAGE="$LINE1$LINE2" | |
gum style \ | |
--foreground 212 --border-foreground 7 --border rounded \ | |
--width 50 \ | |
--padding "1 2" \ | |
"$MESSAGE" | |
# Commit these changes | |
gum confirm "Commit?" && git commit -m "$MESSAGE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment