Add a cargo build space finder/counter script
authorSiraaj Khandkar <siraaj@khandkar.net>
Fri, 6 Jan 2023 23:04:58 +0000 (18:04 -0500)
committerSiraaj Khandkar <siraaj@khandkar.net>
Fri, 6 Jan 2023 23:04:58 +0000 (18:04 -0500)
home/bin/cargo-space [new file with mode: 0755]

diff --git a/home/bin/cargo-space b/home/bin/cargo-space
new file mode 100755 (executable)
index 0000000..624c08d
--- /dev/null
@@ -0,0 +1,27 @@
+#! /bin/bash
+
+total_cargo_build_space() {
+    local -r dir="$1"
+
+    local cargo_toml_path
+    local target_path
+
+    find "$dir" -type f -name Cargo.toml \
+    | while read -r cargo_toml_path
+    do
+        target_path=$(dirname "$cargo_toml_path")/target;
+        if test -d "$target_path"
+        then
+            du -s "$target_path"; fi
+        done \
+    | awk '{tot += $1} END {print tot * 1024}' \
+    | numfmt --to=iec
+}
+
+main() {
+    local -r dir="${1-$HOME}"
+
+    total_cargo_build_space "$dir"
+}
+
+main "$@"
This page took 0.017724 seconds and 4 git commands to generate.