Last Updated: February 25, 2016
·
591
· gahtune

Automatically making scripts executable

I just found a tip for emacs by Stephan Arentz

I found the feature really helpful. so here the vim version:

function! MakeExecutable()
    if (strpart(getline(1), 0, 2) == '#!')
        silent !chmod +x %
    endif
endfunction

autocmd bufwritepost * call MakeExecutable()

It does exactly the same things (ie check if the first line start with "#!")

And in bonus:

nnoremap <silent> <Leader>w :r !echo "\#\! `which <cword>`"<CR>kdd

this mapping calls which to create a shebang. for example type python (or perl, tcl, ruby, ...) and on the word press <Leader> w it will replace the word with the correct shebang.