1
0
mirror of https://github.com/eoli3n/dotfiles synced 2024-11-22 15:01:59 +01:00

tooltip for storage module waybar

This commit is contained in:
eoli3n 2021-05-27 10:36:17 +02:00
parent a173ffc4ca
commit ee9bbf6a02

@ -1,5 +1,9 @@
#!/usr/bin/env bash
# Functions
escape() { while read l; do printf '%s\\n' "$l"; done }
# Vars
warning=85
critical=95
target="$1"
@ -13,13 +17,15 @@ then
exit
elif [[ "$fstype" == zfs ]]
then
zfsroot=$(echo $target | sed 's:/.*::')
pcent=$(zpool list -o cap -H $zfsroot | tr -d '%')
zfsroot=$(findmnt -nT "$target" -o SOURCE | sed 's:/.*::')
pcent=$(zpool list -o cap -H "$zfsroot" | tr -d '%')
tooltip=$(escape <<< "$(zfs list -o name,used,compressratio,logicalused,avail)")
else
pcent=$(df "$target" --output="pcent" 2>/dev/null | sed 1d | tr -d ' ' | tr -d '%')
tooltip="$pcent"
fi
json_fmt='{"text": "%s" , "class": "%s" }\n'
json_fmt='{"text": "%s" , "class": "%s", "tooltip": "%s"}\n'
if [[ -z $pcent ]]
then
@ -27,12 +33,12 @@ then
else
if [[ $pcent -lt $warning ]]
then
printf "$json_fmt" "$pcent" "normal"
printf "$json_fmt" "$pcent" "normal" "$tooltip"
elif [[ $pcent -ge $warning ]] && [[ $pcent -lt $critical ]]
then
printf "$json_fmt" "$pcent" "warning"
printf "$json_fmt" "$pcent" "warning" "$tooltip"
elif [[ $pcent -ge $critical ]]
then
printf "$json_fmt" "$pcent" "critical"
printf "$json_fmt" "$pcent" "critical" "$tooltip"
fi
fi