Skip to content

Instantly share code, notes, and snippets.

@ptbrowne
Last active March 2, 2024 12:59
Show Gist options
  • Save ptbrowne/1f5d15fd22e9d72282c6c5457cb05239 to your computer and use it in GitHub Desktop.
Save ptbrowne/1f5d15fd22e9d72282c6c5457cb05239 to your computer and use it in GitHub Desktop.
Automatically add emojis to your commits

To automatically add emojis to your commits, you can use the commit-msg hook.

$ git init
$ ln -s commit-msg-emoji .git/hooks/commit-msg
#!/bin/sh
# the file where the commit message is written
filepath="$1"
tmp_file=$(mktemp /tmp/emoji-commitzen.XXXX)
replacements=(
's/^feat/✨ feat/'
's/^fix/🐝 fix/'
's/^doc/πŸ“š doc/'
's/^style/🎨 style/'
's/^refactor/πŸ”¨ refactor/'
's/^perf/πŸš€ perf/'
's/^chore/πŸ”§ chore/'
's/^lint/πŸ’„ lint/'
's/^test/🚨 test/'
's/^first/🐣 first/'
)
# join replacements by ; to have sed perform multiple replace
sed_command=$(printf "%s;" "${replacements[@]}")
# perform replacements in temp file
cat $filepath | sed "$sed_command" > $tmp_file
# replace commit file
mv $tmp_file $filepath
@MrAlishr
Copy link

MrAlishr commented Mar 2, 2024

how it work on windows?

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