2020-11-23 23:20:02 +00:00
|
|
|
#!/bin/sh
|
2022-01-21 18:57:10 +00:00
|
|
|
# [d]isk [s]ize usage and partition overview
|
2022-01-10 20:39:57 +00:00
|
|
|
# For an accurate usage percentage add "f" as argument which uses "df"
|
2021-11-17 14:56:16 +00:00
|
|
|
if test "$1" = "f"
|
2021-11-23 12:03:43 +00:00
|
|
|
then df -B1M -x tmpfs -x devtmpfs -x squashfs | awk -v a="\033[31m" -v b="\033[33m" -v c="\033[35m" -v n="\033[0m" 'NR==1 {printf "%-20s %6s %7s %9s %s\n",$1,$5,$3,$4,$6} NR>1 {u=strtonum($5); printf (u > 99) ? a : (u > 97) ? b : (u > 94) ? c : ""; printf "%-20s %6s %6.1fG %8.1fG %s\n",$1,$5,$3/1024,$4/1024,$6; printf n}'
|
2021-11-17 14:56:16 +00:00
|
|
|
else
|
|
|
|
IFS="\n"
|
2022-01-21 18:57:10 +00:00
|
|
|
test "$(lsblk --version | cut -d. -f2)" -ge 37 && width="--width" && cols=$(tput cols) && outcols="s"
|
|
|
|
lsblk --output name,size,fsavail,fsuse%,mountpoint$outcols,label,fstype$(test "${cols:-0}" -gt 120 && echo ',uuid') $width $cols |
|
2021-11-17 14:56:16 +00:00
|
|
|
while read line
|
|
|
|
do p=$(echo "$line" | sed 's|.* \([[:digit:]]\+\)%.*|\1|;t;c0')
|
2022-02-10 14:59:41 +00:00
|
|
|
printf "$(expr "$line" : " " >/dev/null || echo "\033[$(test -z "$first" && echo "4" || expr "5;31" \& "$p" \> 98 \| "31" \& "$p" \> 97 \| "33" \& "$p" \> 94 \| "35" \& "$p" \> 90)m")%s\033[39m\n" "$line"
|
2021-11-17 14:56:16 +00:00
|
|
|
first=1
|
|
|
|
done
|
|
|
|
fi
|