Skip to content

Instantly share code, notes, and snippets.

@giuscri
Created August 25, 2022 10:43
Show Gist options
  • Save giuscri/26fe7caf8057eed8227ea9258f6d589f to your computer and use it in GitHub Desktop.
Save giuscri/26fe7caf8057eed8227ea9258f6d589f to your computer and use it in GitHub Desktop.
# Returns HEAD commit message formatted as a valid branch name
msg2bname() {
git show -s --format=%s | tr '(' '_' | tr -d '):' | tr ' ' '-' # chore(k8s): create secret -> chore_k8s-create-secret
# chore: use correct db password -> chore-use-correct-db-password
}
# Returns branch name formatted as a commit message
bname2msg() {
bname=$(git branch --show-current)
if [[ $(echo $bname | grep '(') ]]; then
echo $bname | sed 's,_\([^-]*\),(\1):,' | tr '-' ' ' # chore_k8s-create-secret -> chore(k8s): create secret
else
echo $bname | sed 's,-,: ,' | tr '-' ' ' # chore-use-correct-db-password -> chore: use correct db password
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment