fish function that prepares a git commit command with message containing the jira ticket number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# commit with juira-ticket-id shortcut | |
# | |
# install via `cat commit.bash >> ~/.bashrc` | |
# Use: | |
# Assuming you are in a git repository of a bitbucket / jira branch using the atlassian jira git flow conventions | |
# example "feature/EXP-1337-cool-new-feature | |
# | |
# > commit -a | |
# will call | |
# > git commit -em "EXP-1337: " -a | |
# opening your configured editor with the Ticket-ID prefixed | |
# | |
function commit() { | |
if [ "$(uname)" == 'Darwin' ]; | |
then | |
sedr="sed -E" | |
else | |
sedr="sed -r" | |
fi | |
_ticket=$(git branch | grep \* | $sedr 's#^\*[[:space:]]+(feature|hotfix|bugfix)/?([[:alpha:]]+-[[:digit:]]+).*$#\2#') | |
git commit -em "$_ticket: " $* | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# save as ~/.config/fish/functions/commit.fish | |
# Use: | |
# Assuming you are in a git repository of a bitbucket / jira branch using the atlassian jira git flow conventions | |
# example "feature/EXP-1337-cool-new-feature | |
# | |
# > commit | |
# will expand to | |
# > git commit -m 'EXP-1337: ' | |
# resting the cursor just before the last quote | |
# | |
function commit | |
function sedr | |
switch (uname) | |
case 'Darwin' | |
sed -E $argv | |
case '*' | |
sed -r $argv | |
end | |
end | |
set _ticket (git branch ^/dev/null | \ | |
grep \* | \ | |
sedr 's#^\*[[:space:]]+(feature|hotfix|bugfix)/?([[:alpha:]]+-[[:digit:]]+).*$#\2#') | |
commandline -r "git commit -m '$_ticket: '" | |
commandline -C (expr (commandline -C) - 1) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I added a function to omit the prefix if no ticket identifier was found, maybe you want to port that. https://gist.github.com/dedeibel/a07cde2f2c8de7a722092f7b54039026