Skip to content

Commit dfbb421

Browse files
authored
feat: display summary of excluded directories at end of run (#7)
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 aace9da commit dfbb421

File tree

3 files changed

+74
-25
lines changed

3 files changed

+74
-25
lines changed

CHANGELOG.md

Lines changed: 24 additions & 25 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`)
@@ -104,32 +105,30 @@ Initial public release.
104105

105106

106107
[Unreleased]: https://github.com/stevegrunwell/asimov/compare/master...develop
107-
[Version 0.1.0]: https://github.com/stevegrunwell/asimov/releases/tag/v0.1.0
108-
[Version 0.2.0]: https://github.com/stevegrunwell/asimov/releases/tag/v0.2.0
109-
[Version 0.3.0]: https://github.com/stevegrunwell/asimov/releases/tag/v0.3.0
110-
[#5]: https://github.com/stevegrunwell/asimov/issues/5
111-
[#7]: https://github.com/stevegrunwell/asimov/issues/7
112-
[#10]: https://github.com/stevegrunwell/asimov/issues/10
113-
[#15]: https://github.com/stevegrunwell/asimov/pull/15
114-
[#16]: https://github.com/stevegrunwell/asimov/pull/16
115-
[#17]: https://github.com/stevegrunwell/asimov/pull/17
116-
[#18]: https://github.com/stevegrunwell/asimov/pull/18
117-
[#20]: https://github.com/stevegrunwell/asimov/pull/20
118-
[#22]: https://github.com/stevegrunwell/asimov/pull/22
119-
[#30]: https://github.com/stevegrunwell/asimov/pull/30
120-
[#31]: https://github.com/stevegrunwell/asimov/pull/31
121-
[#32]: https://github.com/stevegrunwell/asimov/pull/32
122-
[#33]: https://github.com/stevegrunwell/asimov/pull/33
123-
[#34]: https://github.com/stevegrunwell/asimov/pull/34
124-
[#36]: https://github.com/stevegrunwell/asimov/pull/36
125-
[#37]: https://github.com/stevegrunwell/asimov/pull/37
126-
[#43]: https://github.com/stevegrunwell/asimov/pull/43
127-
[#52]: https://github.com/stevegrunwell/asimov/pull/52
128-
[#55]: https://github.com/stevegrunwell/asimov/pull/55
129-
[#35]: https://github.com/stevegrunwell/asimov/pull/35
130-
[#56]: https://github.com/stevegrunwell/asimov/pull/56
108+
[stevegrunwell/asimov#10]: https://github.com/stevegrunwell/asimov/issues/10
109+
[stevegrunwell/asimov#15]: https://github.com/stevegrunwell/asimov/pull/15
110+
[stevegrunwell/asimov#16]: https://github.com/stevegrunwell/asimov/pull/16
111+
[stevegrunwell/asimov#17]: https://github.com/stevegrunwell/asimov/pull/17
112+
[stevegrunwell/asimov#18]: https://github.com/stevegrunwell/asimov/pull/18
113+
[stevegrunwell/asimov#20]: https://github.com/stevegrunwell/asimov/pull/20
114+
[stevegrunwell/asimov#22]: https://github.com/stevegrunwell/asimov/pull/22
115+
[stevegrunwell/asimov#30]: https://github.com/stevegrunwell/asimov/pull/30
116+
[stevegrunwell/asimov#31]: https://github.com/stevegrunwell/asimov/pull/31
117+
[stevegrunwell/asimov#32]: https://github.com/stevegrunwell/asimov/pull/32
118+
[stevegrunwell/asimov#33]: https://github.com/stevegrunwell/asimov/pull/33
119+
[stevegrunwell/asimov#34]: https://github.com/stevegrunwell/asimov/pull/34
120+
[stevegrunwell/asimov#36]: https://github.com/stevegrunwell/asimov/pull/36
121+
[stevegrunwell/asimov#37]: https://github.com/stevegrunwell/asimov/pull/37
122+
[stevegrunwell/asimov#43]: https://github.com/stevegrunwell/asimov/pull/43
123+
[stevegrunwell/asimov#52]: https://github.com/stevegrunwell/asimov/pull/52
124+
[stevegrunwell/asimov#55]: https://github.com/stevegrunwell/asimov/pull/55
125+
[stevegrunwell/asimov#35]: https://github.com/stevegrunwell/asimov/pull/35
126+
[stevegrunwell/asimov#56]: https://github.com/stevegrunwell/asimov/pull/56
131127
[stevegrunwell/asimov#64]: https://github.com/stevegrunwell/asimov/pull/64
132128
[stevegrunwell/asimov#69]: https://github.com/stevegrunwell/asimov/pull/69
133-
[stevegrunwell/asimov#72]: https://github.com/stevegrunwell/asimov/issues/72
134129
[stevegrunwell/asimov#87]: https://github.com/stevegrunwell/asimov/pull/87
135130
[stevegrunwell/asimov#97]: https://github.com/stevegrunwell/asimov/pull/97
131+
[stevegrunwell/asimov#5]: https://github.com/stevegrunwell/asimov/issues/5
132+
[stevegrunwell/asimov#7]: https://github.com/stevegrunwell/asimov/issues/7
133+
[stevegrunwell/asimov#72]: https://github.com/stevegrunwell/asimov/issues/72
134+
[stevegrunwell/asimov#84]: https://github.com/stevegrunwell/asimov/issues/84

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
#
@@ -137,7 +141,9 @@ exclude_file() {
137141
tmutil addexclusion "${path}"
138142

139143
sizeondisk=$(du -hs "${path}" | cut -f1)
144+
rawsize=$(du -sk "${path}" | cut -f1)
140145
echo "- ${path} has been excluded from Time Machine backups (${sizeondisk})."
146+
echo "${rawsize}" >> "$ASIMOV_SIZE_LOG"
141147
done
142148
}
143149

@@ -200,3 +206,21 @@ for dir in "${ASIMOV_FIXED_DIRS[@]}"; do
200206
echo "$dir"
201207
fi
202208
done | exclude_file
209+
210+
# Print summary.
211+
_excluded_count=$(wc -l < "$ASIMOV_SIZE_LOG" | tr -d ' ')
212+
if [[ "$_excluded_count" -gt 0 ]]; then
213+
_total_kb=$(awk '{s+=$1} END {print s}' "$ASIMOV_SIZE_LOG")
214+
215+
if [[ "$_total_kb" -ge 1048576 ]]; then
216+
_total_human="$(awk "BEGIN {printf \"%.1fG\", ${_total_kb}/1048576}")"
217+
elif [[ "$_total_kb" -ge 1024 ]]; then
218+
_total_human="$(awk "BEGIN {printf \"%.1fM\", ${_total_kb}/1024}")"
219+
else
220+
_total_human="${_total_kb}K"
221+
fi
222+
223+
printf '\n\033[0;32mDone! Excluded %d directories, totalling %s.\033[0m\n' "$_excluded_count" "$_total_human"
224+
else
225+
printf '\n\033[0;32mDone! No new directories to exclude.\033[0m\n'
226+
fi

tests/behavior.bats

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,29 @@ load test_helper
218218
second_count="$(count_exclusions)"
219219
[[ "$second_count" -eq 1 ]]
220220
}
221+
222+
# =============================================================================
223+
# Summary output
224+
# =============================================================================
225+
226+
@test "prints summary with count when directories are excluded" {
227+
create_project "Code/Project-A" "package.json" "node_modules"
228+
create_project "Code/Project-B" "composer.json" "vendor"
229+
run_asimov
230+
[[ "$output" == *"Excluded 2 directories"* ]]
231+
}
232+
233+
@test "prints no-exclusion message when nothing to exclude" {
234+
run_asimov
235+
[[ "$output" == *"No new directories to exclude"* ]]
236+
}
237+
238+
@test "prints no-exclusion message when all directories already excluded" {
239+
create_project "Code/My-Project" "package.json" "node_modules"
240+
run_asimov
241+
assert_excluded "${HOME}/Code/My-Project/node_modules"
242+
243+
# Run again — everything is already excluded
244+
run_asimov
245+
[[ "$output" == *"No new directories to exclude"* ]]
246+
}

0 commit comments

Comments
 (0)