summaryrefslogtreecommitdiffhomepage
path: root/etc/notify-once.sh
blob: 1c46401b4496dbfdb3ef1e1690780ca2158b9a62 (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
#!/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"