~mil/sxmo-utils

ref: fa0d9b6e2d6c70df245f1b36578990ad128b9c19 sxmo-utils/scripts/notifications/sxmo_notificationwrite.sh -rwxr-xr-x 904 bytes
fa0d9b6eMaarten van Gompel fixed 24h conky 1 year, 4 months ago
                                                                                
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
#!/usr/bin/env sh

# include common definitions
# shellcheck source=scripts/core/sxmo_common.sh
. "$(dirname "$0")/sxmo_common.sh"

# Takes 4 args:
# (1) the filepath of the notification to write (or random to generate a random id)
# (2) action notification invokes upon selecting
# (3) the file to watch for deactivation.
# (4) description of notification
NOTIFFILEPATHTOWRITE="$1"
ACTION="$2"
WATCHFILE="$3"
NOTIFMSG="$4"

writenotification() {
	lsof | grep "$WATCHFILE" && exit 0 # Already viewing watchfile, nops
	mkdir -p "$NOTIFDIR"
	if [ "$NOTIFFILEPATHTOWRITE" = "random" ]; then
		NOTIFFILEPATHTOWRITE="$NOTIFDIR/$(tr -dc 'a-zA-Z0-9' < /dev/urandom | head -c 10)"
	fi
	touch "$NOTIFFILEPATHTOWRITE"
	printf %b "rm -f $NOTIFFILEPATHTOWRITE; $ACTION\n$WATCHFILE\n$NOTIFMSG\n" > "$NOTIFFILEPATHTOWRITE"
}

[ "$#" -lt 4 ] && echo "Need >=4 args to create a notification" && exit 1
writenotification