From 6625ae5330c1ea9f1960045799b904a3c505b91d Mon Sep 17 00:00:00 2001 From: Siraaj Khandkar Date: Fri, 6 Jan 2023 18:04:58 -0500 Subject: [PATCH] Add a cargo build space finder/counter script --- home/bin/cargo-space | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 home/bin/cargo-space 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 "$@" -- 2.20.1