Permalink
Browse files

Add eunuch.vim

  • Loading branch information...
1 parent c077d29 commit 29e6f1001b212f869f569a66850a5776d4603aaf @tpope committed Nov 5, 2012
Showing with 102 additions and 13 deletions.
  1. +102 −0 .vim/plugin/eunuch.vim
  2. +0 −13 .vimrc
View
@@ -0,0 +1,102 @@
+" eunuch.vim - Helpers for UNIX
+" Maintainer: Tim Pope <http://tpo.pe/>
+" Version: 1.0
+
+if exists('g:loaded_eunuch') || &cp || v:version < 700
+ finish
+endif
+let g:loaded_eunuch = 1
+
+command! -bar -bang Unlink :
+ \ let v:errmsg = '' |
+ \ let s:file = fnamemodify(bufname(<q-args>),':p') |
+ \ execute 'bdelete<bang>' |
+ \ if v:errmsg ==# '' && delete(s:file) |
+ \ echoerr 'Failed to delete "'.s:file.'"' |
+ \ endif |
+ \ unlet s:file
+
+command! -bar -bang Remove :Unlink<bang>
+
+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') |
+ \ endif |
+ \ if <bang>1 && filereadable(s:dst) |
+ \ exe 'keepalt saveas '.fnameescape(s:dst) |
+ \ elseif rename(s:src, s:dst) |
+ \ echoerr 'Failed to rename "'.s:src.'" to "'.s:dst.'"' |
+ \ else |
+ \ setlocal modified |
+ \ exe 'keepalt saveas! '.fnameescape(s:dst) |
+ \ if s:src !=# expand('%:p') |
+ \ execute 'bwipe '.fnameescape(s:src) |
+ \ endif |
+ \ endif |
+ \ unlet s:src |
+ \ unlet s:dst
+
+command! -bar -nargs=1 -bang -complete=file Rename :Move<bang> <args>
+
+command! -bar -nargs=1 Chmod :
+ \ echoerr split(system('chmod '.<q-args>.' -- '.shellescape(expand('%'))), "\n")[0] |
+
+command! -bar -bang -complete=file -nargs=+ Find :call s:Grep(<q-bang>, <q-args>, 'find')
+command! -bar -bang -complete=file -nargs=+ Locate :call s:Grep(<q-bang>, <q-args>, 'locate')
+function! s:Grep(bang,args,prg) abort
+ let grepprg = &l:grepprg
+ let grepformat = &l:grepformat
+ let shellpipe = &shellpipe
+ try
+ let &l:grepprg = a:prg
+ setlocal grepformat=%f
+ if &shellpipe ==# '2>&1| tee' || &shellpipe ==# '|& tee'
+ let &shellpipe = "| tee"
+ endif
+ execute 'grep'.a:bang.' '.a:args
+ finally
+ let &l:grepprg = grepprg
+ let &l:grepformat = grepformat
+ let &shellpipe = shellpipe
+ endtry
+endfunction
+
+command! -bar SudoWrite :
+ \ setlocal nomodified |
+ \ silent exe 'write !sudo tee % >/dev/null' |
+ \ let &modified = v:shell_error
+
+command! -bar W :call s:W()
+function! s:W() abort
+ let tab = tabpagenr()
+ let win = winnr()
+ let seen = {}
+ if !&readonly && expand('%') !=# ''
+ let seen[bufnr('')] = 1
+ write
+ endif
+ tabdo windo if !&readonly && expand('%') !=# '' && !has_key(seen, bufnr('')) | silent write | let seen[bufnr('')] = 1 | endif
+ execute 'tabnext '.tab
+ execute win.'wincmd w'
+endfunction
+
+augroup shebang_chmod
+ autocmd!
+ autocmd BufNewFile * let b:brand_new_file = 1
+ autocmd BufWritePost * unlet! b:brand_new_file
+ autocmd BufWritePre *
+ \ if exists('b:brand_new_file') |
+ \ if getline(1) =~ '^#!' |
+ \ let b:chmod_post = '+x' |
+ \ endif |
+ \ endif
+ autocmd BufWritePost,FileWritePost *
+ \ if exists('b:chmod_post') && executable('chmod') |
+ \ silent! execute '!chmod '.b:chmod_post.' "<afile>"' |
+ \ unlet b:chmod_post |
+ \ endif
+augroup END
+
+" vim:set sw=2 sts=2:
View
@@ -168,16 +168,8 @@ function! SL(function)
endfunction
command! -bar -nargs=1 -complete=file E :exe "edit ".substitute(<q-args>,'\(.*\):\(\d\+\):\=$','+\2 \1','')
-command! -bar -nargs=0 SudoW :setl nomod|silent exe 'write !sudo tee % >/dev/null'|let &mod = v:shell_error
-command! -bar -nargs=* -bang W :write<bang> <args>
command! -bar -nargs=0 -bang Scratch :silent edit<bang> \[Scratch]|set buftype=nofile bufhidden=hide noswapfile buflisted
command! -bar -count=0 RFC :e http://www.ietf.org/rfc/rfc<count>.txt|setl ro noma
-command! -bar -nargs=* -bang -complete=file Rename :
- \ let v:errmsg = ""|
- \ saveas<bang> <args>|
- \ if v:errmsg == ""|
- \ call delete(expand("#"))|
- \ endif
function! Synname()
if exists("*synstack")
@@ -452,11 +444,6 @@ if has("autocmd")
\ set ft=sh | 1
autocmd BufNewFile */.netrc,*/.fetchmailrc,*/.my.cnf let b:chmod_new="go-rwx"
- autocmd BufNewFile * let b:chmod_exe=1
- autocmd BufWritePre * if exists("b:chmod_exe") |
- \ unlet b:chmod_exe |
- \ if getline(1) =~ '^#!' | let b:chmod_new="+x" | endif |
- \ endif
autocmd BufWritePost,FileWritePost * if exists("b:chmod_new")|
\ silent! execute "!chmod ".b:chmod_new." <afile>"|
\ unlet b:chmod_new|

0 comments on commit 29e6f10

Please sign in to comment.