aboutsummaryrefslogtreecommitdiff
path: root/contrib/cpt-size
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/cpt-size')
-rwxr-xr-xcontrib/cpt-size27
1 files changed, 24 insertions, 3 deletions
diff --git a/contrib/cpt-size b/contrib/cpt-size
index 00508b8..22a77b7 100755
--- a/contrib/cpt-size
+++ b/contrib/cpt-size
@@ -3,6 +3,7 @@
## SYNOPSIS:
## .Nm
+## .Op Fl st
## .Op Ar pkg...
## DESCRIPTION:
@@ -14,8 +15,17 @@
## been given,
## .Nm
## will use the name of the current directory as an argument.
+## .Pp
+## The options are as follows:
+## .Bl -tag -width 13n
+## .It Fl s
+## Sort the output by size.
+## .It Fl t
+## Output only the size of given packages and not individual files.
parser_definition() {
- setup REST help:usage -- "usage: ${0##*/} [pkg...]"
+ setup REST help:usage -- "usage: ${0##*/} [-st] [pkg...]"
+ flag sort -s hidden:1
+ flag total -t hidden:1
disp :usage -h --help hidden:1
}
@@ -32,8 +42,19 @@ pkg_list "$@" >/dev/null
mkdir -p "$tmp_dir"
# We don't immediately pipe into awk as we want to exit in an error.
-for pkg; do sed '/\/$/d;s/./\\&/g' "$sys_db/$pkg/manifest"; done |
- xargs du -k > "$tmp_dir/size"
+if [ "$total" ]; then
+ for pkg; do
+ sed '/\/$/d;s/./\\&/g' "$sys_db/$pkg/manifest" |
+ xargs du -k |
+ awk -v name="$pkg" '{size+=$1}END{printf("%s %s\n", size, name)}' >> "$tmp_dir/size"
+ done
+else
+ for pkg; do sed '/\/$/d;s/./\\&/g' "$sys_db/$pkg/manifest"; done |
+ xargs du -k > "$tmp_dir/size"
+fi
+
+# 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