#!/bin/sh # [d]ist [s]ize usage and partition overview # For an accurate usage percentage add "f" as argument which uses "df" if test "$1" = "f" 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}' else IFS="\n" cols=$(tput cols) lsblk --output name,size,fsavail,fsuse%,mountpoints,label,fstype$(test $cols -gt 110 && echo ',uuid') --width $cols | while read line do p=$(echo "$line" | sed 's|.* \([[:digit:]]\+\)%.*|\1|;t;c0') 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\n" "$line" first=1 done fi