From: Siraaj Khandkar Date: Sat, 7 Jan 2023 19:09:03 +0000 (-0500) Subject: Add cargo build space global cleaner X-Git-Url: https://git.xandkar.net/?a=commitdiff_plain;h=70dc9e92d12a30d417a55baf6a0ddf474bd90929;p=khome.git Add cargo build space global cleaner --- diff --git a/home/bin/cargo-clean-all b/home/bin/cargo-clean-all new file mode 100755 index 0000000..fb3af47 --- /dev/null +++ b/home/bin/cargo-clean-all @@ -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 "$@"