Skip to content

Commit c9b936b

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 64834be commit c9b936b

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
@@ -8,6 +8,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
88

99
### Added
1010

11+
* 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)
1112
* Exclude Next.js build cache (`.next`)
1213
* Exclude Nuxt build cache (`.nuxt`)
1314
* Exclude Angular CLI cache (`.angular`)
@@ -117,3 +118,4 @@ Initial public release.
117118
[#55]: https://github.com/stevegrunwell/asimov/pull/55
118119
[#35]: https://github.com/stevegrunwell/asimov/pull/35
119120
[#56]: https://github.com/stevegrunwell/asimov/pull/56
121+
[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
#
@@ -106,7 +110,9 @@ exclude_file() {
106110
tmutil addexclusion "${path}"
107111

108112
sizeondisk=$(du -hs "${path}" | cut -f1)
113+
rawsize=$(du -sk "${path}" | cut -f1)
109114
echo "- ${path} has been excluded from Time Machine backups (${sizeondisk})."
115+
echo "${rawsize}" >> "$ASIMOV_SIZE_LOG"
110116
done
111117
}
112118

@@ -144,3 +150,21 @@ printf '\n\033[0;36mFinding dependency directories with corresponding definition
144150
find "${ASIMOV_ROOT}" \( "${find_parameters_skip[@]}" \) \( -false "${find_parameters_vendor[@]}" \) \
145151
| exclude_file \
146152
;
153+
154+
# Print summary.
155+
_excluded_count=$(wc -l < "$ASIMOV_SIZE_LOG" | tr -d ' ')
156+
if [[ "$_excluded_count" -gt 0 ]]; then
157+
_total_kb=$(awk '{s+=$1} END {print s}' "$ASIMOV_SIZE_LOG")
158+
159+
if [[ "$_total_kb" -ge 1048576 ]]; then
160+
_total_human="$(awk "BEGIN {printf \"%.1fG\", ${_total_kb}/1048576}")"
161+
elif [[ "$_total_kb" -ge 1024 ]]; then
162+
_total_human="$(awk "BEGIN {printf \"%.1fM\", ${_total_kb}/1024}")"
163+
else
164+
_total_human="${_total_kb}K"
165+
fi
166+
167+
printf '\n\033[0;32mDone! Excluded %d directories, totalling %s.\033[0m\n' "$_excluded_count" "$_total_human"
168+
else
169+
printf '\n\033[0;32mDone! No new directories to exclude.\033[0m\n'
170+
fi

tests/behavior.bats

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,29 @@ load test_helper
127127
refute_excluded "${HOME}/Code/My-Project/node_modules/dep/node_modules"
128128
[[ "$(count_exclusions)" -eq 1 ]]
129129
}
130+
131+
# =============================================================================
132+
# Summary output
133+
# =============================================================================
134+
135+
@test "prints summary with count when directories are excluded" {
136+
create_project "Code/Project-A" "package.json" "node_modules"
137+
create_project "Code/Project-B" "composer.json" "vendor"
138+
run_asimov
139+
[[ "$output" == *"Excluded 2 directories"* ]]
140+
}
141+
142+
@test "prints no-exclusion message when nothing to exclude" {
143+
run_asimov
144+
[[ "$output" == *"No new directories to exclude"* ]]
145+
}
146+
147+
@test "prints no-exclusion message when all directories already excluded" {
148+
create_project "Code/My-Project" "package.json" "node_modules"
149+
run_asimov
150+
assert_excluded "${HOME}/Code/My-Project/node_modules"
151+
152+
# Run again — everything is already excluded
153+
run_asimov
154+
[[ "$output" == *"No new directories to exclude"* ]]
155+
}

0 commit comments

Comments
 (0)