[Linux] Properly handle escaped template unit names in systemd

This commit is contained in:
Ivan Malison 2018-06-14 15:50:38 -07:00
parent f9fed49684
commit 4a96845974
No known key found for this signature in database
GPG Key ID: 62530EFBE99DC2F8

View File

@ -1,7 +1,7 @@
#!/usr/bin/env sh #!/usr/bin/env sh
export SYSTEMD_COLORS=0 export SYSTEMD_COLORS=0
term=${ROFI_SYSTEMD_TERM-termite -e} term=${ROFI_SYSTEMD_TERM-urxvt -e}
default_action=${ROFI_SYSTEMD_DEFAULT_ACTION-"list_actions"} default_action=${ROFI_SYSTEMD_DEFAULT_ACTION-"list_actions"}
function unit_files { function unit_files {
@ -16,7 +16,7 @@ function running_units {
function get_units { function get_units {
{ unit_files "--$1"; running_units "--$1"; } | { unit_files "--$1"; running_units "--$1"; } | sort -u -k1,1 |
awk -v unit_type="$1" '{print $0 " " unit_type}' awk -v unit_type="$1" '{print $0 " " unit_type}'
} }
@ -74,7 +74,7 @@ function select_service_and_act {
esac esac
selection="$(echo $result | sed -n 's/ \+/ /gp')" selection="$(echo $result | sed -n 's/ \+/ /gp')"
service_name="$(echo $selection | awk '{ print $1 }' | tr -d ' ')" service_name=$(echo "$selection" | awk '{ print $1 }' | tr -d ' ')
is_user="$(echo $selection | awk '{ print $3 }' )" is_user="$(echo $selection | awk '{ print $3 }' )"
case "$is_user" in case "$is_user" in
@ -92,20 +92,20 @@ function select_service_and_act {
to_run="$(get_command_with_args)" to_run="$(get_command_with_args)"
echo "Running $to_run" echo "Running $to_run"
eval "$to_run" eval "$term $to_run"
} }
function get_command_with_args { function get_command_with_args {
case "$action" in case "$action" in
"tail") "tail")
echo "$term 'journalctl $user_arg -u $service_name -f'" echo "journalctl $user_arg -u '$service_name' -f"
;; ;;
"list_actions") "list_actions")
action=$(echo "$all_actions" | rofi -dmenu -i -p "Select action: ") action=$(echo "$all_actions" | rofi -dmenu -i -p "Select action: ")
get_command_with_args get_command_with_args
;; ;;
*) *)
echo "$command $action $service_name" echo "$command $action '$service_name'"
;; ;;
esac esac
} }