Notification service scripts / modifications rewritten for grammar and style. -Timestamps will appear in the notifications.sh menu now. -Corrected LED behavior when starting the notification service. iressa (1): Notification service v3 configs/appcfg/dunst.conf | 2 ++ scripts/core/sxmo_appmenu.sh | 13 ++++++-- scripts/core/sxmo_notifications.sh | 13 ++++++++ scripts/core/sxmo_notificationservice.sh | 40 ++++++++++++++++++++++++ scripts/core/sxmo_notificationwrite.sh | 30 ++++++++++++++++++ scripts/core/sxmo_xinit.sh | 1 + scripts/modem/sxmo_modemmonitor.sh | 32 ++++++++++--------- 7 files changed, 114 insertions(+), 17 deletions(-) create mode 100755 scripts/core/sxmo_notifications.sh create mode 100755 scripts/core/sxmo_notificationservice.sh create mode 100755 scripts/core/sxmo_notificationwrite.sh -- 2.27.0
Thanks for sending - comments inline. This is very close, we just need to resolve a few style things to make this simpler to understand & easier to maintain. Overall notes: - There's no need to embed dates into the notification files' contents. That metadata can be used from the file's timestamp - If dates are no longer embedded; there are then just two fields for each notification; notification description & watch file. Seems like it'd be nice to change the notification file format to a 2 line file (e.g. 1st line being the file to watch, and the second line being the description). This would save alot of field cutting and awk grepping for NF. Head/tail/wc -l are less verbose & simpler to understand. - Vibration/LED setting/Dunst logic is spread out between both the watcher service script and the write script. This should be in one place - e.g. just in the watcher service; so the notification write script should be relatively 'dumb'. E.g. really all the write script needs to do is actually write the file (and error-check upfront). Also if we do this then the script name is actually self-documenting. The heavy lifting can all be in the monitor script. > --- > configs/appcfg/dunst.conf | 2 ++ > scripts/core/sxmo_appmenu.sh | 13 ++++++-- > scripts/core/sxmo_notifications.sh | 13 ++++++++ > scripts/core/sxmo_notificationservice.sh | 40 ++++++++++++++++++++++++ > scripts/core/sxmo_notificationwrite.sh | 30 ++++++++++++++++++ > scripts/core/sxmo_xinit.sh | 1 + > scripts/modem/sxmo_modemmonitor.sh | 32 ++++++++++--------- > 7 files changed, 114 insertions(+), 17 deletions(-) > create mode 100755 scripts/core/sxmo_notifications.sh > create mode 100755 scripts/core/sxmo_notificationservice.sh > create mode 100755 scripts/core/sxmo_notificationwrite.sh > > diff --git a/configs/appcfg/dunst.conf b/configs/appcfg/dunst.conf > index a7f9323..b2bddee 100644 > --- a/configs/appcfg/dunst.conf > +++ b/configs/appcfg/dunst.conf > @@ -32,6 +32,8 @@ > title = Dunst > class = Dunst > startup_notification = false > + mouse_left_click = do_action > + > [shortcuts] > close_all = ctrl+shift+space > > diff --git a/scripts/core/sxmo_appmenu.sh b/scripts/core/sxmo_appmenu.sh > index c53b140..b0aba1a 100755 > --- a/scripts/core/sxmo_appmenu.sh > +++ b/scripts/core/sxmo_appmenu.sh > @@ -1,6 +1,7 @@ > #!/usr/bin/env sh > trap gracefulexit INT TERM > WIN=$(xdotool getwindowfocus) > +NOTIFDIR="$XDG_CONFIG_HOME"/sxmo/notifications > > gracefulexit() { > echo "Gracefully exiting $0" > @@ -334,8 +335,16 @@ getprogchoices() { > # E.g. sets CHOICES var > programchoicesinit "$@" > > + # Decorate menu at top w/ notifications if they exist > + NOTIFICATIONS="$(find "$NOTIFDIR"/* -type f | grep -vc "sxmo_incomingcall" || echo 0)" > + echo "$NOTIFICATIONS" | grep -v 0 && > + CHOICES=" > + Notifications ($(echo "$NOTIFICATIONS" | cut -d " " -f1)) ^ 0 ^ sxmo_notifications.sh > + $CHOICES > + " > + > # Decorate menu at top w/ incoming call entry if present > - INCOMINGCALL="$(cat /tmp/sxmo_incomingcall || echo NOCALL)" > + INCOMINGCALL="$(cat "$NOTIFDIR"/sxmo_incomingcall || echo NOCALL)" > if echo "$INCOMINGCALL" | grep -v NOCALL; then > CALLID="$(echo "$INCOMINGCALL" | cut -d: -f1)" > CALLNUM="$(echo "$INCOMINGCALL" | cut -d: -f2)" > @@ -398,4 +407,4 @@ pgrep -f "$(command -v sxmo_appmenu.sh)" | grep -Ev "^${$}$" | xargs kill -TERM > DMENUIDX=0 > PICKED="" > ARGS="$*" > -mainloop > \ No newline at end of file > +mainloop > diff --git a/scripts/core/sxmo_notifications.sh b/scripts/core/sxmo_notifications.sh > new file mode 100755 > index 0000000..3d9cf46 > --- /dev/null > +++ b/scripts/core/sxmo_notifications.sh > @@ -0,0 +1,13 @@ > +#!/usr/bin/env sh > + > +NOTIFDIR="$XDG_CONFIG_HOME"/sxmo/notifications > + > +while true; do > + CHOICES="$(find "$NOTIFDIR"/ -type f -not -name 'sxmo_incomingcall' -exec cat {} +)" > + PICKED="$(printf %b "$CHOICES\nClose Menu" | cut -f1 | dmenu -c -i -fn "Terminus-18" -p "Notifs" -l 10)" > + > + echo "$PICKED" | grep "Close Menu" && exit 0 > + > + $(printf %b "$CHOICES" | grep "$PICKED" | cut -f2) > + exit 0 Exit 0 is implied at EOF - you can remove this.
Copy & paste the following snippet into your terminal to import this patchset into git:
curl -s https://lists.sr.ht/~mil/sxmo-devel/patches/11716/mbox | git am -3Learn more about email & git
--- configs/appcfg/dunst.conf | 2 ++ scripts/core/sxmo_appmenu.sh | 13 ++++++-- scripts/core/sxmo_notifications.sh | 13 ++++++++ scripts/core/sxmo_notificationservice.sh | 40 ++++++++++++++++++++++++ scripts/core/sxmo_notificationwrite.sh | 30 ++++++++++++++++++ scripts/core/sxmo_xinit.sh | 1 + scripts/modem/sxmo_modemmonitor.sh | 32 ++++++++++--------- 7 files changed, 114 insertions(+), 17 deletions(-) create mode 100755 scripts/core/sxmo_notifications.sh create mode 100755 scripts/core/sxmo_notificationservice.sh create mode 100755 scripts/core/sxmo_notificationwrite.sh diff --git a/configs/appcfg/dunst.conf b/configs/appcfg/dunst.conf index a7f9323..b2bddee 100644 --- a/configs/appcfg/dunst.conf +++ b/configs/appcfg/dunst.conf @@ -32,6 +32,8 @@ title = Dunst class = Dunst startup_notification = false + mouse_left_click = do_action + [shortcuts] close_all = ctrl+shift+space diff --git a/scripts/core/sxmo_appmenu.sh b/scripts/core/sxmo_appmenu.sh index c53b140..b0aba1a 100755 --- a/scripts/core/sxmo_appmenu.sh +++ b/scripts/core/sxmo_appmenu.sh @@ -1,6 +1,7 @@ #!/usr/bin/env sh trap gracefulexit INT TERM WIN=$(xdotool getwindowfocus) +NOTIFDIR="$XDG_CONFIG_HOME"/sxmo/notifications gracefulexit() { echo "Gracefully exiting $0" @@ -334,8 +335,16 @@ getprogchoices() { # E.g. sets CHOICES var programchoicesinit "$@" + # Decorate menu at top w/ notifications if they exist + NOTIFICATIONS="$(find "$NOTIFDIR"/* -type f | grep -vc "sxmo_incomingcall" || echo 0)" + echo "$NOTIFICATIONS" | grep -v 0 && + CHOICES=" + Notifications ($(echo "$NOTIFICATIONS" | cut -d " " -f1)) ^ 0 ^ sxmo_notifications.sh + $CHOICES + " + # Decorate menu at top w/ incoming call entry if present - INCOMINGCALL="$(cat /tmp/sxmo_incomingcall || echo NOCALL)" + INCOMINGCALL="$(cat "$NOTIFDIR"/sxmo_incomingcall || echo NOCALL)" if echo "$INCOMINGCALL" | grep -v NOCALL; then CALLID="$(echo "$INCOMINGCALL" | cut -d: -f1)" CALLNUM="$(echo "$INCOMINGCALL" | cut -d: -f2)" @@ -398,4 +407,4 @@ pgrep -f "$(command -v sxmo_appmenu.sh)" | grep -Ev "^${$}$" | xargs kill -TERM DMENUIDX=0 PICKED="" ARGS="$*" -mainloop \ No newline at end of file +mainloop diff --git a/scripts/core/sxmo_notifications.sh b/scripts/core/sxmo_notifications.sh new file mode 100755 index 0000000..3d9cf46 --- /dev/null +++ b/scripts/core/sxmo_notifications.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env sh + +NOTIFDIR="$XDG_CONFIG_HOME"/sxmo/notifications + +while true; do + CHOICES="$(find "$NOTIFDIR"/ -type f -not -name 'sxmo_incomingcall' -exec cat {} +)" + PICKED="$(printf %b "$CHOICES\nClose Menu" | cut -f1 | dmenu -c -i -fn "Terminus-18" -p "Notifs" -l 10)" + + echo "$PICKED" | grep "Close Menu" && exit 0 + + $(printf %b "$CHOICES" | grep "$PICKED" | cut -f2) + exit 0 +done diff --git a/scripts/core/sxmo_notificationservice.sh b/scripts/core/sxmo_notificationservice.sh new file mode 100755 index 0000000..d97b26b --- /dev/null +++ b/scripts/core/sxmo_notificationservice.sh @@ -0,0 +1,40 @@
We should probably call this sxmo_notificationmonitor.sh to follow the same pattern as sxmo_modemmonitor.sh
+#!/usr/bin/env sh + +# This script should be run to initialize the notification watchers. + +NOTIFDIR="$XDG_CONFIG_HOME"/sxmo/notifications + +notifyd(){ + inotifywait "$1" && rm -f "$2" +}
Generally I'd avoid one-line functions like this when only called from one place. If not give a better name, notifyd is ambiguous - names of functions should be verbose and self-descriptive. > + > +handlecreation(){ > + sxmo_setpineled green 1 > + # Start notification watcher if it matches the sxmo_notificationwrite format > + awk 'BEGIN {FS="\t"} ; {print NF}' "$1" | grep -v 3 || > + ( notifyd "$(cut -f3 "$1")" "$1" & ) Avoiding the one-line function, you could do the same with the following: { inotifywait "$(cut -f3 "$1")" && rm -f "$1" } & > +} > + > +sxmo_setpineled green 0 > +for NOTIF in "$NOTIFDIR"/*; do > + [ -f "$NOTIF" ] || continue > + handlecreation "$NOTIF" > +done > + > +while true; do > + { > + inotifywait -e create,moved_to,delete,delete_self,moved_from "$NOTIFDIR"/ > /tmp/notifyd > + STATUS="$(tail -1 /tmp/notifyd)" There's no reason to use a temp file here. Also STATUS is ambiguous, use the variable name to document the return format. You could do something like: DIREVENTANDFILE="$( inotifywait -e create,moved_to,delete,delete_self,moved_from "$NOTIFDIR"/ | tail -1 /tmp/notifyd )"
+ +handlecreation(){ + sxmo_setpineled green 1 + # Start notification watcher if it matches the sxmo_notificationwrite format + awk 'BEGIN {FS="\t"} ; {print NF}' "$1" | grep -v 3 || + ( notifyd "$(cut -f3 "$1")" "$1" & ) +} + +sxmo_setpineled green 0 +for NOTIF in "$NOTIFDIR"/*; do + [ -f "$NOTIF" ] || continue + handlecreation "$NOTIF" +done + +while true; do + { + inotifywait -e create,moved_to,delete,delete_self,moved_from "$NOTIFDIR"/ > /tmp/notifyd + STATUS="$(tail -1 /tmp/notifyd)" + case "$(echo "$STATUS" | cut -d" " -f2)" in + "CREATE"|"MOVED_TO") + NOTIFFILE="$NOTIFDIR/$(echo "$STATUS" | cut -d" " -f3)" + handlecreation "$NOTIFFILE" + ;; + + "DELETE"|"DELETE_SELF"|"MOVED_FROM") + find "$NOTIFDIR"/ -type f -mindepth 1 | read -r || sxmo_setpineled green 0 + ;; + esac + } +done +exit 0
Exit 0 is implied at EOF - you can remove this.
diff --git a/scripts/core/sxmo_notificationwrite.sh b/scripts/core/sxmo_notificationwrite.sh new file mode 100755 index 0000000..b51a1d5 --- /dev/null +++ b/scripts/core/sxmo_notificationwrite.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env sh + +# This script takes 3 arguments, (1) a fuzzy description of the notification, (2) the action that the notification invokes upon selecting, and (3) the file to watch for deactivation. +# The message will first be fed to Dunst, and then will be handled based on whether the user interacts with the notification or not. +# A notification file has 3 different fields, (1) a timestamp with a fuzzy description, (2) the selection action, and (3) the watch file. + +NOTIFDIR="$XDG_CONFIG_HOME"/sxmo/notifications +TIMEFORMAT="$(date "+%H:%M")" + +mkdir -p "$NOTIFDIR" +echo "$3" | grep -v . && { echo "Not enough args."; exit 2; } + +# Don't send a notification if we're already looking at it! +lsof | grep "$3" && exit 0
Nice trick :)
+ +{ + sxmo_vibratepine 200; + sleep 0.1; + sxmo_vibratepine 200; + sleep 0.1; + sxmo_vibratepine 200; +} &
We should move the logic for vibrating and dunst sending into the watcher so that this is all in one place. This script would then be alot simpler. > + > +# Dunstify and handle input > +DUNST_RETURN=$(dunstify --action="2,open" "$1"); > + echo "$DUNST_RETURN" | grep -v 2 || { $2& exit 0; } > + OUTFILE=$NOTIFDIR/$(date "+%Y_%m_%d_%H_%M_%S_%N").tsv > + printf %b "$TIMEFORMAT $1\t$2\t$3\n" > "$OUTFILE" $OUTFILE will already contains the date; less duplication of (meta)data is better.
+ +# Dunstify and handle input +DUNST_RETURN=$(dunstify --action="2,open" "$1"); + echo "$DUNST_RETURN" | grep -v 2 || { $2& exit 0; } + OUTFILE=$NOTIFDIR/$(date "+%Y_%m_%d_%H_%M_%S_%N").tsv + printf %b "$TIMEFORMAT $1\t$2\t$3\n" > "$OUTFILE" + +exit 0
Exit 0 is implied at EOF - you can remove this. > diff --git a/scripts/core/sxmo_xinit.sh b/scripts/core/sxmo_xinit.sh > index ea478af..3d28627 100755 > --- a/scripts/core/sxmo_xinit.sh > +++ b/scripts/core/sxmo_xinit.sh > @@ -39,6 +39,7 @@ daemons() { > autocutsel & > autocutsel -selection PRIMARY & > sxmo_statusbar.sh & > + sxmo_notificationservice.sh & > } > > daemonsneedingdbus() { > diff --git a/scripts/modem/sxmo_modemmonitor.sh b/scripts/modem/sxmo_modemmonitor.sh > index 6283df3..0e94063 100755 > --- a/scripts/modem/sxmo_modemmonitor.sh > +++ b/scripts/modem/sxmo_modemmonitor.sh > @@ -1,6 +1,7 @@ > #!/usr/bin/env sh > TIMEOUT=3 > LOGDIR="$XDG_CONFIG_HOME"/sxmo/modem > +NOTIFDIR="$XDG_CONFIG_HOME"/sxmo/notifications > trap "gracefulexit" INT TERM > > err() { > @@ -10,7 +11,6 @@ err() { > > gracefulexit() { > echo "gracefully exiting $0!" > - sxmo_setpineled green 0 > kill -9 0 > } > > @@ -28,14 +28,14 @@ checkforincomingcalls() { > )" > > if echo "$VOICECALLID" | grep -v .; then > - rm -f /tmp/sxmo_incomingcall > + rm -f "$NOTIFDIR/sxmo_incomingcall" > return > fi > > if [ -x "$XDG_CONFIG_HOME/sxmo/hooks/ring" ]; then > "$XDG_CONFIG_HOME/sxmo/hooks/ring" > else > - sxmo_vibratepine 2000 & sxmo_setpineled green 1 > + sxmo_vibratepine 2000 & > fi > > # Delete all previous calls which have been terminated calls > @@ -61,7 +61,7 @@ checkforincomingcalls() { > TIME="$(date --iso-8601=seconds)" > mkdir -p "$LOGDIR" > printf %b "$TIME\tcall_ring\t$INCOMINGNUMBER\n" >> "$LOGDIR/modemlog.tsv" > - echo "$VOICECALLID:$INCOMINGNUMBER" > /tmp/sxmo_incomingcall > + printf %b "$VOICECALLID:$INCOMINGNUMBER\n" > "$NOTIFDIR/sxmo_incomingcall" > echo "Number: $INCOMINGNUMBER (VOICECALLID: $VOICECALLID)" > } > > @@ -74,18 +74,11 @@ checkfornewtexts() { > echo "$TEXTIDS" | grep -v . && return > > # Loop each textid received and read out the data into appropriate logfile > - { > - sxmo_setpineled green 1 > - sxmo_vibratepine 200; > - sleep 0.1; > - sxmo_vibratepine 200; > - sleep 0.1; > - sxmo_vibratepine 200; > - } & > - > - for TEXTID in $(printf %b "$TEXTIDS") ; do > + for TEXTID in $TEXTIDS; do > + > TEXTDATA="$(mmcli -m "$(modem_n)" -s "$TEXTID" -K)" > TEXT="$(echo "$TEXTDATA" | grep sms.content.text | sed -E 's/^sms\.content\.text\s+:\s+//')" > + TRUNCATED="$(printf %b "$TEXT" | cut -c1-70 | tr '\n' ' ' | sed '$s/ $/\n/')" > NUM="$( > echo "$TEXTDATA" | > grep sms.content.number | > @@ -97,12 +90,21 @@ checkfornewtexts() { > printf %b "Received from $NUM at $TIME:\n$TEXT\n\n" >> "$LOGDIR/$NUM/sms.txt" > printf %b "$TIME\trecv_txt\t$NUM\t${#TEXT} chars\n" >> "$LOGDIR/modemlog.tsv" > mmcli -m "$(modem_n)" --messaging-delete-sms="$TEXTID" > + > + CONTACT="$(sxmo_contacts.sh | grep "$NUM" || echo "$NUM")" > + > + # Send a notice of each message to a notification file / watcher > + > + if [ "${#TEXT}" = "${#TRUNCATED}" ]; then > + ( sxmo_notificationwrite.sh "Message from $CONTACT: $TEXT" "st -e tail -n9999 -f $LOGDIR/$NUM/sms.txt" "$LOGDIR/$NUM/sms.txt" & ) & > + else > + ( sxmo_notificationwrite.sh "Message from $CONTACT: $TRUNCATED..." "st -e tail -n9999 -f $LOGDIR/$NUM/sms.txt" "$LOGDIR/$NUM/sms.txt" & ) & > + fi Having a cut statement when running the dunst command maybe cleaner / more consistent.
diff --git a/scripts/core/sxmo_xinit.sh b/scripts/core/sxmo_xinit.sh index ea478af..3d28627 100755 --- a/scripts/core/sxmo_xinit.sh +++ b/scripts/core/sxmo_xinit.sh @@ -39,6 +39,7 @@ daemons() { autocutsel & autocutsel -selection PRIMARY & sxmo_statusbar.sh & + sxmo_notificationservice.sh & } daemonsneedingdbus() { diff --git a/scripts/modem/sxmo_modemmonitor.sh b/scripts/modem/sxmo_modemmonitor.sh index 6283df3..0e94063 100755 --- a/scripts/modem/sxmo_modemmonitor.sh +++ b/scripts/modem/sxmo_modemmonitor.sh @@ -1,6 +1,7 @@ #!/usr/bin/env sh TIMEOUT=3 LOGDIR="$XDG_CONFIG_HOME"/sxmo/modem +NOTIFDIR="$XDG_CONFIG_HOME"/sxmo/notifications trap "gracefulexit" INT TERM err() { @@ -10,7 +11,6 @@ err() { gracefulexit() { echo "gracefully exiting $0!" - sxmo_setpineled green 0 kill -9 0 } @@ -28,14 +28,14 @@ checkforincomingcalls() { )" if echo "$VOICECALLID" | grep -v .; then - rm -f /tmp/sxmo_incomingcall + rm -f "$NOTIFDIR/sxmo_incomingcall" return fi if [ -x "$XDG_CONFIG_HOME/sxmo/hooks/ring" ]; then "$XDG_CONFIG_HOME/sxmo/hooks/ring" else - sxmo_vibratepine 2000 & sxmo_setpineled green 1 + sxmo_vibratepine 2000 & fi # Delete all previous calls which have been terminated calls @@ -61,7 +61,7 @@ checkforincomingcalls() { TIME="$(date --iso-8601=seconds)" mkdir -p "$LOGDIR" printf %b "$TIME\tcall_ring\t$INCOMINGNUMBER\n" >> "$LOGDIR/modemlog.tsv" - echo "$VOICECALLID:$INCOMINGNUMBER" > /tmp/sxmo_incomingcall + printf %b "$VOICECALLID:$INCOMINGNUMBER\n" > "$NOTIFDIR/sxmo_incomingcall" echo "Number: $INCOMINGNUMBER (VOICECALLID: $VOICECALLID)" } @@ -74,18 +74,11 @@ checkfornewtexts() { echo "$TEXTIDS" | grep -v . && return # Loop each textid received and read out the data into appropriate logfile - { - sxmo_setpineled green 1 - sxmo_vibratepine 200; - sleep 0.1; - sxmo_vibratepine 200; - sleep 0.1; - sxmo_vibratepine 200; - } & - - for TEXTID in $(printf %b "$TEXTIDS") ; do + for TEXTID in $TEXTIDS; do + TEXTDATA="$(mmcli -m "$(modem_n)" -s "$TEXTID" -K)" TEXT="$(echo "$TEXTDATA" | grep sms.content.text | sed -E 's/^sms\.content\.text\s+:\s+//')" + TRUNCATED="$(printf %b "$TEXT" | cut -c1-70 | tr '\n' ' ' | sed '$s/ $/\n/')" NUM="$( echo "$TEXTDATA" | grep sms.content.number | @@ -97,12 +90,21 @@ checkfornewtexts() { printf %b "Received from $NUM at $TIME:\n$TEXT\n\n" >> "$LOGDIR/$NUM/sms.txt" printf %b "$TIME\trecv_txt\t$NUM\t${#TEXT} chars\n" >> "$LOGDIR/modemlog.tsv" mmcli -m "$(modem_n)" --messaging-delete-sms="$TEXTID" + + CONTACT="$(sxmo_contacts.sh | grep "$NUM" || echo "$NUM")" + + # Send a notice of each message to a notification file / watcher + + if [ "${#TEXT}" = "${#TRUNCATED}" ]; then + ( sxmo_notificationwrite.sh "Message from $CONTACT: $TEXT" "st -e tail -n9999 -f $LOGDIR/$NUM/sms.txt" "$LOGDIR/$NUM/sms.txt" & ) & + else + ( sxmo_notificationwrite.sh "Message from $CONTACT: $TRUNCATED..." "st -e tail -n9999 -f $LOGDIR/$NUM/sms.txt" "$LOGDIR/$NUM/sms.txt" & ) & + fi done } mainloop() { while true; do - sxmo_setpineled green 0 checkforincomingcalls checkfornewtexts sleep $TIMEOUT & wait -- 2.27.0
Thanks for sending - comments inline. This is very close, we just need to resolve a few style things to make this simpler to understand & easier to maintain. Overall notes: - There's no need to embed dates into the notification files' contents. That metadata can be used from the file's timestamp - If dates are no longer embedded; there are then just two fields for each notification; notification description & watch file. Seems like it'd be nice to change the notification file format to a 2 line file (e.g. 1st line being the file to watch, and the second line being the description). This would save alot of field cutting and awk grepping for NF. Head/tail/wc -l are less verbose & simpler to understand. - Vibration/LED setting/Dunst logic is spread out between both the watcher service script and the write script. This should be in one place - e.g. just in the watcher service; so the notification write script should be relatively 'dumb'. E.g. really all the write script needs to do is actually write the file (and error-check upfront). Also if we do this then the script name is actually self-documenting. The heavy lifting can all be in the monitor script. > --- > configs/appcfg/dunst.conf | 2 ++ > scripts/core/sxmo_appmenu.sh | 13 ++++++-- > scripts/core/sxmo_notifications.sh | 13 ++++++++ > scripts/core/sxmo_notificationservice.sh | 40 ++++++++++++++++++++++++ > scripts/core/sxmo_notificationwrite.sh | 30 ++++++++++++++++++ > scripts/core/sxmo_xinit.sh | 1 + > scripts/modem/sxmo_modemmonitor.sh | 32 ++++++++++--------- > 7 files changed, 114 insertions(+), 17 deletions(-) > create mode 100755 scripts/core/sxmo_notifications.sh > create mode 100755 scripts/core/sxmo_notificationservice.sh > create mode 100755 scripts/core/sxmo_notificationwrite.sh > > diff --git a/configs/appcfg/dunst.conf b/configs/appcfg/dunst.conf > index a7f9323..b2bddee 100644 > --- a/configs/appcfg/dunst.conf > +++ b/configs/appcfg/dunst.conf > @@ -32,6 +32,8 @@ > title = Dunst > class = Dunst > startup_notification = false > + mouse_left_click = do_action > + > [shortcuts] > close_all = ctrl+shift+space > > diff --git a/scripts/core/sxmo_appmenu.sh b/scripts/core/sxmo_appmenu.sh > index c53b140..b0aba1a 100755 > --- a/scripts/core/sxmo_appmenu.sh > +++ b/scripts/core/sxmo_appmenu.sh > @@ -1,6 +1,7 @@ > #!/usr/bin/env sh > trap gracefulexit INT TERM > WIN=$(xdotool getwindowfocus) > +NOTIFDIR="$XDG_CONFIG_HOME"/sxmo/notifications > > gracefulexit() { > echo "Gracefully exiting $0" > @@ -334,8 +335,16 @@ getprogchoices() { > # E.g. sets CHOICES var > programchoicesinit "$@" > > + # Decorate menu at top w/ notifications if they exist > + NOTIFICATIONS="$(find "$NOTIFDIR"/* -type f | grep -vc "sxmo_incomingcall" || echo 0)" > + echo "$NOTIFICATIONS" | grep -v 0 && > + CHOICES=" > + Notifications ($(echo "$NOTIFICATIONS" | cut -d " " -f1)) ^ 0 ^ sxmo_notifications.sh > + $CHOICES > + " > + > # Decorate menu at top w/ incoming call entry if present > - INCOMINGCALL="$(cat /tmp/sxmo_incomingcall || echo NOCALL)" > + INCOMINGCALL="$(cat "$NOTIFDIR"/sxmo_incomingcall || echo NOCALL)" > if echo "$INCOMINGCALL" | grep -v NOCALL; then > CALLID="$(echo "$INCOMINGCALL" | cut -d: -f1)" > CALLNUM="$(echo "$INCOMINGCALL" | cut -d: -f2)" > @@ -398,4 +407,4 @@ pgrep -f "$(command -v sxmo_appmenu.sh)" | grep -Ev "^${$}$" | xargs kill -TERM > DMENUIDX=0 > PICKED="" > ARGS="$*" > -mainloop > \ No newline at end of file > +mainloop > diff --git a/scripts/core/sxmo_notifications.sh b/scripts/core/sxmo_notifications.sh > new file mode 100755 > index 0000000..3d9cf46 > --- /dev/null > +++ b/scripts/core/sxmo_notifications.sh > @@ -0,0 +1,13 @@ > +#!/usr/bin/env sh > + > +NOTIFDIR="$XDG_CONFIG_HOME"/sxmo/notifications > + > +while true; do > + CHOICES="$(find "$NOTIFDIR"/ -type f -not -name 'sxmo_incomingcall' -exec cat {} +)" > + PICKED="$(printf %b "$CHOICES\nClose Menu" | cut -f1 | dmenu -c -i -fn "Terminus-18" -p "Notifs" -l 10)" > + > + echo "$PICKED" | grep "Close Menu" && exit 0 > + > + $(printf %b "$CHOICES" | grep "$PICKED" | cut -f2) > + exit 0 Exit 0 is implied at EOF - you can remove this.