Skip to content

Instantly share code, notes, and snippets.

@luxflux
Last active January 2, 2017 00:01
Show Gist options
  • Save luxflux/8397645 to your computer and use it in GitHub Desktop.
Save luxflux/8397645 to your computer and use it in GitHub Desktop.
Extract issue id from branch name
" get reference for the current issue from git branch name
" assumes your branch name looks like 1337-fixing-a-lot-of-stuff
"
function GitBranchIssue(fixes)
let current_branch = system("git rev-parse --abbrev-ref HEAD")
let ref = substitute(current_branch, '^.\+\/\(\d\+\).\+$', '\1', '')
if a:fixes == 'true'
let prefix = 'fixes'
else
let prefix = 'refs'
endif
return prefix . ' #' . ref
endfunction
iab REFS <C-R>=GitBranchIssue('false')<CR>
iab FIXES <C-R>=GitBranchIssue('true')<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment