Add pending updates widget to xmobar
updates.sh shows the repo/AUR counts and pending kernel rebuilds from update-notify's pending file, and lists them in a notification on click.
This commit is contained in:
Executable
+52
@@ -0,0 +1,52 @@
|
||||
#!/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.
|
||||
# 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"
|
||||
[[ -r $file ]] || exit 0
|
||||
|
||||
mapfile -t entries < "$file"
|
||||
names=()
|
||||
for e in "${entries[@]}"; do
|
||||
read -r src pkg _ <<< "$e"
|
||||
[[ $src != threshold ]] && names+=("$pkg")
|
||||
done
|
||||
|
||||
declare -A installed
|
||||
if (( ${#names[@]} )); then
|
||||
while read -r pkg ver; do
|
||||
installed[$pkg]=$ver
|
||||
done < <(pacman -Q "${names[@]}" 2>/dev/null)
|
||||
fi
|
||||
|
||||
threshold=0 repo=() aur=() kernel=()
|
||||
for e in "${entries[@]}"; do
|
||||
read -r src pkg new <<< "$e"
|
||||
[[ $src == threshold ]] && { threshold=$pkg; continue; }
|
||||
have=${installed[$pkg]:-}
|
||||
[[ -z $have ]] && continue # removed since the last run
|
||||
case $src in
|
||||
repo) (( $(vercmp "$have" "$new") < 0 )) && repo+=("$pkg $new") ;;
|
||||
aur) (( $(vercmp "$have" "$new") < 0 )) && aur+=("$pkg $new") ;;
|
||||
kernel) (( $(vercmp "${have%-*}" "${new%-*}") < 0 )) && kernel+=("$pkg (stock $new)") ;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ ${1:-} == list ]]; then
|
||||
body=""
|
||||
(( ${#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"; }
|
||||
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="<fc=#ffb86c>$text</fc>"
|
||||
(( ${#kernel[@]} )) && text+=" <fc=#f7768e>K</fc>"
|
||||
echo "$text | "
|
||||
Reference in New Issue
Block a user