This repository has been archived by the owner on May 25, 2024. It is now read-only.
forked from emersion/mako
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makoctl
executable file
·105 lines (99 loc) · 2.26 KB
/
makoctl
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/sh -eu
usage() {
echo "Usage: makoctl <command> [options...]"
echo ""
echo "Commands:"
echo " dismiss [-a|--all] Dismiss the last or all notifications"
echo " invoke [-n id] [action] Invoke an action on the notification"
echo " with the given id, or the last"
echo " notification if none is given"
echo " menu [prog] [arg ...] Use [prog] [args ...] to select one"
echo " notification action to be invoked"
echo " list List notifications"
echo " reload Reload the configuration file"
echo " set <key>=<value> Set a global configuration option"
echo " help Show this help"
}
call() {
busctl -j --user call org.freedesktop.Notifications /fr/emersion/Mako \
fr.emersion.Mako -- "$@"
}
if [ $# -eq 0 ]; then
usage
exit 1
fi
case "$1" in
"dismiss")
[ $# -lt 2 ] && action="" || action="$2"
case "$action" in
"-a"|"--all")
call DismissAllNotifications
;;
"")
call DismissLastNotification
;;
*)
echo "makoctl: unrecognized option '$2'"
exit 1
;;
esac
;;
"invoke")
id=0
if [ $# -gt 1 ] && [ "$2" = "-n" ]; then
id="$3"
shift 2
fi
action="default"
if [ $# -gt 1 ]; then
action="$2"
fi
call InvokeAction "us" "$id" "$action"
;;
"menu")
shift 1
if ! type jq > /dev/null; then
echo >&2 "$0: jq is required to use 'menu'"
exit 1
fi
if array="$(call ListNotifications | jq -re '.data[0][0].actions.data | if length > 0 then . else false end')"; then
sel="$(jq -rn "$array|values[]" | "$@")"
sel="$(jq -rn --arg sel "$sel" "$array|to_entries[]|select(.value == \$sel).key")"
if [ -z "$sel" ]; then
echo >&2 "$0: No action selected"
exit 1
else
call InvokeAction "us" 0 "$sel"
fi
else
echo >&2 "$0: No actions found"
exit 1
fi
;;
"list")
call ListNotifications
;;
"reload")
call Reload
;;
"set")
if [ $# -lt 2 ]; then
echo >&2 "makoctl: missing argument for 'set'"
exit 1
fi
name="${2%%'='*}"
value="${2#*'='}"
if [ "$2" = "$name" ]; then
echo >&2 "makoctl: missing '=' in argument for 'set'"
exit 1
fi
call SetConfigOption "ss" "$name" "$value"
;;
"help"|"--help"|"-h")
usage
;;
*)
echo "makoctl: unrecognized command '$1'"
exit 1
;;
esac