summary refs log tree commit diff
path: root/bin/rcmenu
blob: 950c82cfe6dbf249a75d7e11e38cc37767ed55df (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
#!/bin/sh

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

export MENU_PROMPT="> rc"

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 -a rc rc "${_outp}"
		else
			notify-send -a rc -u critical -t 30000 rc "${act}ing ${svc} failed:\n<i>${_outp}</i>"
		fi
		printf "%s\n" "${_outp}"
	done
}

rc-status --servicelist \
	| awk '{printf "%25s\t%s\n", $1, $3}' \
	| menu --list=10 \
	| handle