summary refs log tree commit diff
path: root/bin/rcmenu
blob: 0fce6f4b458f20d341e90a723156d09469ec2cf4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/sh

set -e
[ -n "$DEBUG" ] && set -x

export MENU_PROMPT="󰑮 rc"
ico=/usr/share/icons/mdi/scalable/run-fast.svg

handle() {
	while read -r line; do
		svc=$(printf "%s" "${line}" | awk '{print $1}')
		mode=$(printf "%s" "${line}" | awk '{print $2}')
		act=restart
		[ "${mode}" = "started" ] && act=stop
		_outp=$(doas rc-service "${svc}" "${act}")
		if [ $? = 0 ]; then
			notify-send -i "${ico}" -a rc "${MENU_PROMPT}: ${svc}" "${_outp}"
		else
			notify-send -i "${ico}" -a rc -u critical -t 30000 "${MENU_PROMPT}: ${svc}" "${act}ing ${svc} failed:\n<i>${_outp}</i>"
		fi
		printf "%s\n" "${_outp}"
	done
}

rc-status --servicelist |
	menu --list=10 |
	tr -d '[' | tr -d ']' |
	handle