feat(systemd): preserve editor env for sudo commands

When running `systemctl` commands that require sudo, the users'
configured editor environment variables were not preserved. This
resulted in systemctl opening a default editor.

By instructing sudo to preserve the common environment variables for
configuring an editor, systemctl can see these variables and open the
users' preferred editor.

This is mostly relevant for the `sc-edit` alias.
This commit is contained in:
iyzana 2025-09-05 00:19:41 +02:00
commit c4d215e1dc

View file

@ -67,13 +67,15 @@ power_commands=(
suspend suspend
) )
readonly SUDO_PRESERVE_ENV="SYSTEMD_EDITOR,SUDO_EDITOR,VISUAL,EDITOR"
for c in $user_commands; do for c in $user_commands; do
alias "sc-$c"="systemctl $c" alias "sc-$c"="systemctl $c"
alias "scu-$c"="systemctl --user $c" alias "scu-$c"="systemctl --user $c"
done done
for c in $sudo_commands; do for c in $sudo_commands; do
alias "sc-$c"="sudo systemctl $c" alias "sc-$c"="sudo --preserve-env=$SUDO_PRESERVE_ENV systemctl $c"
alias "scu-$c"="systemctl --user $c" alias "scu-$c"="systemctl --user $c"
done done