aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/dot_config/waybar/executable_mako-status.sh
diff options
context:
space:
mode:
Diffstat (limited to 'dot_config/waybar/executable_mako-status.sh')
-rw-r--r--dot_config/waybar/executable_mako-status.sh55
1 files changed, 40 insertions, 15 deletions
diff --git a/dot_config/waybar/executable_mako-status.sh b/dot_config/waybar/executable_mako-status.sh
index 791aabe..a4fdd31 100644
--- a/dot_config/waybar/executable_mako-status.sh
+++ b/dot_config/waybar/executable_mako-status.sh
@@ -1,26 +1,51 @@
#!/bin/sh
-# Emit waybar JSON with the mako notification count. Falls back to 0 when
-# mako is not running so waybar doesn't blink errors.
+# Waybar status: count of *pending* notifications, where pending = ids in
+# mako's history that have NOT been explicitly dismissed by the user via
+# Mod+n / Mod+Shift+n / the history picker.
+#
+# State file: $XDG_RUNTIME_DIR/mako-dismissed (per-session, plain id list).
+
set -eu
if ! command -v makoctl >/dev/null 2>&1; then
- printf '{"text":"","tooltip":"mako not installed","class":"off"}\n'
+ printf '{"text":"","tooltip":"mako not installed","class":"off"}
+'
exit 0
fi
-count=$(makoctl history 2>/dev/null | grep -c '^Notification ' || true)
-pending=$(makoctl list 2>/dev/null | grep -c '^Notification ' || true)
+state=${XDG_RUNTIME_DIR:-/tmp}/mako-dismissed
+: >>"$state"
-if [ "$pending" -gt 0 ]; then
- text="󰂞 $pending"
- class="pending"
-elif [ "$count" -gt 0 ]; then
- text="󱇨 $count"
- class="history"
+# Visible notifications also count as pending (they aren't in history yet).
+visible_ids=$(makoctl list -f '%i' 2>/dev/null || true)
+history_ids=$(makoctl history -f '%i' 2>/dev/null || true)
+all_ids=$(printf '%s
+%s
+' "$visible_ids" "$history_ids" \
+ | grep -E '^[0-9]+$' | sort -u || true)
+
+# Prune stale ids (no longer present in mako) from the dismissed file.
+if [ -s "$state" ] && [ -n "$all_ids" ]; then
+ tmp=$(mktemp)
+ printf '%s
+' "$all_ids" >"$tmp.all"
+ grep -Fxf "$tmp.all" "$state" >"$tmp" 2>/dev/null || :
+ mv "$tmp" "$state"
+ rm -f "$tmp.all"
+fi
+
+if [ -z "$all_ids" ]; then
+ pending=0
else
- text="󰂜"
- class="empty"
+ pending=$(printf '%s
+' "$all_ids" | grep -Fxvf "$state" | grep -c . || true)
fi
-printf '{"text":"%s","tooltip":"%s pending / %s history","class":"%s"}\n' \
- "$text" "$pending" "$count" "$class"
+if [ "$pending" -gt 0 ]; then
+ printf '{"text":"󰂞 %s","tooltip":"%s pending","class":"pending"}
+' \
+ "$pending" "$pending"
+else
+ printf '{"text":"󰂜","tooltip":"no pending notifications","class":"empty"}
+'
+fi