mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-12-30 08:04:28 +08:00
Support :GBrowse {url} outside of Git repository
This commit is contained in:
@@ -6051,9 +6051,34 @@ augroup END
|
||||
|
||||
" Section: :GBrowse
|
||||
|
||||
function! s:BrowserOpen(url, mods, echo_copy) abort
|
||||
let url = substitute(a:url, '[ <>\|"]', '\="%".printf("%02X",char2nr(submatch(0)))', 'g')
|
||||
let mods = s:Mods(a:mods)
|
||||
if a:echo_copy
|
||||
if has('clipboard')
|
||||
let @+ = url
|
||||
endif
|
||||
return 'echo '.string(url)
|
||||
elseif exists(':Browse') == 2
|
||||
return 'echo '.string(url).'|' . mods . 'Browse '.url
|
||||
elseif exists(':OpenBrowser') == 2
|
||||
return 'echo '.string(url).'|' . mods . 'OpenBrowser '.url
|
||||
else
|
||||
if !exists('g:loaded_netrw')
|
||||
runtime! autoload/netrw.vim
|
||||
endif
|
||||
if exists('*netrw#BrowseX')
|
||||
return 'echo '.string(url).'|' . mods . 'call netrw#BrowseX('.string(url).', 0)'
|
||||
elseif exists('*netrw#NetrwBrowseX')
|
||||
return 'echo '.string(url).'|' . mods . 'call netrw#NetrwBrowseX('.string(url).', 0)'
|
||||
else
|
||||
return 'echoerr ' . string('Netrw not found. Define your own :Browse to use :GBrowse')
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! fugitive#BrowseCommand(line1, count, range, bang, mods, arg, args) abort
|
||||
let dir = s:Dir()
|
||||
exe s:DirCheck(dir)
|
||||
try
|
||||
let arg = a:arg
|
||||
if arg =~# '^++remote='
|
||||
@@ -6085,12 +6110,18 @@ function! fugitive#BrowseCommand(line1, count, range, bang, mods, arg, args) abo
|
||||
if rev ==# ''
|
||||
let rev = s:DirRev(@%)[1]
|
||||
endif
|
||||
if rev =~# '^:\=$'
|
||||
let expanded = s:Relative()
|
||||
elseif rev =~? '^\a\a\+:[\/][\/]' && rev !~? '^fugitive:'
|
||||
let expanded = s:Expand(substitute(rev, '\\\@<!#\|\\\@<!%\ze\w', '\\&', 'g'))
|
||||
else
|
||||
let expanded = s:Expand(rev)
|
||||
if rev =~? '^\a\a\+:[\/][\/]' && rev !~? '^fugitive:'
|
||||
let rev = substitute(rev, '\\\@<![#!]\|\\\@<!%\ze\w', '\\&', 'g')
|
||||
elseif rev ==# ':'
|
||||
let rev = ''
|
||||
endif
|
||||
let expanded = s:Expand(rev)
|
||||
if expanded =~? '^\a\a\+:[\/][\/]' && expanded !~? '^fugitive:'
|
||||
return s:BrowserOpen(s:Slash(expanded), a:mods, a:bang)
|
||||
endif
|
||||
exe s:DirCheck(dir)
|
||||
if empty(expanded)
|
||||
let expanded = s:Relative(':(top)', dir)
|
||||
endif
|
||||
let cdir = FugitiveVimPath(fugitive#CommonDir(dir))
|
||||
for subdir in ['tags/', 'heads/', 'remotes/']
|
||||
@@ -6112,9 +6143,6 @@ function! fugitive#BrowseCommand(line1, count, range, bang, mods, arg, args) abo
|
||||
let type = 'blob'
|
||||
endif
|
||||
let path = path[1:-1]
|
||||
elseif full =~? '^\a\a\+:[\/][\/]'
|
||||
let path = s:Slash(full)
|
||||
let type = 'url'
|
||||
elseif empty(s:Tree(dir))
|
||||
let path = '.git/' . full[strlen(dir)+1:-1]
|
||||
let type = ''
|
||||
@@ -6243,45 +6271,19 @@ function! fugitive#BrowseCommand(line1, count, range, bang, mods, arg, args) abo
|
||||
\ 'line1': line1,
|
||||
\ 'line2': line2}
|
||||
|
||||
if type ==# 'url'
|
||||
let url = path
|
||||
else
|
||||
let url = ''
|
||||
for Handler in get(g:, 'fugitive_browse_handlers', [])
|
||||
let url = call(Handler, [copy(opts)])
|
||||
if !empty(url)
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
let url = ''
|
||||
for Handler in get(g:, 'fugitive_browse_handlers', [])
|
||||
let url = call(Handler, [copy(opts)])
|
||||
if !empty(url)
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
|
||||
if empty(url)
|
||||
call s:throw("No GBrowse handler installed for '".raw."'")
|
||||
endif
|
||||
|
||||
let url = substitute(url, '[ <>\|"]', '\="%".printf("%02X",char2nr(submatch(0)))', 'g')
|
||||
let mods = s:Mods(a:mods)
|
||||
if a:bang
|
||||
if has('clipboard')
|
||||
let @+ = url
|
||||
endif
|
||||
return 'echo '.string(url)
|
||||
elseif exists(':Browse') == 2
|
||||
return 'echo '.string(url).'|' . mods . 'Browse '.url
|
||||
elseif exists(':OpenBrowser') == 2
|
||||
return 'echo '.string(url).'|' . mods . 'OpenBrowser '.url
|
||||
else
|
||||
if !exists('g:loaded_netrw')
|
||||
runtime! autoload/netrw.vim
|
||||
endif
|
||||
if exists('*netrw#BrowseX')
|
||||
return 'echo '.string(url).'|' . mods . 'call netrw#BrowseX('.string(url).', 0)'
|
||||
elseif exists('*netrw#NetrwBrowseX')
|
||||
return 'echo '.string(url).'|' . mods . 'call netrw#NetrwBrowseX('.string(url).', 0)'
|
||||
else
|
||||
return 'echoerr ' . string('Netrw not found. Define your own :Browse to use :GBrowse')
|
||||
endif
|
||||
endif
|
||||
return s:BrowserOpen(url, a:mods, a:bang)
|
||||
catch /^fugitive:/
|
||||
return 'echoerr ' . string(v:exception)
|
||||
endtry
|
||||
|
||||
Reference in New Issue
Block a user