From c4d215e1dc48ac903eab7e5745cdaaebf3b926e4 Mon Sep 17 00:00:00 2001 From: iyzana <16743652+iyzana@users.noreply.github.com> Date: Fri, 5 Sep 2025 00:19:41 +0200 Subject: [PATCH] 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. --- plugins/systemd/systemd.plugin.zsh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/systemd/systemd.plugin.zsh b/plugins/systemd/systemd.plugin.zsh index 382a57b29..3ba9dd23d 100644 --- a/plugins/systemd/systemd.plugin.zsh +++ b/plugins/systemd/systemd.plugin.zsh @@ -67,13 +67,15 @@ power_commands=( suspend ) +readonly SUDO_PRESERVE_ENV="SYSTEMD_EDITOR,SUDO_EDITOR,VISUAL,EDITOR" + for c in $user_commands; do alias "sc-$c"="systemctl $c" alias "scu-$c"="systemctl --user $c" done 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" done