From ab96989293e819674203d6317abffd644b0b38ea Mon Sep 17 00:00:00 2001 From: ville rantanen Date: Fri, 23 Nov 2018 14:50:12 +0200 Subject: [PATCH] fastdu support sorting better --- files/fastdu | 38 ++++++++++++++++++++++---------------- reporting/md-site | 2 +- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/files/fastdu b/files/fastdu index bc0b68b..bb929c5 100755 --- a/files/fastdu +++ b/files/fastdu @@ -16,16 +16,16 @@ function filesize() { # Usage: filesize 10000 [ "$1" = "0" ] && { - echo "0 B" + echo "0~B" return 0 } awk 'BEGIN{ x = '$1' - split("B kB MB GB TB PB EB ZB",type) + split("B kB MB GB TB PB EB ZB", type) for(i=7;y < 1;i--) y = x / (2^(10*i)) - str=int(y*10)/10 " " type[i+2] - if (i==-1) { str = x " B" } + str=int(y*10)/10 type[i+2] + if (i==-1) { str = x "~B" } print str }' || return $? } @@ -33,7 +33,7 @@ function siprefix() { # Return a SI prefixed string from integer [ "$1" = "0" ] && { - echo "0 #" + echo "0~#" return 0 } @@ -41,8 +41,8 @@ function siprefix() { split("# k# M# G# T# P# E# Z#",type) for(i=7;y < 1;i--) y = x / (10^(3*i)) - str=int(y*10)/10 " " type[i+2] - if (i==-1) { str = x " #" } + str=int(y*10)/10 type[i+2] + if (i==-1) { str = x "~#" } print str }' || return $? } @@ -74,15 +74,22 @@ function processfolder() { echo -e "$SIZE\t$COUNTS" } +function formatter() { + cat - | xargs printf "$FORMAT" | sed -e 's,~B, B,' -e 's,~#, #,' +} # Get options what=() for (( i=1; i<=$#; i++ )); do - [[ "${!i}" = "-a" ]] && { ANIMATE=1; continue; } [[ "${!i}" = "-f" ]] && { FORMAT=1; ((i++)); FORMAT_VALUE=${!i}; continue; } [[ "${!i}" = "--help" ]] && helpexit - [[ "${!i}" = "-h" ]] && { HUMAN=1; continue; } - [[ "${!i}" = "-c" ]] && { COUNT=1; continue; } - [[ "${!i}" = "-s" ]] && { SUMMARY=1; continue; } + + [[ "${!i}" = "-"* ]] && { + [[ "${!i}" =~ -.*a ]] && { ANIMATE=1; } + [[ "${!i}" =~ -.*h ]] && { HUMAN=1; } + [[ "${!i}" =~ -.*c ]] && { COUNT=1; } + [[ "${!i}" =~ -.*s ]] && { SUMMARY=1; } + continue + } what+=( "${!i}" ) done @@ -93,7 +100,7 @@ if [[ "$FORMAT" -eq 1 ]]; then echo -e "\nBytes argument missing\n\n" helpexit fi - filesize $FORMAT_VALUE + filesize $FORMAT_VALUE | sed 's,~B, B,' exit $? fi @@ -103,7 +110,7 @@ fi if [[ "$ANIMATE" -eq 1 ]]; then animate & fi -[[ "$HUMAN" -eq 1 ]] && NUMFORMAT="%5s %2s " +[[ "$HUMAN" -eq 1 ]] && NUMFORMAT="%7s " [[ "$HUMAN" -ne 1 ]] && NUMFORMAT="%d\t" [[ "$COUNT" -eq 1 ]] && NUMBERS="$NUMFORMAT$NUMFORMAT" [[ "$COUNT" -ne 1 ]] && NUMBERS="$NUMFORMAT" @@ -113,12 +120,11 @@ fi if [[ "$SUMMARY" -eq 1 ]]; then # Display one line - processfolder "${what[@]}" | xargs printf "$FORMAT" - echo '' + processfolder "${what[@]}" | formatter else # One size for each argument for ((i=0; i<"${#what[@]}"; i++)); do - processfolder "${what[$i]}" | xargs printf "$FORMAT" + processfolder "${what[$i]}" | formatter echo "${what[$i]}" done fi diff --git a/reporting/md-site b/reporting/md-site index cfb9dd5..a6220ae 100755 --- a/reporting/md-site +++ b/reporting/md-site @@ -52,7 +52,7 @@ _build() { echo Target folder not an mdsite folder, delete first exit 1 fi - rsync -r --del "$1"/ "$2" + rsync -r "$1"/ "$2" touch "$2"/.mdsite echo "----" shopt -s nullglob