Skip to content

Instantly share code, notes, and snippets.

@pstray
Created January 18, 2021 11:40
Show Gist options
  • Save pstray/1fe1166c9c0d84e8965ca9f7e9f2054d to your computer and use it in GitHub Desktop.
Save pstray/1fe1166c9c0d84e8965ca9f7e9f2054d to your computer and use it in GitHub Desktop.
(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