summaryrefslogtreecommitdiffhomepage
path: root/etc/notify-once.sh
diff options
context:
space:
mode:
Diffstat (limited to 'etc/notify-once.sh')
-rw-r--r--etc/notify-once.sh31
1 files changed, 31 insertions, 0 deletions
diff --git a/etc/notify-once.sh b/etc/notify-once.sh
new file mode 100644
index 0000000..1c46401
--- /dev/null
+++ b/etc/notify-once.sh
@@ -0,0 +1,31 @@
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+help() {
+ echo "notify-send: send deduplicated notifications"
+ echo "Usage: notify-once <name> [ARGS]"
+ echo " ARGS are arguments passed directly to notify-send"
+}
+
+if [ $# -lt 1 ]; then
+ echo "Should get at least one argument, a name" >&2
+ help
+ exit 1
+fi
+APPNAME="$1"
+shift
+
+ID_PATH="/tmp/notify-state-$APPNAME"
+
+if [ -e "$ID_PATH" ]; then
+ # Exists, replace
+ ID=$(cat "$ID_PATH")
+ ID=$(notify-send -r "$ID" -p "$@")
+else
+ # Doesn't exist, create
+ ID=$(notify-send -p "$@")
+fi
+
+# Store new ID
+echo "$ID" >"$ID_PATH"