From: Siraaj Khandkar Date: Fri, 6 Jan 2023 23:04:58 +0000 (-0500) Subject: Add a cargo build space finder/counter script X-Git-Url: https://git.xandkar.net/?p=khome.git;a=commitdiff_plain;h=6625ae5330c1ea9f1960045799b904a3c505b91d Add a cargo build space finder/counter script --- diff --git a/home/bin/cargo-space b/home/bin/cargo-space new file mode 100755 index 0000000..624c08d --- /dev/null +++ b/home/bin/cargo-space @@ -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 "$@"