summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordavidovski <david@davidovski.xyz>2022-06-20 00:08:10 +0100
committerdavidovski <david@davidovski.xyz>2022-06-20 00:08:10 +0100
commit786633be3f57f66eecaa5534f0a9703373439138 (patch)
tree1c11c868f0d15aa046ee127b0b9f079798d21f0d
parent1c930ef3795800b6897bfa64afb52b3104edf22b (diff)
added size command
-rw-r--r--src/install.sh15
-rw-r--r--src/query.sh23
-rwxr-xr-xsrc/xi.sh37
3 files changed, 56 insertions, 19 deletions
diff --git a/src/install.sh b/src/install.sh
index 52f0a13..4bbacbe 100644
--- a/src/install.sh
+++ b/src/install.sh
@@ -125,3 +125,18 @@ reinstall () {
install $@
}
+do_install () {
+ [ "$#" = "0" ] && set -- $(installed)
+
+ toinstall=${CACHE_DIR}/toinstall
+
+ echo "" > $toinstall
+ tofetch=""
+ for f in $@; do
+ [ -f "$f" ] && echo $f >> $toinstall || tofetch="$tofetch$f "
+ done
+
+ get $tofetch
+ install $(cat $toinstall)
+}
+
diff --git a/src/query.sh b/src/query.sh
index aff4512..9531a29 100644
--- a/src/query.sh
+++ b/src/query.sh
@@ -78,6 +78,7 @@ extract_info () {
#
print_info () {
file=$1
+ name=$(extract_info $file "NAME")
line="${LIGHT_CYAN}%-15s ${LIGHT_BLUE}%s\n"
for field in Name Description Version; do
printf "$line" "$field" "$(extract_info $file $field)"
@@ -86,9 +87,10 @@ print_info () {
printf "$line" "Dependencies" "$(extract_info $file "DEPS")"
printf "$line" "Build Date" "$(extract_info $file "DATE")"
- is_installed $(extract_info $file "NAME") && {
+ is_installed $name && {
date=$(date -d @$(stat -t $file | cut -d' ' -f13))
printf "$line" "Install Date" "$date"
+ printf "$line" "Install Size" "$(QUIET=true size_of $name)"
} || true
}
@@ -100,7 +102,24 @@ info () {
[ -f $infofile ] && {
print_info $infofile
} || {
- printf "Package info for $package could not be found!"
+ printf "Package info for $package could not be found!\n"
}
done
}
+
+# get the size of a package
+#
+size_of () {
+ local size=0 file=
+ for file in $(files $@); do
+ $VERBOSE && printf "${BLACK}file $file "
+ [ -f "$file" ] && {
+ set -- $(stat -t $file)
+ $VERBOSE && printf "has size $2"
+ size=$((size+$2))
+ }
+ $VERBOSE && printf "\n"
+ done
+ echo $size
+}
+
diff --git a/src/xi.sh b/src/xi.sh
index 923612c..eca3141 100755
--- a/src/xi.sh
+++ b/src/xi.sh
@@ -49,8 +49,10 @@ ${BLUE}Available Commands:
${LIGHT_CYAN}search the database for a package
${LIGHT_GREEN}files ${LIGHT_BLUE}[package]
${LIGHT_CYAN}list files belonging to a package
- ${LIGHT_GREEN}verify ${LIGHT_BLUE}[package]
+ ${LIGHT_GREEN}verify ${LIGHT_BLUE}[package...]
${LIGHT_CYAN}verify that a package's files are intact
+ ${LIGHT_GREEN}size ${LIGHT_BLUE}[package...]
+ ${LIGHT_CYAN}get the Total installed size of a package
${LIGHT_GREEN}list
${LIGHT_CYAN}list available packages
${LIGHT_GREEN}installed
@@ -133,21 +135,6 @@ done
. ${LIBDIR}/get.sh
. ${LIBDIR}/remove.sh
-do_install () {
- [ "$#" = "0" ] && set -- $(installed)
-
- toinstall=${CACHE_DIR}/toinstall
-
- echo "" > $toinstall
- tofetch=""
- for f in $@; do
- [ -f "$f" ] && echo $f >> $toinstall || tofetch="$tofetch$f "
- done
-
- get $tofetch
- install $(cat $toinstall)
-}
-
shift $((OPTIND-1))
if [ "$#" = "0" ]; then
@@ -169,7 +156,6 @@ else
checkroot
[ "$#" = "0" ] && set -- $(installed)
-
build $@
;;
"search")
@@ -218,6 +204,23 @@ else
"installed")
installed
;;
+ "size")
+ shift
+ [ "$#" = "0" ] && set -- $(installed)
+
+ total=$(for p in $@; do
+ echo "$(size_of $p) $p"
+ done | sort -n | while read f; do
+ set -- $f
+ $QUIET || printf "${WHITE}Size of ${BLUE}%s${WHITE}: ${LIGHT_WHITE}%s\n" "$2" "$(format_bytes $1)" >/dev/stderr
+ echo $1
+ done | paste -s -d+ - | bc)
+
+ $QUIET && echo $total || {
+ [ "$total" != "$size" ] &&
+ printf "${WHITE}Total size: ${LIGHT_WHITE}%s\n" "$(format_bytes $total)"
+ }
+ ;;
"file")
shift
file_info $@