From 10bb1305eac8cd2a3b5d6bcd53982adb685f0c73 Mon Sep 17 00:00:00 2001 From: Léana 江 Date: Sat, 25 Apr 2026 23:16:28 +0200 Subject: add notify-once script and documentation --- doc/plugins.org | 16 ++++++++++++++-- etc/notify-once.sh | 31 +++++++++++++++++++++++++++++++ nix/readme.org | 2 +- xmobar.cabal | 1 + 4 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 etc/notify-once.sh diff --git a/doc/plugins.org b/doc/plugins.org index 4facc85..442af34 100644 --- a/doc/plugins.org +++ b/doc/plugins.org @@ -306,7 +306,7 @@ "--", "-O", "On - ", "-i", "", "-L", "-15", "-H", "-5", "-l", "red", "-m", "blue", "-h", "green", - "-a", "notify-send -u critical 'Battery running out!!'", + "-a", "notify-once \"xmobar\" -u critical 'Battery running out!!'", "-A", "3"] 600 #+end_src @@ -316,7 +316,19 @@ separator affect how == is displayed. For this monitor, neither the generic nor the specific options have any effect on ==. We are also telling the monitor to execute the unix command - =notify-send= when the percentage left in the battery reaches 6%. + =notify-once= when the percentage left in the battery reaches 6%. + + =notify-once= is a bash wrapper script provided with the =xmobar= package. + =xmobar= will run the notification command according to the refresh period, + this has the effect of spamming the notification tray if calling =notify-send= directly. + =notify-once= script deduplicates the notification by indicating to =notify-send= + the last notification we want to replace. + See [[https://codeberg.org/xmobar/xmobar/issues/746][#746]] for more information. + Note that your notification daemon should handle notification replacement + for this to work. Whether the replacement resets the timeout is also handled by the + notification daemon. + For example, the =wired-notify= implementation has =replacing_enabled= + and =replacing_resets_timeout= configuration options [[https://github.com/Toqozz/wired-notify/wiki/Config]]. It is also possible to specify template variables in the =-O= and =-o= switches, as in the following example: diff --git a/etc/notify-once.sh b/etc/notify-once.sh new file mode 100644 index 0000000..1c46401 --- /dev/null +++ b/etc/notify-once.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +set -euo pipefail + +help() { + echo "notify-send: send deduplicated notifications" + echo "Usage: notify-once [ARGS]" + echo " ARGS are arguments passed directly to notify-send" +} + +if [ $# -lt 1 ]; then + echo "Should get at least one argument, a name" >&2 + help + exit 1 +fi +APPNAME="$1" +shift + +ID_PATH="/tmp/notify-state-$APPNAME" + +if [ -e "$ID_PATH" ]; then + # Exists, replace + ID=$(cat "$ID_PATH") + ID=$(notify-send -r "$ID" -p "$@") +else + # Doesn't exist, create + ID=$(notify-send -p "$@") +fi + +# Store new ID +echo "$ID" >"$ID_PATH" diff --git a/nix/readme.org b/nix/readme.org index ac00ce7..6a492e5 100644 --- a/nix/readme.org +++ b/nix/readme.org @@ -67,7 +67,7 @@ Here is how to set it up: Run MultiCoreTemp ["-t", "\xf2c9°", "-L", "60", "-H", "95", "-l", "white", "-n", "white", "-h", "red"] 50, Run CatInt 0 "/sys/class/hwmon/hwmon4/fan1_input" [] 50, Run MultiCpu ["-t", "\xf4bc ", "-w", "99", "-L", "3", "-H", "50", "--normal", "green", "--high", "red"] 10, - Run BatteryP ["BAT0"] ["-t", "󱊣%", "-L", "10", "-H", "80", "-p", "3", "--", "-O", "On - ", "-i", "", "-L", "-15", "-H", "-5", "-l", "red", "-m", "blue", "-h", "green", "-a", "notify-send -u critical 'Battery running out!!'", "-A", "3"] 600, + Run BatteryP ["BAT0"] ["-t", "󱊣%", "-L", "10", "-H", "80", "-p", "3", "--", "-O", "On - ", "-i", "", "-L", "-15", "-H", "-5", "-l", "red", "-m", "blue", "-h", "green", "-a", "notify-once \"xmobar\" -u critical 'Battery running out!!'", "-A", "3"] 600, Run Alsa "default" "Master" ["-t", "\xf028 %"], Run Date "%a %_d %b %H:%M:%S" "date" 10, Run Load ["-t", "L", "-L", "1", "-H", "3", "-d", "2"] 300, diff --git a/xmobar.cabal b/xmobar.cabal index ff8bc59..5d4dd07 100644 --- a/xmobar.cabal +++ b/xmobar.cabal @@ -26,6 +26,7 @@ extra-source-files: readme.org, changelog.md, etc/xmobar.hs, etc/xmonadpropwrite.hs, etc/xmobar.el + etc/notify-once.sh source-repository head type: git -- cgit v1.2.3