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

Forum rules
Before you post please read how to get help
User avatar
Habitual
Level 13
Level 13
Posts: 4798
Joined: Sun Nov 21, 2010 8:31 pm

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

Postby Habitual » Mon Jun 25, 2012 3:08 pm

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...
Image
rkhunter 1.4.3 Tutorial
“The single biggest problem in communication is the illusion that it has taken place.”

User avatar
xenopeek
Level 24
Level 24
Posts: 20644
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

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

Postby xenopeek » Wed Jun 27, 2012 6:16 am

Cool :D
Image

User avatar
Habitual
Level 13
Level 13
Posts: 4798
Joined: Sun Nov 21, 2010 8:31 pm

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

Postby Habitual » Tue Jul 10, 2012 7:22 am

Vincent Vermeulen wrote:Cool :D


Well, I knew you would appreciate it. :)
Image
rkhunter 1.4.3 Tutorial
“The single biggest problem in communication is the illusion that it has taken place.”


Return to “Scripts & Bash”

Who is online

Users browsing this forum: No registered users and 1 guest