From 4fbb1feed8ae11774fd79db4eabebeae05895e0d Mon Sep 17 00:00:00 2001 From: Price Hiller Date: Mon, 24 Jul 2023 02:33:55 -0500 Subject: [PATCH] fix(waybar): properly count number of available package updates --- .../waybar/scripts/get-pacman-package-updates.bash | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/dots/.config/waybar/scripts/get-pacman-package-updates.bash b/dots/.config/waybar/scripts/get-pacman-package-updates.bash index 1268ae31..dd23640c 100755 --- a/dots/.config/waybar/scripts/get-pacman-package-updates.bash +++ b/dots/.config/waybar/scripts/get-pacman-package-updates.bash @@ -1,17 +1,20 @@ #!/usr/bin/env bash main() { + set -o pipefail local package_updates package_updates="$(checkupdates | cut -d " " -f1)" - package_update_number="$(printf "%s" "${package_updates}" | wc -l)" + + if [[ "${?}" != 0 ]]; then + return 0 + fi + + package_update_number="$(wc -l <<<"${package_updates}")" # Limit the number of results shown to ten, add trailing ellipsis + package_updates="$(printf "%s" "${package_updates}" | head -n 10)" if ((package_update_number > 10)); then - package_updates="$(printf "%s" "${package_updates}" | head -n 10)" package_updates+="\n..." - elif (( package_update_number == 0 )); then - # Don't return anything if there are no updates available - return 0 fi printf '{"text": "%s", "tooltip": "%s"}\n' "${package_update_number}" "${package_updates//$'\n'/\\n}"