Skip to content

Instantly share code, notes, and snippets.

@nirnejak
Last active June 10, 2024 21:42
Show Gist options
  • Save nirnejak/73a709ce77f51070bce2bd0bef780e7f to your computer and use it in GitHub Desktop.
Save nirnejak/73a709ce77f51070bce2bd0bef780e7f to your computer and use it in GitHub Desktop.
Gum Commit
#!/bin/sh
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 (CTRL+D to finish)")
# Preview
echo "# $SUMMARY" | gum format -t markdown
if [ -n "$DESCRIPTION" ]; then
echo "> $DESCRIPTION" | gum format -t markdown
fi
echo "\n"
# Commit these changes
gum confirm "Commit changes?" && git commit -m "$SUMMARY" -m "$DESCRIPTION"
@javiervivanco
Copy link

# Commit these changes
echo -e "# $SUMMARY \n>  $DESCRIPTION" | gum format -t markdown #preview
gum confirm "Commit changes?" && git commit -m "$SUMMARY" -m "$DESCRIPTION"

@nirnejak
Copy link
Author

nirnejak commented Jun 5, 2024

Good idea to add a preview, updated your code to conditionally render description, if description wasn't present the preview looked weird

# Preview
echo "# $SUMMARY" | gum format -t markdown
if [ -n "$DESCRIPTION" ]; then
  echo "> $DESCRIPTION" | gum format -t markdown
fi
echo "\n"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment