Last active
September 11, 2023 04:55
-
-
Save haliphax/c5d8c9b4fe3167d49d416394e4003f2c to your computer and use it in GitHub Desktop.
Gitmoji CLI commit hook
This file contains 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
#!/usr/bin/env bash | |
# install gitmoji as a commit hook | |
# | |
# - uses https://www.npmjs.com/package/gitmoji-cli | |
# - does not require global module installation | |
# - skips hook if message already starts with gitmoji | |
root="$(git rev-parse --show-toplevel)" | |
hook="$root/.git/hooks/prepare-commit-msg" | |
cat >"$hook" <<EOF | |
#!/usr/bin/env bash | |
# gitmoji commit hook | |
# check for skip var | |
if [[ "\$SKIP_GITMOJI_HOOK" != "" ]]; then exit 0; fi | |
# check for existing gitmoji (actually check that first character isn't ASCII) | |
if [[ -f "\$1" ]] && [[ "\$2" == "message" ]] && { | |
[[ "\$(grep -o -P "^[\\x{0000}-\\x{007f}]" <\$1)" == "" ]] | |
} then exit 0; fi | |
# prompt for gitmoji | |
exec </dev/tty | |
npx --package=gitmoji-cli -- gitmoji --hook \$1 \$2 | |
EOF | |
chmod a+x "$hook" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment