mirror of
https://github.com/tpope/vim-rhubarb.git
synced 2025-12-08 04:54:46 +08:00
Support for :Gbrowse
This commit is contained in:
@@ -1,17 +1,15 @@
|
|||||||
# rhubarb.vim
|
# rhubarb.vim
|
||||||
|
|
||||||
If [fugitive.vim][] is the Git, rhubarb.vim is the Hub. Or at least it
|
If [fugitive.vim][] is the Git, rhubarb.vim is the Hub. Here's the full list
|
||||||
could be. One day. Right now it's pretty stupid. I almost named it
|
of features:
|
||||||
chubby.vim, but it just didn't feel right.
|
|
||||||
|
|
||||||
So far there's only one feature: In Git commit messages, GitHub issues
|
* Enables `:Gbrowse` from fugitive.vim to open GitHub URLs. (`:Gbrowse`
|
||||||
and collaborators can be omni-completed (`<C-X><C-O>`, see `:help
|
currently has native support for this, but it is slated to be removed.)
|
||||||
compl-omni`). This makes inserting those `Closes #123` remarks slightly
|
|
||||||
easier than copying and pasting from the browser.
|
|
||||||
|
|
||||||
Maybe I'll extract `:Gbrowse` out of fugitive.vim and put it here
|
* In commit messages, GitHub issues, issue URLs, and collaborators can be
|
||||||
instead. Or maybe I'll add some cool Gist stuff. You never know with
|
omni-completed (`<C-X><C-O>`, see `:help compl-omni`). This makes inserting
|
||||||
rhubarb.vim.
|
those `Closes #123` remarks slightly easier than copying and pasting from
|
||||||
|
the browser.
|
||||||
|
|
||||||
[fugitive.vim]: https://github.com/tpope/vim-fugitive
|
[fugitive.vim]: https://github.com/tpope/vim-fugitive
|
||||||
|
|
||||||
|
|||||||
@@ -180,3 +180,57 @@ function! rhubarb#omnifunc(findstart,base) abort
|
|||||||
echoerr v:errmsg
|
echoerr v:errmsg
|
||||||
endtry
|
endtry
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
" Section: Fugitive :Gbrowse support
|
||||||
|
|
||||||
|
function! rhubarb#fugitive_url(opts, ...) abort
|
||||||
|
if a:0 || type(a:opts) != type({}) || !has_key(a:opts, 'repo')
|
||||||
|
return ''
|
||||||
|
endif
|
||||||
|
let root = s:homepage_for_url(get(a:opts, 'remote'))
|
||||||
|
if empty(root)
|
||||||
|
return ''
|
||||||
|
endif
|
||||||
|
let path = a:opts.path
|
||||||
|
if path =~# '^\.git/refs/heads/'
|
||||||
|
let branch = a:opts.repo.git_chomp('config','branch.'.path[16:-1].'.merge')[11:-1]
|
||||||
|
if branch ==# ''
|
||||||
|
return root . '/commits/' . path[16:-1]
|
||||||
|
else
|
||||||
|
return root . '/commits/' . branch
|
||||||
|
endif
|
||||||
|
elseif path =~# '^\.git/refs/.'
|
||||||
|
return root . '/commits/' . matchstr(path,'[^/]\+$')
|
||||||
|
elseif path =~# '.git/\%(config$\|hooks\>\)'
|
||||||
|
return root . '/admin'
|
||||||
|
elseif path =~# '^\.git\>'
|
||||||
|
return root
|
||||||
|
endif
|
||||||
|
if a:opts.revision =~# '^[[:alnum:]._-]\+:'
|
||||||
|
let commit = matchstr(a:opts.revision,'^[^:]*')
|
||||||
|
elseif a:opts.commit =~# '^\d\=$'
|
||||||
|
let local = matchstr(a:opts.repo.head_ref(),'\<refs/heads/\zs.*')
|
||||||
|
let commit = a:opts.repo.git_chomp('config','branch.'.local.'.merge')[11:-1]
|
||||||
|
if commit ==# ''
|
||||||
|
let commit = local
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
let commit = a:opts.commit
|
||||||
|
endif
|
||||||
|
if a:opts.type == 'tree'
|
||||||
|
let url = substitute(root . '/tree/' . commit . '/' . path, '/$', '', 'g')
|
||||||
|
elseif a:opts.type == 'blob'
|
||||||
|
let url = root . '/blob/' . commit . '/' . path
|
||||||
|
if get(a:opts, 'line2') && a:opts.line1 == a:opts.line2
|
||||||
|
let url .= '#L' . a:opts.line1
|
||||||
|
elseif get(a:opts, 'line2')
|
||||||
|
let url .= '#L' . a:opts.line1 . '-L' . a:opts.line2
|
||||||
|
endif
|
||||||
|
elseif a:opts.type == 'tag'
|
||||||
|
let commit = matchstr(getline(3),'^tag \zs.*')
|
||||||
|
let url = root . '/tree/' . commit
|
||||||
|
else
|
||||||
|
let url = root . '/commit/' . commit
|
||||||
|
endif
|
||||||
|
return url
|
||||||
|
endfunction
|
||||||
|
|||||||
@@ -31,3 +31,11 @@ augroup rhubarb
|
|||||||
\ setlocal nolist linebreak filetype=markdown |
|
\ setlocal nolist linebreak filetype=markdown |
|
||||||
\ endif
|
\ endif
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
|
if !exists('g:fugitive_browse_handlers')
|
||||||
|
let g:fugitive_browse_handlers = []
|
||||||
|
endif
|
||||||
|
|
||||||
|
if index(g:fugitive_browse_handlers, function('rhubarb#fugitive_url')) < 0
|
||||||
|
call insert(g:fugitive_browse_handlers, function('rhubarb#fugitive_url'))
|
||||||
|
endif
|
||||||
|
|||||||
Reference in New Issue
Block a user