Because I like to automate things, I write a lot of shell scripts. Sometimes it’s just some simple shell code, other times the script loads and executes a Scheme program. Almost every time I do this, I forget to set the execute bits on the script so, of course, it fails the first time I try to run it. Here, via Hacker News, is a simple trick to automate making your scripts executable. Add the following to your .emacs
or init.el
file.
(add-hook 'after-save-hook 'executable-make-buffer-file-executable-if-script-p)
This will check when you save a file to see if it looks like a script and if it does, make it executable. The executable-make-buffer-file-executable-if-script-p
function does the intelligent thing when the file is already executable so it won’t mess up any file mode bits that you’ve already set.