From ffb15c0954801c98a175dce0ab29588f0f75230f Mon Sep 17 00:00:00 2001 From: Daniele Fucini Date: Sat, 17 Oct 2026 11:06:46 +0200 Subject: [PATCH] Keep the configured threshold in the pending file A threshold argument is a one-off override for the notification, so status bars keep using THRESHOLD from the config. --- README.md | 4 ++-- update-notify | 11 ++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b987847..accfdb0 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ systemctl --user enable --now update-notify.path update-notify [threshold] ``` -`threshold` is the minimum number of updates (repo + AUR) before update counts are shown. It overrides the `THRESHOLD` setting below. +`threshold` is the minimum number of updates (repo + AUR) before update counts are shown. It overrides the `THRESHOLD` setting below for that run's notification only; the pending file keeps the configured value. ## Configuration @@ -97,7 +97,7 @@ The content of the last notification is stored in `$XDG_STATE_HOME/update-notify Each run also writes the pending updates to `$XDG_STATE_HOME/update-notify/pending`, whether or not the threshold is reached, for status bars such as xmobar to read: ``` -threshold 30 +threshold repo aur kernel diff --git a/update-notify b/update-notify index 31b2f39..e747326 100755 --- a/update-notify +++ b/update-notify @@ -19,10 +19,15 @@ if [[ -r $config_file ]]; then # shellcheck source=/dev/null source "$config_file" fi +config_threshold=$THRESHOLD # written to the pending file, so a one-off argument doesn't change status bars THRESHOLD=${1:-$THRESHOLD} -[[ $THRESHOLD =~ ^[0-9]+$ ]] || { echo "Threshold must be a number" >&2; exit 1; } -THRESHOLD=$((10#$THRESHOLD)) # force base 10, so e.g. "08" isn't read as octal +for t in "$config_threshold" "$THRESHOLD"; do + [[ $t =~ ^[0-9]+$ ]] || { echo "Threshold must be a number" >&2; exit 1; } +done +# force base 10, so e.g. "08" isn't read as octal +config_threshold=$((10#$config_threshold)) +THRESHOLD=$((10#$THRESHOLD)) mkdir -p "$state_dir" # notify-send from cron/systemd needs the session bus address @@ -130,7 +135,7 @@ done # Pending list for status bars, one " " per line # --------------------------------------------------------------------------- { - printf 'threshold %s\n' "$THRESHOLD" + printf 'threshold %s\n' "$config_threshold" for item in "${arch_list[@]}"; do read -r pkg _ _ new <<< "$item" printf 'repo %s %s\n' "$pkg" "$new"