if executable('chmod')
function! SetExecutableBit(x)
checktime
- let fname = expand("%:p")
- let fx = executable(fname)
- execute "au FileChangedShell " . fname . " :echo"
+ " Avoid 'Reload Y/N?' question
+ autocmd FileChangedShell <buffer> call _BufChangedCB()
+ let fx = executable(expand("%:p"))
if a:x && !fx
- !chmod a+x %
+ silent !chmod a+x %
elseif !a:x && fx
- !chmod a-x %
+ silent !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
+ function! _BufChangedCB()
+ autocmd! FileChangedShell <buffer>
+ endfunction
+ command! ToggleXbit if executable(expand("%:p")) | call SetExecutableBit(0) | else | call SetExecutableBit(1) | endif
endif