New check updates script with color indicators for threshholds

This commit is contained in:
Stephan Raabe 2023-09-10 15:03:57 +02:00
parent 1806326c4a
commit 9952035ff4

View File

@ -9,6 +9,18 @@
# by Stephan Raabe (2023)
# -----------------------------------------------------
# -----------------------------------------------------
# Define threshholds for color indicators
# -----------------------------------------------------
threshhold_green=0
threshhold_yellow=25
threshhold_red=100
# -----------------------------------------------------
# Calculate available updates pacman and aur (with trizen)
# -----------------------------------------------------
if ! updates_arch=$(checkupdates 2> /dev/null | wc -l ); then
updates_arch=0
fi
@ -19,8 +31,23 @@ fi
updates=$(("$updates_arch" + "$updates_aur"))
if [ "$updates" -gt 0 ]; then
echo " $updates"
else
echo " 0"
# -----------------------------------------------------
# Output in JSON format for Waybar Module custom-updates
# -----------------------------------------------------
css_class="green"
# test classes
# printf '{"text": "0", "alt": "0", "tooltip": "0 Updates", "class": "red"}'
# exit
if [ "$updates" -gt $threshhold_yellow ]; then
css_class="yellow"
elif [ "$updates" -gt $threshhold_red ]; then
css_class="red"
fi
if [ "$updates" -gt $threshhold_green ]; then
printf '{"text": "%s", "alt": "%s", "tooltip": "%s Updates", "class": "%s"}' "$updates" "$updates" "$updates" "$css_class"
else
printf '{"text": "0", "alt": "0", "tooltip": "0 Updates", "class": "green"}'
fi