Skip to content

Instantly share code, notes, and snippets.

@nok
Last active March 16, 2022 16:11
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save nok/959e0d060893961675b5924948edb52b to your computer and use it in GitHub Desktop.
mkdir -p ~/.git-templates/hooks
rm -f ~/.git-templates/hooks/prepare-commit-msg
cat <<EOT >> ~/.git-templates/hooks/prepare-commit-msg
#!/bin/bash
FILE=\$1
MESSAGE=\$(cat \$FILE)
BRANCH=\$(git branch | grep '*' | sed 's/* //')
TICKET=\$(echo \$BRANCH | grep -Eo '^(DALI-)[0-9]+')
if [[ \$TICKET ]];then
echo "\$MESSAGE (\$TICKET)" > \$FILE
elif [[ ! -z "\$BRANCH" ]];then
BRANCH=\$(echo "\$BRANCH" | sed 's/\(.\{15\}\).*/\1.../')
echo "\$MESSAGE (\$BRANCH)" > \$FILE
fi
EOT
chmod a+x ~/.git-templates/hooks/prepare-commit-msg
git config --global init.templatedir '~/.git-templates'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment