waybar - updated alhp-utils module

This commit is contained in:
2025-05-05 13:02:52 +02:00
parent a2a6395e95
commit 3771ca9115
5 changed files with 152 additions and 159 deletions

View File

@@ -1,28 +1,41 @@
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
# Retrieve JSON output from alhp.utils.
readonly ALHP_OUTPUT=$(alhp.utils -j)
ALHP_OUTPUT=$(alhp.utils -j)
total=$(jq -r '.total' <<<"$ALHP_OUTPUT")
mirror_stale=$(jq -r '.mirror_out_of_date' <<<"$ALHP_OUTPUT")
# Extract "total" as a string and read "packages" into a Bash array.
readonly total=$(echo "$ALHP_OUTPUT" | jq -r '.total | tostring')
readarray -t packages < <(echo "$ALHP_OUTPUT" | jq -r '.packages[]?')
# Initialize default tooltip and class.
tooltip=''
# defaults
text=""
tooltip='All good'
class='good'
# Use arithmetic evaluation to check if total is greater than 0.
if (( total > 0 )); then
class='bad'
# safe array even if packages is null
readarray -t packages < <(
jq -r '.packages // [] | .[]' <<<"$ALHP_OUTPUT"
)
# 1) Mirror stale? highest priority
if [[ "$mirror_stale" == "true" ]]; then
class="stale"
tooltip="Mirror is out of date"
# 2) Any pending PKGBUILDs?
elif (( total > 0 )); then
class="bad"
text="$tooltip"
tooltip=$(printf "%s\n" "${packages[@]}")
fi
# If there are any packages, join them with newline as separator.
if (( ${#packages[@]} > 0 )); then
tooltip=$(IFS=$'\n'; echo "${packages[*]}")
else
tooltip="All good"
fi
case "$class" in
good) icon="";;
stale) icon="󰏖";;
bad) icon="󰏗";;
esac
# Generate compact JSON output (all in one line) with jq.
jq -nc --arg text "$total" --arg class "$class" --arg tooltip "$tooltip" \
'{text: $text, class: $class, tooltip: $tooltip}'
# Emit compact JSON for Statusbar
jq -nc \
--arg text "$icon $text" \
--arg class "$class" \
--arg tooltip "$tooltip" \
'{text: $text, class: $class, tooltip: $tooltip}'