From ba9c331949e99ac9926f27b3327dbd3a4407b875 Mon Sep 17 00:00:00 2001 From: merakor Date: Mon, 14 Nov 2022 17:42:54 +0000 Subject: cpt-size: add option to sort the files by size FossilOrigin-Name: 2ad69811c2e13e2bfc121a79b0e45805ed91cf25f7b7fd56b15e2d83f609bae4 --- contrib/cpt-size | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'contrib/cpt-size') diff --git a/contrib/cpt-size b/contrib/cpt-size index 00508b8..ed48407 100755 --- a/contrib/cpt-size +++ b/contrib/cpt-size @@ -3,6 +3,7 @@ ## SYNOPSIS: ## .Nm +## .Op Fl s ## .Op Ar pkg... ## DESCRIPTION: @@ -14,8 +15,15 @@ ## been given, ## .Nm ## will use the name of the current directory as an argument. +## .Pp +## If the +## .Fl s +## flag is given, +## .Nm +## will sort the files by size. parser_definition() { - setup REST help:usage -- "usage: ${0##*/} [pkg...]" + setup REST help:usage -- "usage: ${0##*/} [-s] [pkg...]" + flag sort -s hidden:1 disp :usage -h --help hidden:1 } @@ -35,6 +43,9 @@ mkdir -p "$tmp_dir" for pkg; do sed '/\/$/d;s/./\\&/g' "$sys_db/$pkg/manifest"; done | xargs du -k > "$tmp_dir/size" +# Do a numerical sort on the file if requested. +[ "$sort" ] && sort -no "$tmp_dir/size" "$tmp_dir/size" + # This awk function formats the `du` output similar to the '-hc' flags. We # could have used a shell `while read` loop to do the exact same thing, but that # would be much much slower. -- cgit v1.2.3