diff --git a/.config/xmobar/updates.sh b/.config/xmobar/updates.sh new file mode 100755 index 0000000..f87545e --- /dev/null +++ b/.config/xmobar/updates.sh @@ -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="$text" +(( ${#kernel[@]} )) && text+=" K" +echo "$text | " diff --git a/.config/xmobar/xmobarrc_hdmi b/.config/xmobar/xmobarrc_hdmi index 9d87a9e..58af4fd 100644 --- a/.config/xmobar/xmobarrc_hdmi +++ b/.config/xmobar/xmobarrc_hdmi @@ -51,9 +51,10 @@ Config { overrideRedirect = True ] 600 , Run Com "/home/fuxino/.config/xmobar/pactl_volume.sh" [] "pactl_volume" 10 , Run Com "/home/fuxino/.config/xmobar/ens_brief.sh" [] "ens_brief" 18000 + , Run Com "/home/fuxino/.config/xmobar/updates.sh" [] "updates" 600 , Run UnsafeXMonadLog ] , sepChar = "%" , alignSep = "}{" - , template = "  | %UnsafeXMonadLog% } %uptime% | %multicpu% %coretemp% | %memory% |  %kbd% { %LZIB% · %ens_brief% | %pactl_volume% | %date% " + , template = "  | %UnsafeXMonadLog% } %uptime% | %multicpu% %coretemp% | %memory% |  %kbd% { %updates%%LZIB% · %ens_brief% | %pactl_volume% | %date% " } diff --git a/.config/xmobar/xmobarrc_laptop b/.config/xmobar/xmobarrc_laptop index a79a654..81f9c5b 100644 --- a/.config/xmobar/xmobarrc_laptop +++ b/.config/xmobar/xmobarrc_laptop @@ -52,9 +52,10 @@ Config { overrideRedirect = True , Run XPropertyLog "_XMONAD_TRAYPAD" , Run Com "/home/fuxino/.config/xmobar/pactl_volume.sh" [] "pactl_volume" 10 , Run Com "/home/fuxino/.config/xmobar/ens_brief.sh" [] "ens_brief" 18000 + , Run Com "/home/fuxino/.config/xmobar/updates.sh" [] "updates" 600 , Run UnsafeXMonadLog ] , sepChar = "%" , alignSep = "}{" - , template = "  | %UnsafeXMonadLog% } %uptime% | %multicpu% %coretemp% | %memory% |  %kbd% { %LZIB% · %ens_brief% | %pactl_volume% | %date% %_XMONAD_TRAYPAD% " + , template = "  | %UnsafeXMonadLog% } %uptime% | %multicpu% %coretemp% | %memory% |  %kbd% { %updates%%LZIB% · %ens_brief% | %pactl_volume% | %date% %_XMONAD_TRAYPAD% " }