Created
January 18, 2021 11:40
-
-
Save pstray/1fe1166c9c0d84e8965ca9f7e9f2054d to your computer and use it in GitHub Desktop.
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 ps: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 'ps:auto-file-mode) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment