From f04fba20485500b35ba81bea45d810a78ed90634 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Sat, 24 Jan 2015 01:38:49 -0800 Subject: [PATCH] project-disk-use.sh: add separators to numbers to improve readability --- toolbox/reports/project-disk-use.sh | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/toolbox/reports/project-disk-use.sh b/toolbox/reports/project-disk-use.sh index 82922cf..b700c48 100755 --- a/toolbox/reports/project-disk-use.sh +++ b/toolbox/reports/project-disk-use.sh @@ -33,6 +33,22 @@ command -v nice > /dev/null && hasnice=1 hasionice= command -v ionice > /dev/null && hasionice=1 +nl="$(printf '\n*')" +nl="${nl%?}" + +fmtcomma() { + # remove leading 0s + _y="${1%%[1-9]*}"; _x="${1#$_y}"; _x="${_x:-0}" + # add commas after each group of 3 + _y= + while [ $_x -gt 999 ]; do + _y="$(printf '%03d' $(($_x - $_x / 1000 * 1000)))${_y:+,$_y}" + _x="$(($_x/1000))" + done + [ $_x -eq 0 ] || _y="$_x${_y:+,$_y}" + echo "${_y:-0}" +} + get_use_k() { _cmd="du -k -s \"$1\" 2>/dev/null | cut -f 1" [ -n "$hasionice" ] && _cmd="ionice -c 3 $_cmd" @@ -68,8 +84,7 @@ while IFS='' read -r proj; do usek="$(get_use_k "$proj.git")" total="$(( $total + $usek ))" howmany="$(( $howmany + 1 ))" - line="$(printf '%8d %s %s%s\n*' "$usek" "$mirror" "$proj" "$x")" - line="${line%?}" + line="$usek $mirror $proj$x$nl" results="$results$line" done </dev/null) @@ -88,17 +103,17 @@ Project Disk Use Report End Time: $enddate Repository Root: $cfg_reporoot - Disk Use: $inuse (1024-byte blocks) - reposizek Total: $ktotal ($kpct%) + Disk Use: $(fmtcomma "$inuse") (1024-byte blocks) + reposizek Total: $(fmtcomma "$ktotal") ($kpct%) Recycle Bin Root: $cfg_reporoot-recyclebin - Disk Use: $binned (1024-byte blocks) + Disk Use: $(fmtcomma "$binned") (1024-byte blocks) - Total Disk Use: $(( $inuse + $binned )) (1024-byte blocks) + Total Disk Use: $(fmtcomma "$(( $inuse + $binned ))") (1024-byte blocks) -Repository Count: $howmany - Orphaned: $orphans -Repository Total: $total (1024-byte blocks) +Repository Count: $(fmtcomma "$howmany") + Orphaned: $(fmtcomma "$orphans") +Repository Total: $(fmtcomma "$total") (1024-byte blocks) $(df -h "$cfg_reporoot") EOT @@ -116,6 +131,9 @@ EOT echo "$message" | tr -c '\n' - echo "" printf '%s' "$results" | sort -k1,1nr -k3,3 | \ + while read -r a b c; do + printf "%10s %s %s\n" "$(fmtcomma "$a")" "$b" "$c" + done | \ sed -e 's/ M / /' | $topn fi } | eval "$domail" -- 2.11.4.GIT