Skip to content

Instantly share code, notes, and snippets.

@paulstatezny
Last active June 15, 2018 21:45
Show Gist options
  • Save paulstatezny/f7023f11f5f374e330bc to your computer and use it in GitHub Desktop.
Save paulstatezny/f7023f11f5f374e330bc to your computer and use it in GitHub Desktop.
A fish shell function for committing in Git in a "Refs #123 - Commit message." format (Usage: `commit 'Commit message'`)
# Prefix commit message with "Refs #[PULL_NUMBER] - "
# PULL_NUMBER is derived from the branch name, which is assumed to be in one of the following formats:
# something/[PULL_NUMBER]-short-descriptive-name
# something/[GROUP_NUMBER]/[PULL_NUMBER]-short-descriptive-name
function commit
set issue (git rev-parse --abbrev-ref HEAD | cut -d / -f 3 | cut -d - -f 1 | grep "^\d*\$")
set message $argv[1]
set prefix "Refs #"
if [ "$issue" = "" ]
set issue (git rev-parse --abbrev-ref HEAD | cut -d / -f 2 | cut -d - -f 1 | grep "^\d*\$")
end
if [ "$issue" = "" ]
set prefix ""
else
set prefix "Refs #$issue - "
end
git commit -m "$prefix$message."
end
@paulstatezny
Copy link
Author

Examples:

Usage:

Branch name: feature/123-add-profile-pic

commit 'Add initial unit test'

Results in:

git commit -m 'Refs #123 - Add initial unit test.'

Branch name: group/123/456-add-profile-pic

commit 'Add initial unit test'

Results in:

git commit -m 'Refs #456 - Add initial unit test.'

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