aboutsummaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authormerakor <cem@ckyln.com>2022-11-14 17:42:54 +0000
committermerakor <cem@ckyln.com>2022-11-14 17:42:54 +0000
commitba9c331949e99ac9926f27b3327dbd3a4407b875 (patch)
treea112e395a58eb6dc5a5fc9ebe0600b4f4f5d799e /contrib
parent3e26a7c96254806602086301333ed64ebed6c38a (diff)
downloadcpt-ba9c331949e99ac9926f27b3327dbd3a4407b875.tar.gz
cpt-size: add option to sort the files by size
FossilOrigin-Name: 2ad69811c2e13e2bfc121a79b0e45805ed91cf25f7b7fd56b15e2d83f609bae4
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/cpt-size13
1 files changed, 12 insertions, 1 deletions
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.