prelude
prelude copied to clipboard
File permissions break sudoedit
I am running Prelude (emacs 27.2) on Arch Linux. It seems that when editing a file that looks like a bash script, something will automatically set +x on that file upon saving. Unfortunately that breaks sudoedit :
% echo $SUDO_EDITOR
emacsclient -nw -c
% sudoedit /etc/makepkg.conf
sudoedit: /var/tmp/makepkgXXgBYd1E.conf: bad file mode: 0711
sudoedit: /etc/makepkg.conf left unmodified
Steps to reproduce:
% mkdir bar
% echo '#!/hint/bash\nfoo' > bar/foo.conf
% chmod 644 bar/foo.conf
% sudo chown root:root bar bar/foo.conf
% SUDO_EDITOR=emacsclient sudoedit bar/foo.conf
# (make any change then C-x C-s)
sudoedit: /var/tmp/fooXXiFtpLJ.conf: bad file mode: 0711
sudoedit: bar/foo.conf left unmodified
How can I disable this behaviour? Thanks.
There's a hook in prelude-editor.el
that does this:
;; make a shell script executable automatically on save
(add-hook 'after-save-hook
'executable-make-buffer-file-executable-if-script-p)
You can use remove-hook
to remove it.
Is there any way to make Emacs "smart" on this? I'm not sure what it'd look like exactly (I can't find where sudoedit changes any environment variables with light testing), but it might come in handy.
We can have a more sophisticated hook - e.g. one that ignores certain files or runs additional predicate checks. It's easy to do, but I think it's going to be an overkill for most people.
I figured as much -- I was scratching my head trying to figure out the predicate checks to make. Not sure if just checking whether the owner of the file is root is enough... but like you say, it's probably overkill.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution and understanding!