Make :Gcd global

This commit is contained in:
Tim Pope
2019-09-03 21:27:13 -04:00
parent 77a732c97c
commit 2464b0c29a
2 changed files with 10 additions and 9 deletions

View File

@@ -2175,22 +2175,20 @@ endfunction
" Section: :Gcd, :Glcd
function! s:DirComplete(A, L, P) abort
function! fugitive#CdComplete(A, L, P) abort
return filter(fugitive#CompletePath(a:A), 'v:val =~# "/$"')
endfunction
function! s:DirArg(path) abort
function! fugitive#Cd(path, ...) abort
let path = substitute(a:path, '^:/:\=\|^:(\%(top\|top,literal\|literal,top\|literal\))', '', '')
if path =~# '^/\|^\a\+:\|^\.\.\=\%(/\|$\)'
return path
else
return FugitiveVimPath((empty(s:Tree()) ? s:Dir() : s:Tree()) . '/' . path)
if path !~# '^/\|^\a\+:\|^\.\.\=\%(/\|$\)'
let dir = s:Dir()
exe s:DirCheck(dir)
let path = (empty(s:Tree(dir)) ? dir : s:Tree(dir)) . '/' . path
endif
return (a:0 && a:1 ? 'lcd ' : 'cd ') . s:fnameescape(FugitiveVimPath(path))
endfunction
call s:command("-bar -bang -nargs=? -complete=customlist,s:DirComplete Gcd :exe s:DirCheck()|exe 'cd<bang>' s:fnameescape(s:DirArg(<q-args>))")
call s:command("-bar -bang -nargs=? -complete=customlist,s:DirComplete Glcd :exe s:DirCheck()|exe 'lcd<bang>' s:fnameescape(s:DirArg(<q-args>))")
" Section: :Gstatus
call s:command("-bar -bang -range=-1 -addr=other Gstatus", "Status")

View File

@@ -362,6 +362,9 @@ let s:addr_tabs = has('patch-7.4.542') ? '-addr=tabs' : ''
exe 'command! -bang -nargs=? -range=-1' s:addr_other '-complete=customlist,fugitive#Complete G exe fugitive#Command(<line1>, <count>, +"<range>", <bang>0, "<mods>", <q-args>)'
exe 'command! -bang -nargs=? -range=-1' s:addr_other '-complete=customlist,fugitive#Complete Git exe fugitive#Command(<line1>, <count>, +"<range>", <bang>0, "<mods>", <q-args>)'
exe "command! -bar -bang -nargs=? -complete=customlist,fugitive#CdComplete Gcd exe fugitive#Cd(<q-args>, 0)"
exe "command! -bar -bang -nargs=? -complete=customlist,fugitive#CdComplete Glcd exe fugitive#Cd(<q-args>, 1)"
exe 'command! -bar -bang -nargs=* -complete=customlist,fugitive#CompleteObject Ge exe fugitive#Open("edit<bang>", 0, "<mods>", <q-args>, [<f-args>])'
exe 'command! -bar -bang -nargs=* -complete=customlist,fugitive#CompleteObject Gedit exe fugitive#Open("edit<bang>", 0, "<mods>", <q-args>, [<f-args>])'
exe 'command! -bar -bang -nargs=* -complete=customlist,fugitive#ReadComplete Gpedit exe fugitive#Open("pedit", <bang>0, "<mods>", <q-args>, [<f-args>])'