[feat](waybar): Add support for custom/alhp module
[feat](waybar): Add support for custom/alhp module
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
"modules-left": [
|
"modules-left": [
|
||||||
"clock",
|
"clock",
|
||||||
"custom/swaync",
|
"custom/swaync",
|
||||||
|
"custom/alhp",
|
||||||
"hyprland/window",
|
"hyprland/window",
|
||||||
"hyprland/workspaces"
|
"hyprland/workspaces"
|
||||||
],
|
],
|
||||||
@@ -278,5 +279,14 @@
|
|||||||
"on-scroll-down": "hyprctl hyprsunset gamma -10", // dimmer
|
"on-scroll-down": "hyprctl hyprsunset gamma -10", // dimmer
|
||||||
|
|
||||||
"interval": 0
|
"interval": 0
|
||||||
|
},
|
||||||
|
|
||||||
|
"custom/alhp": {
|
||||||
|
"id": "custom-alhp",
|
||||||
|
"exec": "$HOME/.config/waybar/scripts/alhp.sh",
|
||||||
|
"return-type": "json",
|
||||||
|
"interval": 60,
|
||||||
|
"tooltip": true,
|
||||||
|
"format": "{text}",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
52
.config/waybar/scripts/alhp.sh
Executable file
52
.config/waybar/scripts/alhp.sh
Executable file
@@ -0,0 +1,52 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
IFS=$'\n\t'
|
||||||
|
|
||||||
|
# defaults
|
||||||
|
text=""
|
||||||
|
tooltip='All good'
|
||||||
|
class='good'
|
||||||
|
|
||||||
|
# Check if alhp.utils command exists, if not consider it as down
|
||||||
|
if ! command -v alhp.utils &> /dev/null; then
|
||||||
|
tooltip="Service unavailable"
|
||||||
|
text=""
|
||||||
|
class="down"
|
||||||
|
else
|
||||||
|
ALHP_OUTPUT=$(alhp.utils -j)
|
||||||
|
mirror_stale=$(jq -r '.mirror_out_of_date' <<<"$ALHP_OUTPUT")
|
||||||
|
|
||||||
|
total=$(jq -r '.total' <<<"$ALHP_OUTPUT")
|
||||||
|
mirror_stale=$(jq -r '.mirror_out_of_date' <<<"$ALHP_OUTPUT")
|
||||||
|
|
||||||
|
# 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="$total"
|
||||||
|
tooltip=$(printf "%s\n" "${packages[@]}")
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "$class" in
|
||||||
|
good) icon=" ";;
|
||||||
|
stale) icon=" ";;
|
||||||
|
bad) icon=" ";;
|
||||||
|
down) icon="x ";;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# Emit compact JSON for Statusbar
|
||||||
|
jq -nc \
|
||||||
|
--arg text "<span color=\"#4F84CC\">$icon</span> <span color=\"#CAD3E8\">$text</span>" \
|
||||||
|
--arg class "$class" \
|
||||||
|
--arg tooltip "$tooltip" \
|
||||||
|
'{text: $text, class: $class, tooltip: $tooltip}'
|
||||||
|
|
Reference in New Issue
Block a user