Add cargo build space global cleaner
[khome.git] / home / bin / cargo-clean-all
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.03315 seconds and 4 git commands to generate.