Refactor notifications work to use 1 interface for writing notifs & use dates

Summary of changes:
1. Always use the sxmo_notificationwrite.sh script to write notifications
   rather then sometimes using echo to the DIR
2. Reorder args for notiffile spec to be action as 1st line, watchfile 2nd, and
   rest as msg; this way msg can be multiple lines without propogating bugs
3. Write calls as a standard notification via sxmo_notificationwrite.sh
4. Use datestamps from notification files instead of filename, this way (3)
   works without extra logic
5. Various style fixes
This commit is contained in:
Miles Alan 2020-08-05 22:11:58 -05:00
parent e6635ba7ef
commit faf9bfc48d
7 changed files with 131 additions and 86 deletions

View file

@ -0,0 +1,32 @@
#!/usr/bin/env sh
NOTIFDIR="$XDG_CONFIG_HOME"/sxmo/notifications
notificationmenu() {
CHOICES="Close Menu"
for NOTIFFILE in "$NOTIFDIR"/*; do
NOTIFMSG="$(tail -n+3 "$NOTIFFILE" | tr "\n^" " ")"
NOTIFHRANDMIN="$(stat --printf %y "$NOTIFFILE" | grep -oE '[0-9]{2}:[0-9]{2}')"
CHOICES="
$CHOICES
$NOTIFHRANDMIN - $NOTIFMSG ^ $NOTIFFILE
"
done
PICKEDCONTENT="$(
printf "%b" "$CHOICES" |
xargs -0 echo |
sed '/^[[:space:]]*$/d' |
awk '{$1=$1};1' |
cut -d^ -f1 |
dmenu -c -i -fn "Terminus-18" -p "Notifs" -l 10
)"
[ "$PICKEDCONTENT" = "Close Menu" ] && exit 1
PICKEDNOTIFFILE="$(echo "$CHOICES" | grep "$PICKEDCONTENT" | cut -d^ -f2 | tr -d ' ')"
NOTIFACTION="$(head -n1 "$PICKEDNOTIFFILE")"
eval "$NOTIFACTION" &
rm "$PICKEDNOTIFFILE"
}
notificationmenu