Add :Grename
I'll rip out the weird current directory stuff later.
This commit is contained in:
parent
fa1b8652f1
commit
dcecb762b0
@ -196,7 +196,13 @@ that are part of Git repositories).
|
||||
:Gmove {destination} Wrapper around git-mv that renames the buffer
|
||||
afterward. The destination is relative to the current
|
||||
directory except when started with a /, in which case
|
||||
it is relative to the work tree. Add a ! to pass -f.
|
||||
it is relative to the work tree. (This is a holdover
|
||||
from before |:Grename| and will be removed.) Add a !
|
||||
to pass -f.
|
||||
|
||||
*fugitive-:Grename*
|
||||
:Grename {destination} Like |:Gmove| but operates relative to the parent
|
||||
directory of the current file.
|
||||
|
||||
*fugitive-:Gdelete*
|
||||
:Gdelete Wrapper around git-rm that deletes the buffer
|
||||
|
@ -1883,9 +1883,11 @@ endfunction
|
||||
|
||||
" Section: Gmove, Gremove
|
||||
|
||||
function! s:Move(force,destination) abort
|
||||
function! s:Move(force, rename, destination) abort
|
||||
if a:destination =~# '^/'
|
||||
let destination = a:destination[1:-1]
|
||||
elseif a:rename
|
||||
let destination = fnamemodify(s:buffer().path(), ':h') . '/' . a:destination
|
||||
else
|
||||
let destination = s:shellslash(fnamemodify(s:sub(a:destination,'[%#]%(:\w)*','\=expand(submatch(0))'),':p'))
|
||||
if destination[0:strlen(s:repo().tree())] ==# s:repo().tree('')
|
||||
@ -1906,7 +1908,7 @@ function! s:Move(force,destination) abort
|
||||
let destination = fnamemodify(s:sub(destination,'/$','').'/'.expand('%:t'),':.')
|
||||
endif
|
||||
call fugitive#reload_status()
|
||||
if s:buffer().commit() == ''
|
||||
if empty(s:buffer().commit())
|
||||
if isdirectory(destination)
|
||||
return 'keepalt edit '.s:fnameescape(destination)
|
||||
else
|
||||
@ -1918,15 +1920,24 @@ function! s:Move(force,destination) abort
|
||||
endfunction
|
||||
|
||||
function! s:MoveComplete(A,L,P) abort
|
||||
if a:A =~ '^/'
|
||||
if a:A =~# '^/'
|
||||
return s:repo().superglob(a:A)
|
||||
else
|
||||
let matches = split(glob(a:A.'*'),"\n")
|
||||
call map(matches,'v:val !~ "/$" && isdirectory(v:val) ? v:val."/" : v:val')
|
||||
call map(matches,'v:val !~# "/$" && isdirectory(v:val) ? v:val."/" : v:val')
|
||||
return matches
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:RenameComplete(A,L,P) abort
|
||||
if a:A =~# '^/'
|
||||
return s:repo().superglob(a:A)
|
||||
else
|
||||
let pre = '/'. fnamemodify(s:buffer().path(), ':h') . '/'
|
||||
return map(s:repo().superglob(pre.a:A), 'strpart(v:val, len(pre))')
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:Remove(after, force) abort
|
||||
if s:buffer().commit() ==# ''
|
||||
let cmd = ['rm']
|
||||
@ -1952,7 +1963,8 @@ endfunction
|
||||
augroup fugitive_remove
|
||||
autocmd!
|
||||
autocmd User Fugitive if s:buffer().commit() =~# '^0\=$' |
|
||||
\ exe "command! -buffer -bar -bang -nargs=1 -complete=customlist,s:MoveComplete Gmove :execute s:Move(<bang>0,<q-args>)" |
|
||||
\ exe "command! -buffer -bar -bang -nargs=1 -complete=customlist,s:MoveComplete Gmove :execute s:Move(<bang>0,0,<q-args>)" |
|
||||
\ exe "command! -buffer -bar -bang -nargs=1 -complete=customlist,s:RenameComplete Grename :execute s:Move(<bang>0,1,<q-args>)" |
|
||||
\ exe "command! -buffer -bar -bang Gremove :execute s:Remove('edit',<bang>0)" |
|
||||
\ exe "command! -buffer -bar -bang Gdelete :execute s:Remove('bdelete',<bang>0)" |
|
||||
\ endif
|
||||
|
Loading…
Reference in New Issue
Block a user