Skip to content

Instantly share code, notes, and snippets.

@MaZderMind
Forked from dedeibel/commit.fish
Last active May 23, 2017 10:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MaZderMind/1c79bf1be1a5bf92c3a10608e8710c3c to your computer and use it in GitHub Desktop.
Save MaZderMind/1c79bf1be1a5bf92c3a10608e8710c3c to your computer and use it in GitHub Desktop.
fish function that prepares a git commit command with message containing the jira ticket number
# 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: " $*
}
# 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
@dedeibel
Copy link

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

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