Skip to content

Commit

Permalink
vimrc: add FugitiveOpenBrowser() to open URL of commit
Browse files Browse the repository at this point in the history
  • Loading branch information
yous committed May 9, 2024
1 parent 1ac8332 commit 15e4b95
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions vimrc
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,43 @@ let g:gutentags_file_list_command = {
\ : s:BuildTagsFileListCmd('find') }
let g:gutentags_cscope_build_inverted_index = 1

" vim-fugitive
function! s:FugitiveOpenBrowser()
let hash = matchstr(getline('.'), '^\^\=[?*]*\zs\x\+')
if hash =~# '^0\+$'
return
endif
let remote_url = FugitiveRemoteUrl()
if remote_url =~# '^git@'
let remote_url = substitute(remote_url, '^git@\(.*\):\(.*\)$', 'http://\1/\2', '')
endif
let remote_url = substitute(remote_url, '\.git$', '', '')
if remote_url =~# '^https\=://github\.com'
let commit_url = remote_url . '/commit/' . hash
elseif remote_url =~# '^https\=://bitbucket\.org'
let commit_url = remote_url . '/commits/' . hash
else
let commit_url = remote_url . '/-/commit/' . hash
endif
if has('win32')
let open_cmd = 'start "" "%s"'
elseif has('mac') || has('macnuix')
let open_cmd = 'open "%s"'
elseif executable('xdg-open')
let open_cmd = 'xdg-open "%s"'
elseif executable('gio')
let open_cmd = 'gio open "%s"'
else
return
endif
call system(printf(open_cmd, commit_url))
endfunction
augroup FugitiveBrowser
autocmd!
autocmd FileType fugitiveblame
\ nnoremap <buffer> <silent> <Leader>o :<C-U>call <SID>FugitiveOpenBrowser()<CR>
augroup END

" fzf.vim
if has_key(g:plugs, 'fzf.vim')
function! s:GetVisualSelection()
Expand Down

0 comments on commit 15e4b95

Please sign in to comment.