Add cargo build space global cleaner
authorSiraaj Khandkar <siraaj@khandkar.net>
Sat, 7 Jan 2023 19:09:03 +0000 (14:09 -0500)
committerSiraaj Khandkar <siraaj@khandkar.net>
Sat, 7 Jan 2023 19:22:13 +0000 (14:22 -0500)
home/bin/cargo-clean-all [new file with mode: 0755]

diff --git a/home/bin/cargo-clean-all b/home/bin/cargo-clean-all
new file mode 100755 (executable)
index 0000000..fb3af47
--- /dev/null
@@ -0,0 +1,15 @@
+#! /bin/bash
+
+N_CPUS=$(nproc 2> /dev/null || gnproc 2> /dev/null || sysctl -n hw.ncpu 2> /dev/null)
+
+main() {
+    local -r dir="${1-$HOME}"
+    local -r jobs="${1-$N_CPUS}"
+
+    # XXX Just doing 'rm -rf' because 'cargo clean' starts doing extra work
+    #     and in some cases even downloads new deps, etc.
+    find "$dir" -type f -name Cargo.toml -print0 \
+    | xargs -0 -I % -P "$jobs" sh -c 'rm -rf $(dirname "%")/target'
+}
+
+main "$@"
This page took 0.029088 seconds and 4 git commands to generate.