Skip to content

Commit 1e1f526

Browse files
committed
feat: display summary of excluded directories at end of run
Show the total count and combined size of newly excluded directories after each run, making it easy to see the impact at a glance. Inspired by stevegrunwell#84, props @Vadorequest.
1 parent 5d4263d commit 1e1f526

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
1111
* Support glob patterns in sentinel definitions, enabling wildcards like `*.xcodeproj` ([stevegrunwell/asimov#64], props @mdab121)
1212
* Exclude Xcode DerivedData when `*.xcodeproj` is present ([stevegrunwell/asimov#64], props @mdab121)
1313
* Exclude well-known global cache directories (`~/.cache`, `~/.gradle/caches`, `~/.m2/repository`, `~/.npm/_cacache`, `~/.nuget/packages`, `~/.kube/cache`, etc.) without requiring sentinel files (inspired by [stevegrunwell/asimov#69], props @pkuczynski)
14+
* Display a summary of total count and size of newly excluded directories at the end of each run (inspired by [stevegrunwell/asimov#84], props @Vadorequest)
1415
* Exclude Next.js build cache (`.next`)
1516
* Exclude Nuxt build cache (`.nuxt`)
1617
* Exclude Angular CLI cache (`.angular`)
@@ -129,5 +130,6 @@ Initial public release.
129130
[#56]: https://github.com/stevegrunwell/asimov/pull/56
130131
[stevegrunwell/asimov#64]: https://github.com/stevegrunwell/asimov/pull/64
131132
[stevegrunwell/asimov#69]: https://github.com/stevegrunwell/asimov/pull/69
133+
[stevegrunwell/asimov#84]: https://github.com/stevegrunwell/asimov/issues/84
132134
[stevegrunwell/asimov#87]: https://github.com/stevegrunwell/asimov/pull/87
133135
[stevegrunwell/asimov#97]: https://github.com/stevegrunwell/asimov/pull/97

asimov

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#!/usr/bin/env bash
22
set -Eeu -o pipefail
33

4+
# Temp file for tracking excluded directory sizes (cleaned up on exit).
5+
ASIMOV_SIZE_LOG="$(mktemp)"
6+
trap 'rm -f "$ASIMOV_SIZE_LOG"' EXIT
7+
48
# Look through the local filesystem and exclude development dependencies
59
# from Apple Time Machine backups.
610
#
@@ -125,7 +129,9 @@ exclude_file() {
125129
tmutil addexclusion "${path}"
126130

127131
sizeondisk=$(du -hs "${path}" | cut -f1)
132+
rawsize=$(du -sk "${path}" | cut -f1)
128133
echo "- ${path} has been excluded from Time Machine backups (${sizeondisk})."
134+
echo "${rawsize}" >> "$ASIMOV_SIZE_LOG"
129135
done
130136
}
131137

@@ -188,3 +194,21 @@ for dir in "${ASIMOV_FIXED_DIRS[@]}"; do
188194
echo "$dir"
189195
fi
190196
done | exclude_file
197+
198+
# Print summary.
199+
_excluded_count=$(wc -l < "$ASIMOV_SIZE_LOG" | tr -d ' ')
200+
if [[ "$_excluded_count" -gt 0 ]]; then
201+
_total_kb=$(awk '{s+=$1} END {print s}' "$ASIMOV_SIZE_LOG")
202+
203+
if [[ "$_total_kb" -ge 1048576 ]]; then
204+
_total_human="$(awk "BEGIN {printf \"%.1fG\", ${_total_kb}/1048576}")"
205+
elif [[ "$_total_kb" -ge 1024 ]]; then
206+
_total_human="$(awk "BEGIN {printf \"%.1fM\", ${_total_kb}/1024}")"
207+
else
208+
_total_human="${_total_kb}K"
209+
fi
210+
211+
printf '\n\033[0;32mDone! Excluded %d directories, totalling %s.\033[0m\n' "$_excluded_count" "$_total_human"
212+
else
213+
printf '\n\033[0;32mDone! No new directories to exclude.\033[0m\n'
214+
fi

tests/behavior.bats

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,3 +207,29 @@ load test_helper
207207
second_count="$(count_exclusions)"
208208
[[ "$second_count" -eq 1 ]]
209209
}
210+
211+
# =============================================================================
212+
# Summary output
213+
# =============================================================================
214+
215+
@test "prints summary with count when directories are excluded" {
216+
create_project "Code/Project-A" "package.json" "node_modules"
217+
create_project "Code/Project-B" "composer.json" "vendor"
218+
run_asimov
219+
[[ "$output" == *"Excluded 2 directories"* ]]
220+
}
221+
222+
@test "prints no-exclusion message when nothing to exclude" {
223+
run_asimov
224+
[[ "$output" == *"No new directories to exclude"* ]]
225+
}
226+
227+
@test "prints no-exclusion message when all directories already excluded" {
228+
create_project "Code/My-Project" "package.json" "node_modules"
229+
run_asimov
230+
assert_excluded "${HOME}/Code/My-Project/node_modules"
231+
232+
# Run again — everything is already excluded
233+
run_asimov
234+
[[ "$output" == *"No new directories to exclude"* ]]
235+
}

0 commit comments

Comments
 (0)