diff --git a/README.markdown b/README.markdown index 01dd086..f07c2ce 100644 --- a/README.markdown +++ b/README.markdown @@ -1,17 +1,15 @@ # rhubarb.vim -If [fugitive.vim][] is the Git, rhubarb.vim is the Hub. Or at least it -could be. One day. Right now it's pretty stupid. I almost named it -chubby.vim, but it just didn't feel right. +If [fugitive.vim][] is the Git, rhubarb.vim is the Hub. Here's the full list +of features: -So far there's only one feature: In Git commit messages, GitHub issues -and collaborators can be omni-completed (``, see `:help -compl-omni`). This makes inserting those `Closes #123` remarks slightly -easier than copying and pasting from the browser. +* Enables `:Gbrowse` from fugitive.vim to open GitHub URLs. (`:Gbrowse` + currently has native support for this, but it is slated to be removed.) -Maybe I'll extract `:Gbrowse` out of fugitive.vim and put it here -instead. Or maybe I'll add some cool Gist stuff. You never know with -rhubarb.vim. +* In commit messages, GitHub issues, issue URLs, and collaborators can be + omni-completed (``, see `:help compl-omni`). This makes inserting + those `Closes #123` remarks slightly easier than copying and pasting from + the browser. [fugitive.vim]: https://github.com/tpope/vim-fugitive diff --git a/autoload/rhubarb.vim b/autoload/rhubarb.vim index 8411331..d2d2dd3 100644 --- a/autoload/rhubarb.vim +++ b/autoload/rhubarb.vim @@ -180,3 +180,57 @@ function! rhubarb#omnifunc(findstart,base) abort echoerr v:errmsg endtry 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(),'\