Skip to content

Instantly share code, notes, and snippets.

@pstray
Created January 27, 2020 12:58
Show Gist options
  • Save pstray/f9dceac152d49942230250c5635c2293 to your computer and use it in GitHub Desktop.
Save pstray/f9dceac152d49942230250c5635c2293 to your computer and use it in GitHub Desktop.
A small elisp snippet for automatic +x on scripts
(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