From 0bf6afa72ca190d7378752944ef901f8b84cea6f Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Mon, 26 Mar 2018 06:59:48 +0300 Subject: [PATCH] .vimrc: Check chmod just once --- .vimrc | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/.vimrc b/.vimrc index f592934..bb97edb 100644 --- a/.vimrc +++ b/.vimrc @@ -586,26 +586,25 @@ endif " From Tip 212: " http://vim.wikia.com/wiki/Setting_file_attributes_without_reloading_a_buffer -function! SetExecutableBit(x) - if !executable('chmod') - return - endif - checktime - let fname = expand("%:p") - let fx = executable(fname) - execute "au FileChangedShell " . fname . " :echo" - if a:x && !fx - !chmod a+x % - elseif !a:x && fx - !chmod a-x % - endif - if v:shell_error - echoerr 'Error running chmod: ' . v:shell_error - endif - checktime - execute "au! FileChangedShell " . fname -endfunction -command! Xbit if executable(expand("%:p")) | call SetExecutableBit(0) | else | call SetExecutableBit(1) | endif +if executable('chmod') + function! SetExecutableBit(x) + checktime + let fname = expand("%:p") + let fx = executable(fname) + execute "au FileChangedShell " . fname . " :echo" + if a:x && !fx + !chmod a+x % + elseif !a:x && fx + !chmod a-x % + endif + if v:shell_error + echoerr 'Error running chmod: ' . v:shell_error + endif + checktime + execute "au! FileChangedShell " . fname + endfunction + command! Xbit if executable(expand("%:p")) | call SetExecutableBit(0) | else | call SetExecutableBit(1) | endif +endif " ---------- -- 2.39.5