Skip to content

Commit f10be79

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 91730c2 commit f10be79

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
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`)
@@ -133,6 +134,7 @@ Initial public release.
133134
[#56]: https://github.com/stevegrunwell/asimov/pull/56
134135
[stevegrunwell/asimov#64]: https://github.com/stevegrunwell/asimov/pull/64
135136
[stevegrunwell/asimov#69]: https://github.com/stevegrunwell/asimov/pull/69
137+
[stevegrunwell/asimov#84]: https://github.com/stevegrunwell/asimov/issues/84
136138
[stevegrunwell/asimov#86]: https://github.com/stevegrunwell/asimov/issues/86
137139
[stevegrunwell/asimov#87]: https://github.com/stevegrunwell/asimov/pull/87
138140
[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
#
@@ -128,7 +132,9 @@ exclude_file() {
128132
fi
129133

130134
sizeondisk=$(du -hs "${path}" | cut -f1)
135+
rawsize=$(du -sk "${path}" | cut -f1)
131136
echo "- ${path} has been excluded from Time Machine backups (${sizeondisk})."
137+
echo "${rawsize}" >> "$ASIMOV_SIZE_LOG"
132138
done
133139
}
134140

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

tests/behavior.bats

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ load test_helper
143143
}
144144

145145
# =============================================================================
146-
<<<<<<< HEAD
147146
# Skip already-excluded directories (mdfind optimization)
148147
# =============================================================================
149148

@@ -246,3 +245,29 @@ load test_helper
246245
[[ "$output" == *"failed to exclude"* ]]
247246
[[ "$(count_exclusions)" -eq 0 ]]
248247
}
248+
249+
# =============================================================================
250+
# Summary output
251+
# =============================================================================
252+
253+
@test "prints summary with count when directories are excluded" {
254+
create_project "Code/Project-A" "package.json" "node_modules"
255+
create_project "Code/Project-B" "composer.json" "vendor"
256+
run_asimov
257+
[[ "$output" == *"Excluded 2 directories"* ]]
258+
}
259+
260+
@test "prints no-exclusion message when nothing to exclude" {
261+
run_asimov
262+
[[ "$output" == *"No new directories to exclude"* ]]
263+
}
264+
265+
@test "prints no-exclusion message when all directories already excluded" {
266+
create_project "Code/My-Project" "package.json" "node_modules"
267+
run_asimov
268+
assert_excluded "${HOME}/Code/My-Project/node_modules"
269+
270+
# Run again — everything is already excluded
271+
run_asimov
272+
[[ "$output" == *"No new directories to exclude"* ]]
273+
}

0 commit comments

Comments
 (0)