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.
This commit is contained in:
Daniele Fucini
2026-11-07 10:41:36 +01:00
parent 0ec1272df6
commit b5c268ae7d
+17 -7
View File
@@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
# Pending updates for xmobar from update-notify's pending list, e.g. " 15/3 | " (repo/AUR), empty when none # 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 # 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) # 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" file="${XDG_STATE_HOME:-$HOME/.local/state}/update-notify/pending"
@@ -11,7 +11,7 @@ mapfile -t entries < "$file"
names=() names=()
for e in "${entries[@]}"; do for e in "${entries[@]}"; do
read -r src pkg _ <<< "$e" read -r src pkg _ <<< "$e"
[[ $src != threshold ]] && names+=("$pkg") case $src in repo|aur|kernel) names+=("$pkg") ;; esac
done done
declare -A installed declare -A installed
@@ -21,10 +21,15 @@ if (( ${#names[@]} )); then
done < <(pacman -Q "${names[@]}" 2>/dev/null) done < <(pacman -Q "${names[@]}" 2>/dev/null)
fi fi
threshold=0 repo=() aur=() kernel=() threshold=0 repo=() aur=() kernel=() pacnew=() reboot=""
running=$(uname -r)
for e in "${entries[@]}"; do for e in "${entries[@]}"; do
read -r src pkg new <<< "$e" 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]:-} have=${installed[$pkg]:-}
[[ -z $have ]] && continue # removed since the last run [[ -z $have ]] && continue # removed since the last run
case $src in case $src in
@@ -39,14 +44,19 @@ if [[ ${1:-} == list ]]; then
(( ${#repo[@]} )) && { printf -v l '%s\n' "${repo[@]}"; body+="Repo:"$'\n'"$l"; } (( ${#repo[@]} )) && { printf -v l '%s\n' "${repo[@]}"; body+="Repo:"$'\n'"$l"; }
(( ${#aur[@]} )) && { printf -v l '%s\n' "${aur[@]}"; body+="AUR:"$'\n'"$l"; } (( ${#aur[@]} )) && { printf -v l '%s\n' "${aur[@]}"; body+="AUR:"$'\n'"$l"; }
(( ${#kernel[@]} )) && { printf -v l 'Rebuild %s\n' "${kernel[@]}"; body+="$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'} body=${body%$'\n'}
notify-send "Pending updates" "${body:-None}" notify-send "Pending updates" "${body:-None}"
exit exit
fi fi
total=$(( ${#repo[@]} + ${#aur[@]} )) total=$(( ${#repo[@]} + ${#aur[@]} ))
(( total + ${#kernel[@]} )) || exit 0 (( total + ${#kernel[@]} + ${#pacnew[@]} )) || [[ -n $reboot ]] || exit 0
text=$'\xef\x92\x87'" ${#repo[@]}/${#aur[@]}" # nf-oct-package, as UTF-8 bytes so the locale doesn't matter text=$'\xef\x92\x87' # nf-oct-package, as UTF-8 bytes so the locale doesn't matter
(( total >= threshold )) && text="<fc=#ffb86c>$text</fc>" (( total )) && text+=" ${#repo[@]}/${#aur[@]}" # markers alone: no "0/0"
(( total && total >= threshold )) && text="<fc=#ffb86c>$text</fc>"
(( ${#kernel[@]} )) && text+=" <fc=#f7768e>K</fc>" (( ${#kernel[@]} )) && text+=" <fc=#f7768e>K</fc>"
[[ -n $reboot ]] && text+=" <fc=#f7768e>R</fc>"
(( ${#pacnew[@]} )) && text+=" <fc=#7aa2f7>P</fc>"
echo "$text | " echo "$text | "