#!/bin/bash [ -n "$DEBUG" ] && set -x set -u export MENU_PROMPT="󰑮 rc" svdir=/run/s6-rc/servicedirs ico=/usr/share/icons/mdi/scalable/run-fast.svg menu_exitcode=-1 __list() { for sv in "$svdir"/*; do printf "%s " "$(basename "$sv")" doas -n s6-svstat "$sv" done | column -t } __handle() { while read -r line; do sv=$(printf "%s" "${line}" | awk '{print $1}') state=$(printf "%s" "${line}" | awk '{print $2}') case "$state" in up) msg=$(doas -n s6-rc -v2 -d change "$sv") if [ $menu_exitcode -eq 18 ]; then action=stopp else action=restart sleep 0.5 msg=$(doas -n s6-rc -v2 -u change "$sv") fi ;; down) action=start msg=$(doas -n s6-rc -v2 -u change "$sv") ;; *) msg=$(printf "unknown service state: %s\n" "$state") false ;; esac if [ "$?" = 0 ]; then notify-send -i "${ico}" -a rc "${sv}" "${action}ed" else notify-send -i "${ico}" -a rc -u critical -t 30000 "${sv}" "${action}ing ${sv} failed:\n${msg}" fi printf "%s\n" "${msg}" done } svs=$(__list | menu --list=10) menu_exitcode=$? __handle <<<"$svs"