Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

migrated from stackoverflow.com Aug 28 '12 at 3:49

This question came from our site for professional and enthusiast programmers.

    
@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 '12 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 '12 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 '12 at 16:41
    
@event_jr thanks –  Vivek Goel Aug 1 '12 at 16:58
add comment

3 Answers

up vote 9 down vote accepted

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)
share|improve this answer
    
Agreed. Almost every Emacs question involves a programmatic elisp solution, so such questions belong here IMO. –  sanityinc Aug 2 '12 at 11:17
add comment

One vim equivalent:

au BufWritePost,BufFilePost *.sh call system("chmod +x ".expand("%"))
share|improve this answer
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.