Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 41 additions & 6 deletions doc/eunuch.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@ a buffer and the underlying file at the same time. Load a `find` or a

COMMANDS *eunuch-commands*


*eunuch-:Remove* *eunuch-:Unlink*
:Remove[!] Delete the file from disk and reload the buffer. If
:Unlink[!] you change your mind, the contents of the buffer can
be restored with |u| (see 'undoreload').
:Remove[!] Delete the file using the method specified by
:Unlink[!] |g:Eunuch_rm| and reload the buffer. If you change
your mind, the contents of the buffer can be restored
with |u| (see 'undoreload').

*eunuch-:Delete*
:Delete[!] Delete the file from disk and |:bdelete| the buffer.
This cannot be undone, and thus a `!` is required to
delete non-empty files.
:Delete[!] Delete the file using the method specified by
|g:Eunuch_rm| and |:bdelete| the buffer. This cannot
be undone, and thus a `!` is required to delete
non-empty files.

*eunuch-:Copy*
:Copy[!] {file} Small wrapper around |:saveas|. Parent directories
Expand Down Expand Up @@ -95,6 +98,38 @@ COMMANDS *eunuch-commands*
doubles as a safe fallback for people who, like me,
accidentally type :W instead of :w a lot.

DELETION *eunuch-deletion*

*g:Eunuch_rm*
*g:Eunuch_rmdir*
You can customize how |eunuch-commands| will delete files and directories by
setting your own values for the global variables `g:Eunuch_rm` and
`g:Eunuch_rmdir` respectively.

You can specify a String, a List, or a |Funcref|. A string will be called as
a system command with the file's path as its only argument:
>
let g:Eunuch_rm = 'trash'
<
Lists will be interpreted as the name of a system command, and arguments to
pass to it. The file's path will be the final argument:
>
let g:Eunuch_rmdir = ['rm', '-rf']
<
A |Funcref| will let you perform more customized operations:
>
function! MyDelete(path)
echo "deleting " . a:path
endfunction
let g:Eunuch_rm = function('MyDelete')
<
Eunuch uses Vim's |delete()| function by default. The default configuration
is:
>
let g:Eunuch_rm = {path -> delete(path)}
let g:Eunuch_rmdir = {path -> delete(path, 'd')}
<

PASSIVE BEHAVIORS *eunuch-passive*

If you type a line at the beginning of a file that starts with #! and press
Expand Down
22 changes: 18 additions & 4 deletions plugin/eunuch.vim
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ function! s:fcall(fn, path, ...) abort
return call(s:ffn(a:fn, a:path), [a:path] + a:000)
endfunction

let g:Eunuch_rm = {path -> delete(path)}
let g:Eunuch_rmdir = {path -> delete(path, 'd')}

function! s:use_configured(fn, path) abort
if type(a:fn) == v:t_string
call system([a:fn, a:path])
return v:shell_error
elseif type(a:fn) == v:t_list
call system(a:fn + [a:path])
return v:shell_error
endif
return a:fn(a:path)
endfunction

function! s:AbortOnError(cmd) abort
try
exe a:cmd
Expand All @@ -42,11 +56,11 @@ function! EunuchRename(src, dst) abort
let fn = s:ffn('writefile', a:dst)
let copy = call(fn, [s:fcall('readfile', a:src, 'b'), a:dst])
if copy == 0
let delete = s:fcall('delete', a:src)
let delete = s:use_configured(g:Eunuch_rm, a:src)
if delete == 0
return 0
else
call s:fcall('delete', a:dst)
call s:use_configured(g:Eunuch_rm, a:dst)
return -1
endif
endif
Expand All @@ -69,9 +83,9 @@ endfunction

function! s:Delete(path) abort
if has('patch-7.4.1107') && isdirectory(a:path)
return delete(a:path, 'd')
return s:use_configured(g:Eunuch_rmdir, a:path)
else
return s:fcall('delete', a:path)
return s:use_configured(g:Eunuch_rm, a:path)
endif
endfunction

Expand Down