Skip to content

Instantly share code, notes, and snippets.

@skahack
Created July 14, 2014 16:12
Show Gist options
  • Save skahack/17fd66bf0d15dfa5d547 to your computer and use it in GitHub Desktop.
Save skahack/17fd66bf0d15dfa5d547 to your computer and use it in GitHub Desktop.
open a GitHub page
function! g:open_github() "{{{
let commit = system("git rev-parse HEAD")
let commit = substitute(commit, '^[ \t\n]\+', '', 'g')
let commit = substitute(commit, '[ \t\n]\+$', '', 'g')
let top = system('git rev-parse --show-toplevel')
let top = substitute(top, '^[ \t\n]\+', '', 'g')
let top = substitute(top, '[ \t\n]\+$', '', 'g')
let filepath = expand('%:p')
let path = substitute(filepath, top, '', 'g')
silent exec(join(['!hub browse -- tree/', commit, path], ''))
redraw!
endfunction "}}}
command! OpenGithubFile call g:open_github()
nmap <Space>g :OpenGithubFile<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment