From b5c268ae7daf3387265479a2bebbb3995e96d004 Mon Sep 17 00:00:00 2001 From: Daniele Fucini Date: Sat, 7 Nov 2026 10:41:36 +0100 Subject: [PATCH] xmobar: show reboot and .pacnew markers in the updates segment Red R until the reboot, blue P until the files are merged, read from update-notify's pending file; markers show alone when there are no updates. --- .config/xmobar/updates.sh | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/.config/xmobar/updates.sh b/.config/xmobar/updates.sh index f87545e..17ab6eb 100755 --- a/.config/xmobar/updates.sh +++ b/.config/xmobar/updates.sh @@ -1,7 +1,7 @@ #!/bin/bash # Pending updates for xmobar from update-notify's pending list, e.g. " 15/3 | " (repo/AUR), empty when none # Entries already installed are dropped, so the count falls right after an upgrade. Orange from the threshold -# on, red "K" when a custom kernel needs a rebuild. +# on, red "K" when a custom kernel needs a rebuild, red "R" when a reboot is needed, blue "P" for .pacnew files. # With "list": show the pending packages in a notification (for a click on the bar) file="${XDG_STATE_HOME:-$HOME/.local/state}/update-notify/pending" @@ -11,7 +11,7 @@ mapfile -t entries < "$file" names=() for e in "${entries[@]}"; do read -r src pkg _ <<< "$e" - [[ $src != threshold ]] && names+=("$pkg") + case $src in repo|aur|kernel) names+=("$pkg") ;; esac done declare -A installed @@ -21,10 +21,15 @@ if (( ${#names[@]} )); then done < <(pacman -Q "${names[@]}" 2>/dev/null) fi -threshold=0 repo=() aur=() kernel=() +threshold=0 repo=() aur=() kernel=() pacnew=() reboot="" +running=$(uname -r) for e in "${entries[@]}"; do read -r src pkg new <<< "$e" - [[ $src == threshold ]] && { threshold=$pkg; continue; } + case $src in + threshold) threshold=$pkg; continue ;; + pacnew) [[ -e ${e#pacnew } ]] && pacnew+=("${e#pacnew }"); continue ;; # gone once merged + reboot) [[ $pkg == "$running" ]] && reboot=$pkg; continue ;; # gone after the reboot + esac have=${installed[$pkg]:-} [[ -z $have ]] && continue # removed since the last run case $src in @@ -39,14 +44,19 @@ if [[ ${1:-} == list ]]; then (( ${#repo[@]} )) && { printf -v l '%s\n' "${repo[@]}"; body+="Repo:"$'\n'"$l"; } (( ${#aur[@]} )) && { printf -v l '%s\n' "${aur[@]}"; body+="AUR:"$'\n'"$l"; } (( ${#kernel[@]} )) && { printf -v l 'Rebuild %s\n' "${kernel[@]}"; body+="$l"; } + (( ${#pacnew[@]} )) && { printf -v l '%s\n' "${pacnew[@]}"; body+="Merge with pacdiff:"$'\n'"$l"; } + [[ -n $reboot ]] && body+="Reboot (running $reboot)"$'\n' body=${body%$'\n'} notify-send "Pending updates" "${body:-None}" exit fi total=$(( ${#repo[@]} + ${#aur[@]} )) -(( total + ${#kernel[@]} )) || exit 0 -text=$'\xef\x92\x87'" ${#repo[@]}/${#aur[@]}" # nf-oct-package, as UTF-8 bytes so the locale doesn't matter -(( total >= threshold )) && text="$text" +(( total + ${#kernel[@]} + ${#pacnew[@]} )) || [[ -n $reboot ]] || exit 0 +text=$'\xef\x92\x87' # nf-oct-package, as UTF-8 bytes so the locale doesn't matter +(( total )) && text+=" ${#repo[@]}/${#aur[@]}" # markers alone: no "0/0" +(( total && total >= threshold )) && text="$text" (( ${#kernel[@]} )) && text+=" K" +[[ -n $reboot ]] && text+=" R" +(( ${#pacnew[@]} )) && text+=" P" echo "$text | "