You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

25 lines
836 B

#!/usr/bin/env sh
NOTIFDIR="$XDG_DATA_HOME"/sxmo/notifications
# 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