From b96713de1bd71818d222be87c7bcba567813b44c Mon Sep 17 00:00:00 2001 From: Ivan Malison Date: Tue, 28 Feb 2017 12:04:04 -0800 Subject: [PATCH] [Linux] Support restarting system services with rofi_restart_service --- dotfiles/lib/bin/rofi_restart_service.sh | 30 ++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/dotfiles/lib/bin/rofi_restart_service.sh b/dotfiles/lib/bin/rofi_restart_service.sh index 864c0e8e..5f3314b2 100755 --- a/dotfiles/lib/bin/rofi_restart_service.sh +++ b/dotfiles/lib/bin/rofi_restart_service.sh @@ -1,4 +1,30 @@ #!/usr/bin/env zsh -systemctl --user list-unit-files | tail -n +2 | head -n -2 | - rofi -dmenu -i | get_cols 1 | xargs systemctl --user restart +export SYSTEMD_COLORS=0 + +function user_units { + SYSTEMD_COLORS=0 systemctl --user list-unit-files | tail -n +2 | head -n -2 | + awk '{print $0 " user"}' +} + +function system_units { + systemctl list-unit-files | tail -n +2 | head -n -2 | + awk '{print $0 " system"}' +} + +function restart_service { + result=$(get_cols 1 3) + service_name="$(printf $result | get_cols 1 | tr -d ' ')" + is_user="$(printf $result | get_cols 2)" + echo "$service_name" + case "$is_user" in + user*) + systemctl restart --user "$service_name" + ;; + system*) + sudo systemctl restart "$service_name" + ;; + esac +} + +{ user_units; system_units } | rofi -dmenu -i | restart_service