Skip to content

Instantly share code, notes, and snippets.

@jonEbird
Created March 13, 2015 19:26
Show Gist options
  • Save jonEbird/ddabb9067ace8f119706 to your computer and use it in GitHub Desktop.
Save jonEbird/ddabb9067ace8f119706 to your computer and use it in GitHub Desktop.
Make scripts executable with conditions
;; Make files that should be executable, executable
(defun jsm:make-buffer-file-executable-if-script-p ()
"Limit the situations that I want scripts to be made executable"
(interactive)
(let ((parent-dir (file-name-base
(directory-file-name
(file-name-directory buffer-file-name)))))
(if (cond ((eq major-mode 'sh-mode) t)
((and (eq major-mode 'python-mode)
(string= parent-dir "scripts")) t)
(t nil))
(executable-make-buffer-file-executable-if-script-p))))
(add-hook 'after-save-hook
'jsm:make-buffer-file-executable-if-script-p)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment