From 4bc606de0ac44bc57de834d3c8bfa13609397eb9 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Mon, 17 Jan 2022 20:52:51 +0100 Subject: [PATCH] config/shell: modernize systemctl helpers --- .config/shell/functions | 8 ++++---- .local/bin/scripts/edconf | 14 ++++++++------ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/.config/shell/functions b/.config/shell/functions index f682b66..bb9f11d 100644 --- a/.config/shell/functions +++ b/.config/shell/functions @@ -142,10 +142,10 @@ alias scud='systemctl --user disable --now' # Reload or restart matching systemctl service scr() { - systemctl --user reload "$1" || - sudo systemctl reload "$1" || - systemctl --user restart "$1" || - sudo systemctl restart "$1" + echo -n "User: " + systemctl --user reload-or-restart "$1" || + { echo -n "System: " && sudo systemctl reload-or-restart "$1"; } && + echo "Successful reload" } # Restart matching systemctl service with time for adjustments inbetween diff --git a/.local/bin/scripts/edconf b/.local/bin/scripts/edconf index 858724c..7e4865e 100755 --- a/.local/bin/scripts/edconf +++ b/.local/bin/scripts/edconf @@ -21,11 +21,13 @@ touch "$conf_cache" sel=$(listconf | fzf -1 -0 --tiebreak=end,length --preview '$(test -r {} || echo "sudo") bat --color=always --style=numbers --line-range :200 {}' --query="$1" --history "$conf_cache_dir/searches") case "$sel" in - "") exit 1;; - /etc/sudoers) sudo visudo;; - /etc/fstab) sudoedit "$sel" && sudo findmnt --verify;; - /etc/default/grub) sudoedit "$sel" && sudo grub-mkconfig -o /boot/grub/grub.cfg;; - /etc/locale.gen) sudoedit "$sel" && sudo locale-gen;; - *) $(test -w "$sel" || echo sudo) "$EDITOR" "$sel";; + ("") exit 1;; + (/etc/sudoers) sudo visudo;; + (/etc/fstab) sudoedit "$sel" && sudo findmnt --verify;; + (/etc/default/grub) sudoedit "$sel" && sudo grub-mkconfig -o /boot/grub/grub.cfg;; + (/etc/locale.gen) sudoedit "$sel" && sudo locale-gen;; + (/etc/nginx/*) sudoedit "$sel" && nginx -t && nginx -s reload;; + (/etc/caddy/*) sudoedit "$sel" && sudo systemctl reload caddy;; + (*) $(test -w "$sel" || echo sudo) "$EDITOR" "$sel";; esac echo "$sel" | cat - "$conf_cache" | head -20 >"$conf_tmp" && mv "$conf_tmp" "$conf_cache"