summarylogtreecommitdiffstats
path: root/dctl
blob: a8c804e6c7bb031fa5ca308ce1ae7a7fddea731b (plain)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/sh

# All credit and criticisms can be directed to Aelius @ Freenode

#TODO
# - implement status, detailed info piped to dmenu
# - make failed list prettier

export ${SUDO_ASKPASS-/usr/bin/daskpass}
systemctlArgs="--type service,timer,automount,socket --no-pager"
action=$(dmenu <<EOF
start
stop
restart
enable
enable --now
disable
disable --now
daemon reload
--user start
--user stop
--user restart
--user enable
--user enable --now
--user disable
--user disable --now
--user daemon reload
EOF
)

[ -z "$action" ] && exit 0 # if no action, quit
if [ -z $(echo $action | sed -e '/--user/d') ]; then # if action contains '--user'
	systemctl --user $systemctlArgs | sed -e '/failed/!d' -e 's/●\s//' > /tmp/dctl
	systemctl --user $systemctlArgs list-unit-files >> /tmp/dctl
	unit=$(dmenu -l 20 </tmp/dctl | sed 's/\s.*$//') # List --user units
	[ -z $unit ] && exit 0 # if no unit, quit
	systemctl $action $unit && notify-send 'dctl - success' "systemctl $action $unit"
else # action for system
	systemctl $systemctlArgs | sed -e '/failed/!d' -e 's/●\s//' > /tmp/dctl
	systemctl $systemctlArgs list-unit-files >> /tmp/dctl
	unit=$(dmenu -l 20 </tmp/dctl | sed 's/\s.*$//') # List --user units
	[ -z $unit ] && exit 0 # if no unit, quit
	sudo -A systemctl $action $unit && notify-send 'dctl - success' "systemctl $action $unit"
fi