Created
January 27, 2020 12:58
-
-
Save pstray/f9dceac152d49942230250c5635c2293 to your computer and use it in GitHub Desktop.
A small elisp snippet for automatic +x on scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun my:auto-file-mode () | |
(when (save-excursion | |
(save-restriction | |
(widen) | |
(goto-char (point-min)) | |
(save-match-data | |
(looking-at "^#!")))) | |
(let* ((cmode (file-modes buffer-file-name)) | |
(nmode (logior cmode (lsh (logand cmode #o444) -2)))) | |
(when (not (= cmode nmode)) | |
(message "Changing mode of script %s to %o" | |
buffer-file-name nmode) | |
(set-file-modes buffer-file-name nmode))))) | |
(add-hook 'after-save-hook 'my:auto-file-mode) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment