Skip to content

Instantly share code, notes, and snippets.

@nok
Last active March 16, 2022 16:11
Embed
What would you like to do?
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