diff options
| author | Craig Jennings <c@cjennings.net> | 2026-06-30 17:34:32 -0400 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-06-30 17:34:32 -0400 |
| commit | dc2784b6c271bf7733259a1d5cd3657485ef7b1b (patch) | |
| tree | f148d693f5542d1d5e578b5f8173e84d13eec799 /modules/prog-shell.el | |
| parent | f53aaf2d6278a219dd19e4f40f2a4c3696ec838a (diff) | |
| download | dotemacs-dc2784b6c271bf7733259a1d5cd3657485ef7b1b.tar.gz dotemacs-dc2784b6c271bf7733259a1d5cd3657485ef7b1b.zip | |
fix(prog-shell): only auto-chmod scripts in prog-mode buffers
cj/make-script-executable runs from a global after-save-hook and set +x on any saved file whose first line was a shebang, in every buffer. A downloaded script you were reading, a template, or a shebang in a text or org file silently became executable. I gated it on derived-mode-p prog-mode, so it only acts on actual script buffers. Real scripts (sh-mode, python-mode) still get the fast path.
Diffstat (limited to 'modules/prog-shell.el')
| -rw-r--r-- | modules/prog-shell.el | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/modules/prog-shell.el b/modules/prog-shell.el index d7f97932..3ed51da1 100644 --- a/modules/prog-shell.el +++ b/modules/prog-shell.el @@ -166,8 +166,12 @@ Overrides default prog-mode keybindings with shell-specific commands." ;; Automatically set execute permission on shell scripts with shebangs (defun cj/make-script-executable () - "Make the current file executable if it has a shebang." + "Make the current file executable if it is a script buffer with a shebang. +Runs from a global `after-save-hook', so it gates on `prog-mode': a shebang in a +text, org, or fundamental-mode buffer (a script being read, quoted, or reviewed) +is left alone rather than silently made executable." (when (and buffer-file-name + (derived-mode-p 'prog-mode) (not (file-executable-p buffer-file-name)) (save-excursion (goto-char (point-min)) |
