From d4a8207fa8cd810ae292b5b6fa5e95d327db4539 Mon Sep 17 00:00:00 2001 From: Derek Taylor Date: Mon, 2 Jan 2023 18:34:35 -0600 Subject: [PATCH] A rewrite of notify-log. --- .local/bin/notify-log | 44 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/.local/bin/notify-log b/.local/bin/notify-log index 94fa64c..c0bfe21 100755 --- a/.local/bin/notify-log +++ b/.local/bin/notify-log @@ -2,10 +2,40 @@ logfile=$1 -dbus-monitor "interface='org.freedesktop.Notifications'" |\ -grep --line-buffered "string" |\ -grep --line-buffered -e method -e ":" -e '""' -e urgency -e notify -v |\ -grep --line-buffered '.*(?=string)|(?<=string).*' -oPi |\ -grep --line-buffered -v "sender-pid" |\ -grep --line-buffered -v '^\s*$' |\ -xargs -I '{}' echo {} >> "$logfile" +declare -a MSGBUF +STATE=off +MSGTIME= + +printbuf() { + JOINED=$( echo "${MSGBUF[@]}" | sed 's/,$//' ) + printf "%s\n%s\n" "--- ${MSGTIME} ---" "${JOINED}" +} + +procmsg() { + if [[ "${1}" =~ member=Notify$ ]]; then + STATE=on + MSGTIME=$(date '+%Y-%m-%d %H:%M:%S') + MSGBUF=() + elif [[ "${1}" =~ member=NotificationClosed$ ]]; then + STATE=off + printbuf + else + if [[ "${STATE}" == "on" ]]; then + if [[ "${1}" =~ ^string ]]; then + case "${1}" in + "string \"\"") ;; + "string \"urgency\"") ;; + "string \"sender-pid\"") ;; + *) + MSGBUF+=$( echo -n "${1}," ) + ;; + esac + fi + fi + fi +} + +dbus-monitor "interface='org.freedesktop.Notifications'" | \ + while read -r line; do + procmsg "$line" >> "$logfile" + done