#!/usr/bin/env bash tmp=$XDG_CACHE_HOME/dunst-history.json lock="$XDG_CACHE_HOME/dunst-toggle.lock" lockinfo="$XDG_CACHE_HOME/dunst-lock-info" touch $lockinfo declare ids export toggle_icon="" get_ids() { mapfile -t ids < <(dunstctl history | jq -r ".data[] | .[] | select(.appname.data != \"Spotify\") | .id.data") } get_notif() { echo -n '(box :class "container" :orientation "v" :space-evenly false ' for id in "${ids[@]}"; do mapfile -t n < <(jq -r ".data[] | .[] | select(.id.data == $id) | .appname.data, .summary.data, .body.data" "$tmp" | sed -r '/^\s*$/d' | sed -e 's/\%/ percent/g') echo -n '(eventbox :onclick "dunstctl history-pop '"$id"' && dunstctl action 0 && dunstctl close" ' echo -n '(box :class "notification" :orientation "v" :width 300 :space-evenly false ' echo -n '(box :space-evenly false :spacing 10 ' echo -n '(label :halign "start" :xalign 0 :wrap true :class "summary" :text "'"${n[1]}"'")' echo -n '(label :halign "end" :xalign 1 :wrap true :class "appname" :text "'"${n[0]}"'"))' echo -n '(label :halign "start" :wrap true :class "body" :text "'"${n[2]}"'")))' done echo ')' } toggle() { dunstctl set-paused toggle if [ ! -f "$lock" ]; then export toggle_icon="" touch "$lock" else export toggle_icon="" rm "$lock" fi echo "icon_change" > $lockinfo } clear() { systemctl --user restart dunst echo "icon_change" > $lockinfo } get_icon() { if [ ${#ids[@]} -eq 0 ]; then echo "󰆂" else echo "󰆄" fi } if [ "$1" == "toggle" ]; then toggle dunstctl history > "$tmp" elif [ "$1" == "clear" ]; then clear dunstctl history > "$tmp" elif [ "$1" == "icons" ]; then dunstctl history > "$tmp" get_ids echo '{"toggle_icon": "'"$toggle_icon"'", "icon": "'"$(get_icon)"'"}' tail -f "$lockinfo" | while read -r; do get_ids echo '{"toggle_icon": "'"$toggle_icon"'", "icon": "'"$(get_icon)"'"}' done else dunstctl history > "$tmp" get_ids get_notif tail -f "$tmp" 2>/dev/null | rg --line-buffered "aa\{sv\}" | while read -r; do get_ids get_notif done fi