Improve disk space display

This commit is contained in:
Alice Gaudon 2023-03-08 11:31:20 +01:00
parent c3942f5973
commit b599517c2d

19
motd.sh
View File

@ -82,21 +82,29 @@ dim="\e[2m"
undim="\e[0m"
# disk usage: ignore zfs, squashfs & tmpfs
DISKS=$(df -H -x squashfs -x tmpfs -x devtmpfs -x zfs --output=target,pcent,size | tail -n+2)
DISKS=$(df -H -x squashfs -x tmpfs -x devtmpfs -x zfs --output=target,pcent,size,used | tail -n+2)
if test $(command -v zpool); then
if test $(command -v zfs); then
DISKS+="\n"
DISKS+=$(zpool list -o name,capacity,size | tail -n+2)
#DISKS+=$(zpool list -o name,capacity,size | tail -n+2)
while read name available used usedsnap usedds usedchild compressratio; do
ttlsize=$((($available+$used)))
pcent=$(echo "($used/$ttlsize)*100" | bc -l | numfmt --format="%3.0f")
gfxsize=$(numfmt --to=iec --format="%9f" $ttlsize)
gfxused=$(numfmt --to=iec --format="%9f" $used)
DISKS+="$name $pcent% $gfxsize $gfxused\n"
done <<< $(zfs list -H -p -d 0 -o name,available,used,usedsnap,usedds,usedchild,compressratio)
fi
printf "\nDisk usage:\n"
while read line; do
if [ -z "$line" ]; then
continuetest
continue
fi
# get disk usage
usage=$(echo "$line" | awk '{print $2}' | sed 's/%//')
used_width=$((($usage*$bar_width)/100))
# color is green if usage < max_usage, else red
if [ "${usage}" -ge "${max_usage}" ]; then
color=$red
@ -114,8 +122,9 @@ while read line; do
bar+="="
done
bar+="${undim}]"
# print usage line & bar
echo "${line}" | awk '{ printf("%-31s%+3s used out of %+4s\n", $1, $2, $3); }' | sed -e 's/^/ /'
echo "${line}" | awk '{ printf("%-36s%+4s/%+4s [%+3s]\n", $1, $4, $3, $2); }' | sed -e 's/^/ /'
echo -e "${bar}" | sed -e 's/^/ /'
done <<< $(echo -e "$DISKS")