Skip to content

Instantly share code, notes, and snippets.

@dctucker
Created March 13, 2018 15:54
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 dctucker/d20be758f3ace5a69242786f1b611588 to your computer and use it in GitHub Desktop.
Save dctucker/d20be758f3ace5a69242786f1b611588 to your computer and use it in GitHub Desktop.
Vimscript for opening the current file in GitHub for Mac
function! OpenGithub()
" let l:pwd = expand("%:p:h:t")
let l:branch = systemlist("git -C " . expand("%:p:h") . " symbolic-ref --quiet --short HEAD || git rev-parse --short HEAD")[0]
let l:root = systemlist("git -C " . expand("%:p:h") . " rev-parse --show-toplevel")[0]
let l:repo = fnamemodify(l:root, ":t")
let l:fn = substitute(expand("%"), escape(l:root, "/"), "", "g")
exec "!open https://github.com/github/" . l:repo . "/blob/" . l:branch . l:fn
endfunction
command! -nargs=0 GH call OpenGithub()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment