Skip to content

Instantly share code, notes, and snippets.

@anson-vandoren
Last active November 17, 2023 23:15
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 anson-vandoren/52d38af9fd2f2284dd02e200b8d11fe8 to your computer and use it in GitHub Desktop.
Save anson-vandoren/52d38af9fd2f2284dd02e200b8d11fe8 to your computer and use it in GitHub Desktop.
git commit script w/ gum
#!/bin/bash
if ! command -v gum &> /dev/null; then
echo "gum not found. To install:"
echo "sudo mkdir -p /etc/apt/keyrings"
echo "curl -fsSL https://repo.charm.sh/apt/gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/charm.gpg"
echo 'echo "deb [signed-by=/etc/apt/keyrings/charm.gpg] https://repo.charm.sh/apt/ * *" | sudo tee /etc/apt/sources.list.d/charm.list'
echo "sudo apt update && sudo apt install gum"
exit 1
fi
branch_name=$(git symbolic-ref --short HEAD)
pattern="^.+\/(CRIBL-[0-9]+)"
if [[ $branch_name =~ $pattern ]]; then
prefix="${BASH_REMATCH[1]}"
else
echo "Branch name does not match pattern: $pattern"
exit 1
fi
SUMMARY=$(gum input --value "$prefix: " --placeholder "Summary of this change")
pizzazz="dammit|damn|shit|fuck|dafuq|da fuq|bastard"
if ! [[ $SUMMARY =~ $pizzazz ]]; then
if gum confirm "Are you sure you want to commit? This message lacks pizzazz."; then
git commit -m "$SUMMARY"
else
echo "Didn't commit. Try more swearing."
fi
else
git commit -m "$SUMMARY"
echo -e "\033[0;31mGG, ASSHOLE. YOU POLLUTED GIT HISTORY WITH MORE SWEAR WORDS\033[0m"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment