3

Is there a way I can configure my linux box or editor like vim/emacs to automatically give executable file permission to certain file types ?

Currently if I want to write a bash script I need to manually give executable permission. I am looking for a way that whenever I create file having .bash or .sh extension It should give executable permission to that file.

3
  • @JohnWatts sorry I realized after posting question that is should belong to super user. How can I move question to super user.
    – Vivek Goel
    Aug 1, 2012 at 16:35
  • I'm actually not sure. I think it will get moved by the close operation automatically. It gets closed here and opened there, once it gets enough votes.
    – John Watts
    Aug 1, 2012 at 16:38
  • 1
    @VivekGoel you should also be looking at the presence of the magic cookie "hash-bang", not file extension.
    – event_jr
    Aug 1, 2012 at 16:41

3 Answers 3

9

Well the Emacs aspect of it definitely does fit on StackOverflow. Here is a bit of code to add to your init file to mark magic number "hash-bang" files executable:

(add-hook 'after-save-hook 'executable-make-buffer-file-executable-if-script-p)
1
  • Agreed. Almost every Emacs question involves a programmatic elisp solution, so such questions belong here IMO.
    – sanityinc
    Aug 2, 2012 at 11:17
4

One vim equivalent:

au BufWritePost,BufFilePost *.sh call system("chmod +x ".expand("%"))
1

vim-eunuch makes files with shebang lines executable, among other things.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .