illiliti / ssu

Extremely simple su utility
GNU General Public License v3.0
71 stars 3 forks source link

set up clean environment when using -e #11

Closed j0057 closed 1 year ago

j0057 commented 1 year ago

Create a clean environment by default when editing a file using the -e flag, and use the logic for the -p flag to allow preserving the user's environment.

illiliti commented 1 year ago

The -e flag intentionally preserves user environment, so that invoked editor could inherit user configuration. If you need clean environment, you can directly run editor: ssu <editor> <file>...

j0057 commented 1 year ago

That's a shame: I get Xauthority warnings when using ssu -e as is, because DISPLAY is set by Xwayland. The help output documents -p as being relevant to the -e code path as well, which based on the code as it is it isn't, because the !pflag test is never actually reached when using -e.

I suppose I'll set up an alias like alias sse='ssu -- $EDITOR' then. Thanks!

illiliti commented 1 year ago

You could point EDITOR to a script which checks uid, resets environment if needed and runs editor. But I guess you want to keep things simple and having script is not ideal for you, hence alias is better, yeah.

FWIW I have considered making -e act as sudoedit before, which is exactly what you need, but it's rather too complex as it is implies copying files and their metadata, then moving those files to their original location and also making sure there's no TOCTOU or race condition involved(sudo has suffered from them much). I may reconsider this idea later, but for now I think it is acceptable tradeoff that -e runs editor with user environment.

The help output documents -p as being relevant to the -e code path as well

Fixed, thanks!