X-Git-Url: https://git.xandkar.net/?a=blobdiff_plain;f=home%2Fbin%2Fcargo-space;fp=home%2Fbin%2Fcargo-space;h=624c08df9874751d0347f6e2822ca87b260e9d36;hb=6625ae5330c1ea9f1960045799b904a3c505b91d;hp=0000000000000000000000000000000000000000;hpb=fc2e11b57c520cb88153821bcea7cb9eed71d80a;p=khome.git 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 "$@"