This commit is contained in:
2026-04-17 19:38:35 +02:00
parent 556c0823c2
commit 8e6f0db4ba
9 changed files with 962 additions and 65 deletions

View File

@@ -7,10 +7,37 @@ LABEL="$2"
ICON_MOUNT="󰋊"
ICON_DOWN=""
json_escape() {
local s="$1"
s=${s//\\/\\\\}
s=${s//\"/\\\"}
s=${s//$'\n'/\\n}
printf '%s' "$s"
}
markup_escape() {
local s="$1"
s=${s//&/&}
s=${s//</&lt;}
s=${s//>/&gt;}
printf '%s' "$s"
}
icon_markup() {
local icon="$1"
local color="$2"
printf '<span font_desc="SauceCodePro Nerd Font 15" foreground="%s">%s</span>' "$color" "$icon"
}
if mountpoint -q "$MOUNT"; then
read -r used avail pcent <<< "$(df -h --output=used,avail,pcent "$MOUNT" | tail -1)"
printf '{"text": "%s %s %s/%s (%s)", "tooltip": "%s mounted — used: %s, free: %s (%s)", "class": "mounted"}\n' \
"$ICON_MOUNT" "$LABEL" "$used" "$avail" "$pcent" "$MOUNT" "$used" "$avail" "$pcent"
text="<span foreground=\"#D8DEE9\">$(markup_escape "$LABEL $used/$avail ($pcent)")</span> $(icon_markup "$ICON_MOUNT" "#A3BE8C")"
tooltip="$(markup_escape "$MOUNT mounted - used: $used, free: $avail ($pcent)")"
printf '{"text":"%s","tooltip":"%s","class":"mounted"}\n' \
"$(json_escape "$text")" "$(json_escape "$tooltip")"
else
printf '{"text": "%s %s N/A", "tooltip": "%s is NOT mounted", "class": "unmounted"}\n' "$ICON_DOWN" "$LABEL" "$MOUNT"
text="<span foreground=\"#EBCB8B\">$(markup_escape "$LABEL N/A")</span> $(icon_markup "$ICON_DOWN" "#BF616A")"
tooltip="$(markup_escape "$MOUNT is NOT mounted")"
printf '{"text":"%s","tooltip":"%s","class":"unmounted"}\n' \
"$(json_escape "$text")" "$(json_escape "$tooltip")"
fi