Skip to content

Instantly share code, notes, and snippets.

@chalasr
Last active July 18, 2018 18:04
Show Gist options
  • Select an option

  • Save chalasr/e1926e067e8c75d8fcc6 to your computer and use it in GitHub Desktop.

Select an option

Save chalasr/e1926e067e8c75d8fcc6 to your computer and use it in GitHub Desktop.
Beautify git commit message by capitalize message's first letter + prepend issue ID from ref.
#!/bin/bash
# original message
base=$(cat $1)
# ticket patterns
patterns=(ticket- issue- bug-)
# current branch name excluding namespace
current_branch=$(git symbolic-ref --short HEAD | cut -d/ -f2-)
# capitalize message's first char
message=`echo ${base:0:1} | tr '[a-z]' '[A-Z]'`${base:1}
# retrieve ticket number from patterns
i=0;
while [ $i -le 2 ]; do
pattern=${patterns[$i]}
if [ "${current_branch#$pattern}" != "$current_branch" ]; then
ticket=${current_branch#$pattern}
fi
((i++))
done
# prepend number to commit message
if [ -n "$ticket" ]; then
echo "#$ticket $message" > $1
else
echo "$message" > $1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment