From ee9bbf6a02d2cd7639cf3b91a354b164651675be Mon Sep 17 00:00:00 2001 From: eoli3n Date: Thu, 27 May 2021 10:36:17 +0200 Subject: [PATCH] tooltip for storage module waybar --- roles/waybar/files/waybar/modules/storage.sh | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/roles/waybar/files/waybar/modules/storage.sh b/roles/waybar/files/waybar/modules/storage.sh index 735232b..ec84153 100755 --- a/roles/waybar/files/waybar/modules/storage.sh +++ b/roles/waybar/files/waybar/modules/storage.sh @@ -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