Thursday, 27 October 2011

how do I configure vim to set the executable bit on scripts?

how do I configure vim to set the executable bit on scripts?

I am trying to configure vim so that when I write a new script it will automatically set the executable bit on it when I write to it for the first time without the annoying
Code:

W16: Warning: Mode of file "b.sh" has changed since editing started
See ":help W16" for more info.
[O]K, (L)oad File:

No matter what I do though, it doesn't seem to work.

here is my .vimrc:

Code:

so ~/.vim/mod.vim

autocmd BufNewFile * let fname=expand("%:p")
autocmd BufNewFile *.pl execute "autocmd BufWritePost ".fname." call SetExecutableBit()"
autocmd BufNewFile *.sh execute "autocmd BufWritePost ".fname." call SetExecutableBit()"
autocmd BufNewFile *.rb execute "autocmd BufWritePost ".fname." call SetExecutableBit()"
autocmd BufNewFile *.py execute "autocmd BufWritePost ".fname." call SetExecutableBit()"

and this is my .vim/mod.vim file:
Code:

function! SetExecutableBit()
        let fname=expand("%:p")
        execute "autocmd FileChangedShell ".fname
        execute "!chmod a+x ".fname
        execute "autocmd! FileChangedShell ".fname
endfunction

No comments:

Post a Comment