config/shell: modernize systemctl helpers

This commit is contained in:
xeruf 2022-01-17 20:52:51 +01:00
parent cccbfa82a3
commit 4bc606de0a
2 changed files with 12 additions and 10 deletions

View File

@ -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

View File

@ -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"