From 8234fdfdf0244bff8b8ae2abd4aae0531fcf972d Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Fri, 24 Sep 2021 11:16:38 +0200 Subject: [PATCH] polybar: Fix archupdate display Fixed archupdates to work even if `checkupdates` script returns an error by falling back to `yay` to do its package update detection. --- .../.config/polybar/scripts/poly-archupdates | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/polybar/.config/polybar/scripts/poly-archupdates b/polybar/.config/polybar/scripts/poly-archupdates index c54bd69..6b27e35 100755 --- a/polybar/.config/polybar/scripts/poly-archupdates +++ b/polybar/.config/polybar/scripts/poly-archupdates @@ -6,25 +6,32 @@ # that polybar simply displays nothing. # # dependendies: yay, (pacman-contrib optional) +# +# Takes an optional integer argument, which is the minimum +# numer of package updates for an answer to be returned. +min_upd=${1:-0} # prefer checkupdates since it allows checking w/o partial upgrade if command -v "checkupdates" >/dev/null; then - updates_repo="$(checkupdates | wc -l)" -# fall back to yay, but be aware it will not find everything -else - updates_repo="$(yay -Qun 2>/dev/null | wc -l)" + updates_repo="$(checkupdates 2>&1)" fi +# fall back to yay, but be aware it will not find everything +# if checkupdates finds nothing or returns an error +if [ "$updates_repo" = "" ] || [ -z "${updates_repo##*==> ERROR: Cannot fetch updates*}" ]; then + updates_repo="$(yay -Qun 2>/dev/null)" +fi +updates_repo=$(echo "$updates_repo" | wc -l) + updates_aur="$(yay -Qum 2>/dev/null | wc -l)" -# if ! updates_aur=$(cower -u 2> /dev/null | wc -l); then -# if ! updates_aur=$(trizen -Su --aur --quiet | wc -l); then -# if ! updates_aur=$(pikaur -Qua 2> /dev/null | wc -l); then -# if ! updates_aur=$(rua upgrade --printonly 2> /dev/null | wc -l); then +# updates_aur=$(cower -u 2> /dev/null | wc -l) +# updates_aur=$(trizen -Su --aur --quiet | wc -l) +# updates_aur=$(pikaur -Qua 2> /dev/null | wc -l) +# updates_aur=$(rua upgrade --printonly 2> /dev/null | wc -l) -updates="$((updates_repo + updates_aur))" - -if [ "$updates" -gt 0 ]; then - echo "$updates" +updates=$((updates_repo + updates_aur)) +if [ "$updates" -gt "$min_upd" ]; then + echo "$updates" else - echo "" + echo "" fi