commit 164a3d9
chld
·
2026-08-30 04:49:01 +0000 UTC
parent 195661e
zs: (imported from kiss-community/kiss) calculate total file size
1 files changed,
+25,
-2
M
zs
M
zs
+25,
-2
1@@ -1,3 +1,26 @@
2-#!/bin/sh
3+#!/bin/sh -eu
4
5-du -sh `dtr pm $1`
6+# ripped from kiss-community/kiss/contrib/kiss-size lol
7+
8+get_size() {
9+ # Naive function to convert bytes to human readable
10+ # sizes (MB, KB, etc). This is probably wrong in places
11+ # though we can fix this over time. It's a start.
12+ case ${#1} in
13+ [0-3]) hum=$(($1))KB ;;
14+ [4-6]) hum=$(($1 / 1024))MB ;;
15+ [7-9]) hum=$(($1 / 1024 / 1024))GB ;;
16+ *) hum=$(($1)) ;;
17+ esac
18+
19+ printf '%s\t%s\n' "$hum" "$2"
20+}
21+
22+du -sk `dtr pm $1` |
23+ while read -r size file || {
24+ get_size "$tot" total >&2
25+ break
26+} do
27+ get_size "$size" "$file"
28+ tot=$((tot + size))
29+done