Page 1 of 1

vi[m] hook to make .sh files automatically executable

Posted: Mon Jun 25, 2012 3:08 pm
by Habitual
I found this today and thought I'd share.
add the following lines to the end of your ~/.vimrc file

Code: Select all

au BufWritePost * if getline(1) =~ "^#!" | if getline(1) =~ "/bin/" | silent !chmod a+x <afile> | endif | endif
This code will automatically change the file to executable if the first line contains both "#!" and "/bin/".
Once you add #!/bin/sh (for example) to the start of a file and save it, the file will be immediately executable.
755 upon exiting vim.

YMMV...

Re: vi[m] hook to make .sh files automatically executable

Posted: Wed Jun 27, 2012 6:16 am
by xenopeek
Cool :D

Re: vi[m] hook to make .sh files automatically executable

Posted: Tue Jul 10, 2012 7:22 am
by Habitual
xenopeek wrote:Cool :D
Well, I knew you would appreciate it. :)