#!/bin/sh # The MIT License (MIT) # # Copyright © 2020-2025 pacman64 # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the “Software”), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. # ndf [options...] [files...] # # Nice DF runs `df` and displays its output using ANSI styles, so things are # easier to scan/read. The options are the same as those for `df`. case "$1" in -help|--help) { awk '/^# +ndf /, /^$/ { gsub(/^# ?/, ""); print }' "$0" printf "\n\n" df --help } | less -MKiCRS --header=1 exit 0 ;; esac df "$@" | # add empty lines to chunk things, restyle numbers with at least 4 digits # to make them easier to read, and make 0s stand out awk ' (NR - 1) % 5 == 1 { print "" } { gsub(/[3-9][0-9]%/, "\x1b[38;2;204;124;0m&\x1b[0m") gsub(/[7-9][0-9]%/, "\x1b[38;2;204;0;0m&\x1b[0m") gsub(/ 0+%? /, "\x1b[38;2;0;105;185m&\x1b[0m") line = $0 # restyle digit-runs which are longer than 3 while (match(line, /[0-9]{4,}/)) { len = RLENGTH lead = len % 3 alt = lead > 0 printf "%s", substr(line, 1, RSTART + lead - 1) line = substr(line, RSTART + lead) len -= lead while (len > 0) { fs = (alt == 1) ? "\x1b[38;2;168;168;168m%s\x1b[0m" : "%s" printf fs, substr(line, 1, 3) alt = 1 - alt line = substr(line, 4) len -= 3 } } printf "%s\n", line } ' | less -MKiCRS --header=1