From cbc826bc8fb2b2551750ded22f2dc277fbc5f567 Mon Sep 17 00:00:00 2001 From: q Date: Sun, 12 Aug 2018 09:26:12 +0300 Subject: [PATCH] better formatting for fastdu humanreadable --- files/fastdu | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/files/fastdu b/files/fastdu index 4c1e0e5..bcdb414 100755 --- a/files/fastdu +++ b/files/fastdu @@ -13,7 +13,7 @@ function filesize() { # Usage: filesize 10000 [ "$1" = "0" ] && { - echo "0 B" + echo "0 B" return 0 } @@ -22,7 +22,7 @@ function filesize() { for(i=7;y < 1;i--) y = x / (2^(10*i)) str=int(y*10)/10 " " type[i+2] - if (x==0) { str = "0 B" } + if (x==0) { str = "0 B" } print str }' || return $? } @@ -87,9 +87,14 @@ if [[ "$SUMMARY" -eq 1 ]]; then # Display one line processfolder "${what[@]}" else + if [[ "$HUMAN" -eq 1 ]]; then + FORMAT="%8s %s\n" + else + FORMAT="%d\t%s\n" + fi # One size for each argument for dir in "${what[@]}"; do - printf "%s\t%s\n" "$( processfolder "$dir" )" "$dir" + printf "$FORMAT" "$( processfolder "$dir" )" "$dir" done fi