Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make :Rename relative to containing directory

Closes #5.
  • Loading branch information...
commit 4abf1f58614fc6b4c20bb247db59469a9a52ff9b 1 parent c4e8d83
@tpope authored
Showing with 20 additions and 3 deletions.
  1. +2 −1  doc/eunuch.txt
  2. +18 −2 plugin/eunuch.vim
View
3  doc/eunuch.txt
@@ -31,7 +31,8 @@ COMMANDS *eunuch-commands*
:Move[!] {file} Like |:saveas|, but delete the old file afterwards.
*eunuch-:Rename*
-:Rename[!] {file} Alias for |:Move|.
+:Rename[!] {file} Like |:Move|, but relative to the current file's
+ containing directory.
*eunuch-:Chmod*
:Chmod {mode} Change the permissions of the current file.
View
20 plugin/eunuch.vim
@@ -7,6 +7,10 @@ if exists('g:loaded_eunuch') || &cp || v:version < 700
endif
let g:loaded_eunuch = 1
+function! s:separator()
+ return !exists('+shellslash') || &shellslash ? '/' : '\\'
+endfunction
+
command! -bar -bang Unlink :
\ let v:errmsg = '' |
\ let s:file = fnamemodify(bufname(<q-args>),':p') |
@@ -22,8 +26,10 @@ command! -bar -nargs=1 -bang -complete=file Move :
\ let s:src = expand('%:p') |
\ let s:dst = expand(<q-args>) |
\ if isdirectory(s:dst) |
- \ let s:dst .= '/' . fnamemodify(s:src, ':t') |
+ \ let s:dst .= (s:dst[-1:-1] =~# '[\\/]' ? '' : s:separator()) .
+ \ fnamemodify(s:src, ':t') |
\ endif |
+ \ let s:dst = substitute(simplify(s:dst), '^\.\'.s:separator(), '', '') |
\ if <bang>1 && filereadable(s:dst) |
\ exe 'keepalt saveas '.fnameescape(s:dst) |
\ elseif rename(s:src, s:dst) |
@@ -38,7 +44,17 @@ command! -bar -nargs=1 -bang -complete=file Move :
\ unlet s:src |
\ unlet s:dst
-command! -bar -nargs=1 -bang -complete=file Rename :Move<bang> <args>
+function! s:Rename_complete(A, L, P) abort
+ let sep = s:separator()
+ let prefix = expand('%:p:h').sep
+ let files = split(glob(prefix.a:A.'*'), "\n")
+ call filter(files, 'simplify(v:val) !=# simplify(expand("%:p"))')
+ call map(files, 'v:val[strlen(prefix) : -1] . (isdirectory(v:val) ? sep : "")')
+ return join(files + ['..'.s:separator()], "\n")
+endfunction
+
+command! -bar -nargs=1 -bang -complete=custom,s:Rename_complete Rename
+ \ Move<bang> %:h/<args>
command! -bar -nargs=1 Chmod :
\ echoerr split(system('chmod '.<q-args>.' -- '.shellescape(expand('%'))), "\n")[0] |
Please sign in to comment.
Something went wrong with that request. Please try again.