aboutsummaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authormerakor <cem@ckyln.com>2023-02-05 17:30:18 +0000
committermerakor <cem@ckyln.com>2023-02-05 17:30:18 +0000
commitaabe332d65cabbc1dfc32ebb10ff68b85b54064f (patch)
tree2e4719d1db0587ba928dba06e27cc095db3fceab /contrib
parent19c12c4de57015f8621affad51a78335cc49d2f0 (diff)
downloadcpt-aabe332d65cabbc1dfc32ebb10ff68b85b54064f.tar.gz
cpt-size: add option to display only the total size of each given packageHEADmaster
FossilOrigin-Name: 495af02d29371f5aae7801e8c08ae4ec6de4c22c1bf2486d4ecd99f9108642d2
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/cpt-size28
1 files changed, 19 insertions, 9 deletions
diff --git a/contrib/cpt-size b/contrib/cpt-size
index ed48407..22a77b7 100755
--- a/contrib/cpt-size
+++ b/contrib/cpt-size
@@ -3,7 +3,7 @@
## SYNOPSIS:
## .Nm
-## .Op Fl s
+## .Op Fl st
## .Op Ar pkg...
## DESCRIPTION:
@@ -16,14 +16,16 @@
## .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.
+## 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##*/} [-s] [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
}
@@ -40,8 +42,16 @@ 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"