Skip to content

Instantly share code, notes, and snippets.

@markjaquith
Created August 1, 2022 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markjaquith/bbb500dfe6d1c4093d5f11f17a8e5bb9 to your computer and use it in GitHub Desktop.
Save markjaquith/bbb500dfe6d1c4093d5f11f17a8e5bb9 to your computer and use it in GitHub Desktop.
git commit helper
#!/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