aboutsummaryrefslogtreecommitdiffstats
path: root/notifications/notify-actions.sh
diff options
context:
space:
mode:
Diffstat (limited to 'notifications/notify-actions.sh')
-rwxr-xr-xnotifications/notify-actions.sh40
1 files changed, 40 insertions, 0 deletions
diff --git a/notifications/notify-actions.sh b/notifications/notify-actions.sh
new file mode 100755
index 0000000..651275c
--- /dev/null
+++ b/notifications/notify-actions.sh
@@ -0,0 +1,40 @@
+#!/bin/bash
+#
+# Copyright (C) 2026 Danilo M. <danix@danix.xyz>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# Pick one of a notification's actions with rofi and invoke it. The renderer
+# passes the labels and keys as arguments, so nothing here parses JSON.
+#
+# notify-actions.sh <id> <label> <key> [label key ...]
+
+set -u
+
+[[ $# -ge 3 ]] || { echo "usage: ${0##*/} <id> <label> <key> ..." >&2; exit 2; }
+
+id="$1"; shift
+labels=()
+keys=()
+while [[ $# -ge 2 ]]; do
+ labels+=("$1")
+ keys+=("$2")
+ shift 2
+done
+
+choice="$(printf '%s\n' "${labels[@]}" | rofi -dmenu -i -p "Notification")"
+[[ -n "$choice" ]] || exit 0
+
+for i in "${!labels[@]}"; do
+ if [[ "${labels[$i]}" == "$choice" ]]; then
+ notifyctl action "$id" "${keys[$i]}"
+ exit $?
+ fi
+done