Repository navigation
Expand file tree
/
Copy pathfreespace.sh
More file actions
executable file
·1712 lines (1567 loc) · 74.5 KB
/
Copy pathfreespace.sh
File metadata and controls
executable file
·1712 lines (1567 loc) · 74.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
#
# Frees disk space.
#
# Usage: freespace.sh [-n] [-f]
#
# Modes:
# (default) Cheap to delete, cheap to recover (safe for daily use):
# - Build caches (every primary checkout + linked worktrees): .swc,
# storybook-static, .next, .turbo, __pycache__, .mypy_cache,
# .pytest_cache, .ruff_cache
# - node_modules in secondary worktrees (non-symlinked)
# - App caches: ~/Library/Caches/{Xcode,VSCode,Cursor,Chrome,Chrome Beta,
# Arc,Firefox,Brave,Edge,Opera,OpenAI Atlas,ChatGPT,Claude Desktop,
# Granola+Loom updaters,Zoom,JetBrains,pip,virtualenv,Homebrew,go-build,
# gopls,pnpm,Yarn,electron,Playwright,bazelisk,colima,mise,helm,...}
# - Loose ~/Library/Caches files over 100 MB untouched for 180 days
# (not com.apple.*), e.g. a requests-cache DB from a one-off script
# - Application Support/Caches/*-updater (Loom, etc.) + Edge updater
# - Cursor App Support (Cache, CachedData, logs, Partitions, WebStorage,
# GPUCache, CachedProfilesData) — workspaceStorage + History are -f only
# since they hold per-workspace UI state and Local-History recovery
# - VSCode App Support safe caches (Cache, CachedData, CachedExtensionVSIXs,
# logs, Crashpad, WebStorage, GPUCache)
# - Chromium safe caches for Chrome + Chrome Beta (OptGuideOnDeviceModel,
# extensions_crx_cache, Snapshots, optimization_guide_model_store,
# Crashpad, component_crx_cache, GraphiteDawnCache, GrShaderCache,
# ShaderCache)
# - Electron app caches (Cache, Code Cache, GPUCache, Service Worker
# cache, Crashpad, logs) for Slack (incl. sandbox container), Claude,
# Claude (3P), Granola, Loom, Highlight, OpenAI Atlas, ChatGPT,
# Cluely, Slapdash, Dropbox Dash, Mighty, Microsoft Edge, Brave
# - Windsurf App Support safe caches (Cache, CachedData, logs, GPUCache, etc.)
# - Project dev caches: PROJECT_CACHE_DIRS, relative to each primary
# checkout (e.g. a local search index that repopulates on restart)
# - Service logs: truncate *.log files over 100 MB under
# LOG_TRUNCATE_DIRS (truncation keeps the inode valid for running
# services)
# - gcloud CLI logs (~/.config/gcloud/logs)
# - System: ~/.Trash, ~/.cache/*, and /tmp + $TMPDIR entries untouched
# for 3 days (keeps sockets, com.apple.*, and paths a running
# process names or holds open)
# - ~/Library/Logs/* (third-party only: Webex, Spark, Zoom, Loom,
# Claude, CoreSimulator, Glean, Docker; preserves Apple subsystems)
# - Toolchains: mise prune (versions no tracked config uses) and
# versioned rustup toolchains that are not the default, active in
# a checkout, or installed by mise
# - Quick restore (~30s): brew cleanup, ~/.npm/_cacache, idle
# ~/.npm/_npx entries, ~/.yarn/berry/cache (kept when a checkout
# uses Yarn Plug'n'Play)
# - Misc: uv cache, bazel java logs, git temp packs
# - Git: worktree prune, remove prunable worktrees (refuses if dirty),
# git gc (default prune window — keeps reflog recovery for ~2 weeks)
# - All linked-worktree Bazel output bases (preserves every repository's
# main output base and the shared disk cache)
# - Bazel output bases left by an interrupted
# `bazel clean --expunge_async` (<name>_tmp_<pid>_<uuid>)
# - Bazel's default repository cache (<output_user_root>/cache/repos)
# once ~/.bazelrc sends every command to a shared one
# (`common --repository_cache=...`)
#
# -f Deep clean — expensive to recover:
# - Docker: images, containers, volumes (docker system prune -a)
# - Colima: fstrim each running profile after the Docker prune so
# the sparse VM disk shrinks on the host (keeps the VM and its
# settings; stopped profiles are reported, not touched)
# - iOS Simulator: ~/Library/Developer/CoreSimulator (user)
# - iOS Simulator runtimes not booted for 365 days (read from
# CoreSimulator's images.plist, deleted with `xcrun simctl
# runtime delete`; never-booted runtimes are kept)
# - System CoreSimulator Caches flagged as a sudo follow-up target
# if root-owned
# - Android emulators (AVDs) with no file modified for 365 days
# - Claude Desktop + Claude (3P) vm_bundles (regenerate on next
# code-execution session)
# - pre-commit hook envs (~/.cache/pre-commit; auto-recreate next commit)
# - Cursor/VSCode workspaceStorage + History (per-workspace tabs/state +
# Local History recovery for unversioned edits — opt-in only)
# - Primary-checkout node_modules and virtual environments are
# PRESERVED (bounded size, slow to reinstall); linked-worktree
# node_modules are handled by the default cleanup
# - Gradle cache, Maven cache
# - ALL of ~/.cache/bazel: every primary checkout's output base, the
# shared disk cache, and repository_cache. The next build is a
# cold rebuild and external deps are re-downloaded.
# - Legacy Bazel root contents (/private/var/tmp/_bazel_$USER)
# - Go module cache (go clean -modcache, slow to re-download)
# - pnpm store (~/Library/pnpm/store)
# - git gc --aggressive --prune=now (thorough repack, slow,
# drops dangling commits — reflog recovery is lost for pruned refs)
#
# Best-effort cleanup: keep going past per-op failures (missing dirs, perms,
# stale paths). Each safe_rm/safe_rm_pattern handles its own errors. Switching
# to `set -e` would abort the whole run on any single rm failure, which is the
# opposite of what we want for a disk-recovery script.
set +e
# Configuration — override via environment
MAIN_WORKSPACE="${FREESPACE_MAIN_WORKSPACE:-}"
BAZEL_ROOT="${BAZEL_ROOT:-/private/var/tmp/_bazel_$USER}"
WORKTREE_PARENT="${FREESPACE_WORKTREE_PARENT:-$HOME/workspace}"
# Project-specific caches, relative to each primary checkout (space-separated).
# Example: PROJECT_CACHE_DIRS=".opensearch python/venv_backup"
PROJECT_CACHE_DIRS="${PROJECT_CACHE_DIRS:-}"
# Directories whose *.log files over LOG_TRUNCATE_THRESHOLD_KB (default 100 MB)
# are truncated in place rather than deleted, so a running process keeps writing.
# Example: LOG_TRUNCATE_DIRS="$HOME/.devdock"
LOG_TRUNCATE_DIRS="${LOG_TRUNCATE_DIRS:-}"
LOG_TRUNCATE_THRESHOLD_KB="${LOG_TRUNCATE_THRESHOLD_KB:-102400}"
AVD_HOME="${ANDROID_AVD_HOME:-${ANDROID_USER_HOME:-$HOME/.android}/avd}"
TEMP_MIN_AGE_DAYS=3 # /tmp, $TMPDIR, npx entries untouched this long are stale
STALE_CACHE_FILE_DAYS=180 # loose ~/Library/Caches files untouched this long
SIM_UNUSED_DAYS=365 # -f: iOS runtimes / Android emulators unused this long
# `bazel clean --expunge_async` renames <output_base> to <name>_tmp_<pid>_<uuid>.
EXPUNGE_LEFTOVER_RE='_tmp_([0-9]+)_[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$'
# Parse arguments
dry_run=false
full=false
while [[ $# -gt 0 ]]; do
case "$1" in
-n | --dry-run) dry_run=true ;;
-f | --full) full=true ;;
-nf | -fn)
dry_run=true
full=true
;;
-h | --help)
cat <<'EOF'
Usage: freespace.sh [-n] [-f]
Modes:
(default) Cheap to delete, cheap to recover (safe for daily use):
- Build caches: .swc, storybook-static, .next, .turbo, __pycache__, etc
- App caches: ~/Library/Caches/{Xcode,VSCode,Cursor,Chrome,Chrome Beta,
Firefox,Brave,Edge,Opera,Atlas,ChatGPT,Claude,JetBrains,...}
- Loose ~/Library/Caches files over 100M untouched for 180 days
- Updater caches: Granola/Loom/Edge updaters
- Cursor/VSCode App Support pure caches (Cache, CachedData, logs, etc)
— workspaceStorage + History are -f only (recovery surfaces)
- Chromium safe caches (Chrome+Beta)
- Electron app caches: Slack (incl sandbox), Claude, Claude (3P),
Granola, Loom, Highlight, Atlas, ChatGPT, Cluely, Slapdash,
Dropbox Dash, Mighty, Edge, Brave
- Windsurf App Support safe caches
- PROJECT_CACHE_DIRS, gcloud logs, ~/.Trash, ~/.cache/*
(preserves pre-commit)
- /tmp and $TMPDIR entries untouched for 3 days and not in use
- ~/Library/Logs (3rd-party app logs only; preserves Apple)
- Bazel java logs, git temp packs
- Toolchains: mise prune, unused versioned rustup toolchains
- Quick restore (~30s): brew cleanup, ~/.npm/_cacache, idle
~/.npm/_npx entries, ~/.yarn/berry/cache (unless Plug'n'Play)
- Git: worktree prune, remove prunable worktrees (refuses if dirty),
git gc (default prune window — keeps reflog recovery for ~2 weeks)
- All linked-worktree Bazel output bases and node_modules (preserves
every repository's main worktree, its output base, and shared cache)
- Leftovers of an interrupted `bazel clean --expunge_async`
- Bazel's default repository cache, once ~/.bazelrc points every
command at a shared one (common --repository_cache)
- Repo-scoped cleanup covers every primary checkout found under
~/workspace, whatever directory freespace is invoked from
-f Deep clean — expensive to recover:
- Docker: images, containers, volumes (docker system prune -a)
- Colima: fstrim running VMs so the host disk image shrinks
- iOS Simulator devices, and runtimes not booted for 365 days
- Android emulators with no file modified for 365 days
- Claude + Claude (3P) vm_bundles, ~/.cache/pre-commit
- Cursor/VSCode workspaceStorage + History (per-workspace state +
Local History — recovery surfaces, not pure caches)
- System CoreSimulator Caches (flagged for sudo)
- Keeps primary node_modules + venvs; Gradle, Maven, pnpm store
- ALL of ~/.cache/bazel (every primary output base, the disk cache
and repository_cache), legacy Bazel root, go modcache
- git gc --aggressive
-n Dry run — preview everything (default + deep) without deleting
EOF
exit 0
;;
*)
echo "Unknown option: $1" >&2
exit 1
;;
esac
shift
done
# Dry-run always previews everything
if $dry_run; then
full=true
fi
# Stats
freed_total=0
items_deleted=0
items_skipped=0
items_failed=0
# Colors and symbols
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
DIM='\033[2m'
RESET='\033[0m'
DISK_TOTAL_KB=$(df -k ~ | tail -1 | awk '{print $2}')
get_size() {
local path="$1"
if [[ -e "$path" ]]; then
if command -v dust >/dev/null 2>&1 && command -v jq >/dev/null 2>&1; then
dust -j -P -d 0 -o k "$path" 2>/dev/null | jq .size | sed -E 's/"|K//g'
else
du -sk "$path" 2>/dev/null | cut -f1
fi
else
echo 0
fi
}
format_size() {
local kb=$1
local size_str
if [[ $kb -ge 1048576 ]]; then
size_str=$(printf "%.1fG" "$(echo "scale=1; $kb / 1048576" | bc)")
elif [[ $kb -ge 1024 ]]; then
size_str="$((kb / 1024))M"
elif [[ $kb -gt 0 ]]; then
size_str="${kb}K"
else
echo "0"
return
fi
local pct
pct=$(awk "BEGIN {printf \"%.1f\", $kb * 100 / $DISK_TOTAL_KB}")
echo "$size_str ($pct%)"
}
# Progress spinner for long operations
spin() {
local pid=$1
local msg="${2:-}"
local delay=0.1
local spinstr='⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏'
local i=0
while ps -p "$pid" >/dev/null 2>&1; do
printf "\r ${DIM}%s %s${RESET} " "${spinstr:$i:1}" "$msg"
i=$(((i + 1) % ${#spinstr}))
sleep $delay
done
# Clear the spinner line
printf "\r%*s\r" $((${#msg} + 10)) ""
}
rm_or_rmz() {
if command -v rmz >/dev/null 2>&1; then
rmz "$@"
else
rm -rf "$@"
fi
}
safe_rm() {
local path="$1"
local desc="$2"
local size_kb
size_kb=$(get_size "$path")
if [[ $size_kb -eq 0 ]]; then
echo -e " ${DIM}· $desc (empty)${RESET}"
((items_skipped++))
return
fi
local size_str
size_str=$(format_size "$size_kb")
if $dry_run; then
echo -e " ${BLUE}○${RESET} $desc ${YELLOW}$size_str${RESET}"
freed_total=$((freed_total + size_kb))
((items_deleted++))
else
# Try simple rm/rmz first
if rm_or_rmz "$path" 2>/dev/null; then
echo -e " ${GREEN}✓${RESET} $desc ${GREEN}$size_str${RESET}"
freed_total=$((freed_total + size_kb))
((items_deleted++))
else
# Bazel sets dirs read-only; fix permissions then retry
chmod -R u+w "$path" 2>/dev/null
chflags -R nouchg "$path" 2>/dev/null
if rm_or_rmz "$path" 2>/dev/null; then
echo -e " ${GREEN}✓${RESET} $desc ${GREEN}$size_str${RESET} (fixed perms)"
freed_total=$((freed_total + size_kb))
((items_deleted++))
else
echo -e " ${RED}✗${RESET} $desc ${RED}$size_str${RESET} (need sudo)"
((items_failed++))
fi
fi
fi
}
# Truncates a file to zero bytes without deleting it. Safe to use on files that
# may be held open by running processes (truncation preserves the inode, so the
# writing process keeps its file descriptor and continues writing; the freed
# space is reclaimed immediately by the OS).
safe_truncate() {
local path="$1"
local desc="$2"
local size_kb
size_kb=$(get_size "$path")
if [[ $size_kb -eq 0 ]]; then
echo -e " ${DIM}· $desc (empty)${RESET}"
((items_skipped++))
return
fi
local size_str
size_str=$(format_size "$size_kb")
if $dry_run; then
echo -e " ${BLUE}○${RESET} $desc ${YELLOW}$size_str${RESET}"
freed_total=$((freed_total + size_kb))
((items_deleted++))
else
# Wrap the redirect in a brace group so the outer `2>/dev/null` also
# silences bash's own "cannot open" message (bash emits that to stderr
# before any redirection placed inline after `>"$path"` takes effect).
if { >"$path"; } 2>/dev/null; then
echo -e " ${GREEN}✓${RESET} $desc ${GREEN}$size_str${RESET} (truncated)"
freed_total=$((freed_total + size_kb))
((items_deleted++))
else
echo -e " ${RED}✗${RESET} $desc ${RED}$size_str${RESET} (permission denied)"
((items_failed++))
fi
fi
}
# Cleans the Chromium-style cache subdirs that virtually every Electron app
# drops under Application Support/<app>/. Excludes anything that holds user
# state (Local Storage, IndexedDB, Cookies, Preferences, Partitions, Sessions,
# Service Worker registration data — Service Worker/CacheStorage on the other
# hand is just HTTP cache so it's listed below).
clean_electron_app() {
local label="$1"
local base="$2"
[[ -d "$base" ]] || return
# Subdirs that browsers/Electron treat as expendable cache. Order matters
# only for output. Each is silently skipped when absent.
local subs=(
"Cache"
"Code Cache"
"GPUCache"
"DawnGraphiteCache"
"DawnWebGPUCache"
"GraphiteDawnCache"
"GrShaderCache"
"ShaderCache"
"Shared Dictionary"
"Crashpad"
"Service Worker/CacheStorage"
"Service Worker/ScriptCache"
"logs"
)
local total_kb=0
local sub size_kb
for sub in "${subs[@]}"; do
[[ -d "$base/$sub" ]] || continue
size_kb=$(get_size "$base/$sub")
total_kb=$((total_kb + size_kb))
if ! $dry_run; then
rm_or_rmz "$base/$sub" 2>/dev/null
fi
done
if [[ $total_kb -eq 0 ]]; then
echo -e " ${DIM}· $label (empty)${RESET}"
((items_skipped++))
else
local size_str
size_str=$(format_size "$total_kb")
if $dry_run; then
echo -e " ${BLUE}○${RESET} $label ${YELLOW}$size_str${RESET}"
else
echo -e " ${GREEN}✓${RESET} $label ${GREEN}$size_str${RESET}"
fi
freed_total=$((freed_total + total_kb))
((items_deleted++))
fi
}
# Chromium-profile safe caches: bigger model/snapshot dirs that aren't part of
# the Electron list above. Used for both Chrome and Chrome Beta.
clean_chromium_profile() {
local label="$1"
local base="$2"
[[ -d "$base" ]] || {
echo -e " ${DIM}· $label (not installed)${RESET}"
((items_skipped++))
return
}
safe_rm "$base/OptGuideOnDeviceModel" "$label ML model"
safe_rm "$base/optimization_guide_model_store" "$label optimization models"
safe_rm "$base/Snapshots" "$label Snapshots"
safe_rm "$base/extensions_crx_cache" "$label extensions cache"
safe_rm "$base/component_crx_cache" "$label component cache"
safe_rm "$base/Crashpad" "$label Crashpad"
safe_rm "$base/GraphiteDawnCache" "$label GraphiteDawnCache"
safe_rm "$base/GrShaderCache" "$label GrShaderCache"
safe_rm "$base/ShaderCache" "$label ShaderCache"
}
safe_rm_pattern() {
local base="$1"
local pattern="$2"
local desc="$3"
if [[ ! -d "$base" ]]; then
return
fi
local total_kb=0
local count=0
# -H: follow a symlinked base (e.g. /tmp -> /private/tmp); plain find lists
# nothing there. -prune: a matching directory is counted and removed as a
# whole, so never descend into it and count its contents a second time.
while IFS= read -r -d '' file; do
local size_kb
size_kb=$(get_size "$file")
total_kb=$((total_kb + size_kb))
count=$((count + 1))
if ! $dry_run; then
rm_or_rmz "$file" 2>/dev/null
fi
done < <(find -H "$base" -mindepth 1 -name "$pattern" -prune -print0 2>/dev/null)
if [[ $count -gt 0 ]]; then
local size_str
size_str=$(format_size "$total_kb")
if $dry_run; then
echo -e " ${BLUE}○${RESET} $desc ${DIM}($count)${RESET} ${YELLOW}$size_str${RESET}"
else
echo -e " ${GREEN}✓${RESET} $desc ${DIM}($count)${RESET} ${GREEN}$size_str${RESET}"
fi
freed_total=$((freed_total + total_kb))
((items_deleted++))
else
echo -e " ${DIM}· $desc (none)${RESET}"
((items_skipped++))
fi
}
# Deletes top-level entries of a scratch directory (/tmp, $TMPDIR, npx cache)
# that look abandoned. An entry is kept when anything inside it changed in the
# last <days> days, when it holds a socket or FIFO (agents, IPC listeners), when
# a running process names its path or holds a file in it open, or when its name
# matches one of the extra glob patterns (system-owned entries). Entries owned
# by other users are skipped.
clean_stale_entries() {
local base="$1"
local desc="$2"
local days="$3"
shift 3
local physical
physical=$(cd "$base" 2>/dev/null && pwd -P) || return
base="${base%/}"
local procs open entry name keep_glob size_kb short
local total_kb=0
local count=0
procs=$(ps -axww -o command= 2>/dev/null)
# Top-level names a process holds open (files, cwd, mapped libraries). lsof
# prints resolved paths, so match against the physical base.
open=$(lsof -nP -Fn 2>/dev/null | awk -v p="n$physical/" \
'index($0, p) == 1 { s = substr($0, length(p) + 1); sub("/.*", "", s); print s }' | sort -u)
# /tmp and /var are symlinks into /private; processes may use either form.
short="${physical#/private}"
while IFS= read -r -d '' entry; do
name="${entry#"$physical"/}"
for keep_glob in "$@"; do
# shellcheck disable=SC2053 # intentional glob match
[[ "$name" == $keep_glob ]] && continue 2
done
[[ "$procs" == *"$physical/$name"* || "$procs" == *"$short/$name"* || "$procs" == *"$base/$name"* ]] && continue
[[ $'\n'"$open"$'\n' == *$'\n'"$name"$'\n'* ]] && continue
[[ -n $(find "$entry" \( -mmin "-$((days * 1440))" -o -type s -o -type p \) -print -quit 2>/dev/null) ]] && continue
size_kb=$(get_size "$entry")
if ! $dry_run; then
rm_or_rmz "$entry" 2>/dev/null
[[ -e "$entry" || -L "$entry" ]] && continue
fi
total_kb=$((total_kb + size_kb))
count=$((count + 1))
done < <(find "$physical" -mindepth 1 -maxdepth 1 -user "$USER" -print0 2>/dev/null)
if [[ $count -gt 0 ]]; then
local size_str
size_str=$(format_size "$total_kb")
if $dry_run; then
echo -e " ${BLUE}○${RESET} $desc ${DIM}($count)${RESET} ${YELLOW}$size_str${RESET}"
else
echo -e " ${GREEN}✓${RESET} $desc ${DIM}($count)${RESET} ${GREEN}$size_str${RESET}"
fi
freed_total=$((freed_total + total_kb))
((items_deleted++))
else
echo -e " ${DIM}· $desc (none untouched for ${days}d)${RESET}"
((items_skipped++))
fi
}
# Prints the last value a bazelrc gives `<command> --<flag>` (last one wins, as
# in Bazel), with a leading ~ expanded. Config-specific lines (build:macos) are
# ignored. Prints nothing when the flag is not set.
bazelrc_flag_value() {
local rc="$1"
local command="$2"
local flag="$3"
local value
[[ -f "$rc" ]] || return
value=$(sed -nE "s/^[[:space:]]*${command}[[:space:]](.*[[:space:]])?--${flag}[=[:space:]]\"?([^\"[:space:]]+).*/\2/p" "$rc" | tail -1)
[[ -n "$value" ]] && printf '%s\n' "${value/#\~/$HOME}"
}
# Physical path when the directory exists, else the path without a trailing /.
physical_path() {
(cd "$1" 2>/dev/null && pwd -P) || printf '%s\n' "${1%/}"
}
# Prints the version part of a versioned rustup toolchain name
# (1.94.0-aarch64-apple-darwin -> 1.94.0); nothing for stable/nightly/custom.
rust_version() {
[[ "$1" =~ ^([0-9]+\.[0-9]+(\.[0-9]+)?)(-|$) ]] && printf '%s\n' "${BASH_REMATCH[1]}"
}
get_repository_roots() {
local dir current_repo
current_repo=$(git rev-parse --show-toplevel 2>/dev/null) || true
[[ -n "$current_repo" && -e "$current_repo/.git" ]] && printf '%s\n' "$current_repo"
for dir in "$WORKTREE_PARENT"/*/; do
[[ -d "$dir" ]] || continue
[[ -e "${dir}.git" ]] && printf '%s\n' "${dir%/}"
done
}
get_main_worktree_for_repo() {
git -C "$1" worktree list --porcelain 2>/dev/null \
| awk '/^worktree / { print substr($0, 10); exit }'
}
get_primary_worktrees() {
local repo
while IFS= read -r repo; do
get_main_worktree_for_repo "$repo"
done < <(get_repository_roots) | sort -u
}
get_worktrees() {
local repo
while IFS= read -r repo; do
git -C "$repo" worktree list --porcelain 2>/dev/null \
| awk 'BEGIN { seen = 0 } /^worktree / { if (seen++ > 0) print substr($0, 10) "/" }'
done < <(get_repository_roots) | sort -u
}
get_script_main_worktree() {
local current_repo main_worktree
current_repo=$(git rev-parse --show-toplevel 2>/dev/null) || true
if [[ -n "$current_repo" ]]; then
main_worktree=$(get_main_worktree_for_repo "$current_repo")
[[ -n "$main_worktree" ]] && printf '%s\n' "$main_worktree"
fi
}
display_worktree_path() {
local path="${1%/}"
if [[ "$path" == "$HOME/"* ]]; then
printf '~/%s\n' "${path#"$HOME/"}"
else
printf '%s\n' "$path"
fi
}
is_primary_worktree() {
local path primary
[[ -d "$1" ]] || return 1
path=$(cd "$1" 2>/dev/null && pwd -P) || return 1
while IFS= read -r primary; do
[[ -n "$primary" ]] || continue
primary=$(cd "$primary" 2>/dev/null && pwd -P) || continue
[[ "$path" == "$primary" ]] && return 0
done <<<"$PRIMARY_WORKTREES"
return 1
}
# Resolve one repository's bazel output_base. Symlink targets are resolved
# physically, so a relative link (e.g. ../../x/.bazel/out in a sibling worktree)
# lands on the real output base instead of a path assembled from the link text.
get_repo_output_base() {
local repo="$1"
[[ -n "$repo" && -d "$repo" ]] || return
# Try convenience symlinks before invoking bazel (which is slow and can fail).
# .bazel/out -> <output_base>/execroot/_main/bazel-out (up 3)
# .bazel/bin -> <output_base>/execroot/_main/bazel-out/<cfg>/bin (up 5)
# bazel-out -> <output_base>/execroot/_main/bazel-out (up 3)
local link resolved ob levels i
for entry in ".bazel/out:3" ".bazel/bin:5" "bazel-out:3"; do
link="${entry%:*}"
levels="${entry##*:}"
[[ -L "$repo/$link" ]] || continue
resolved=$(cd "$repo/$link" 2>/dev/null && pwd -P) || continue
[[ -n "$resolved" ]] || continue
ob="$resolved"
for ((i = 0; i < levels; i++)); do
ob=$(dirname "$ob")
done
[[ -d "$ob" ]] && {
echo "$ob"
return
}
done
# Fall back to asking bazel, but only for real bazel workspaces: otherwise
# this would start a bazel server once per non-bazel repository.
[[ -e "$repo/WORKSPACE" || -e "$repo/WORKSPACE.bazel" || -e "$repo/MODULE.bazel" ]] || return
(cd "$repo" && bazel info output_base 2>/dev/null) || true
}
# True when the path is the output base of some primary checkout. Those are the
# build state actually in use, so default mode preserves them.
is_primary_output_base() {
local candidate="$1" ob
[[ -n "$candidate" ]] || return 1
while IFS= read -r ob; do
[[ -n "$ob" ]] || continue
[[ "$candidate" == "$ob" ]] && return 0
done <<<"$PRIMARY_OUTPUT_BASES"
return 1
}
# Repo-scoped cleanup runs over every primary checkout discovered under
# WORKTREE_PARENT (plus the invoking repository), so the result does not depend
# on which directory freespace was started from. FREESPACE_MAIN_WORKSPACE
# narrows the run to a single repository.
if [[ -n "$MAIN_WORKSPACE" ]]; then
PRIMARY_WORKTREES=$(get_main_worktree_for_repo "$MAIN_WORKSPACE")
[[ -n "$PRIMARY_WORKTREES" ]] || PRIMARY_WORKTREES="$MAIN_WORKSPACE"
else
PRIMARY_WORKTREES=$(get_primary_worktrees)
# Put the invoking repository first so its git gc runs before the others.
script_primary=$(get_script_main_worktree)
if [[ -n "$script_primary" ]]; then
PRIMARY_WORKTREES=$(printf '%s\n%s\n' "$script_primary" "$PRIMARY_WORKTREES" \
| awk 'NF && !seen[$0]++')
fi
fi
if [[ -z "$PRIMARY_WORKTREES" ]]; then
echo "freespace: no git repository found in $WORKTREE_PARENT or the current directory" >&2
echo "freespace: cd into a repository, or set FREESPACE_WORKTREE_PARENT /" >&2
echo "freespace: FREESPACE_MAIN_WORKSPACE to point at one explicitly." >&2
exit 1
fi
primary_count=$(printf '%s\n' "$PRIMARY_WORKTREES" | grep -c '[^[:space:]]')
# Collect each primary's output base once; reused for preservation checks and
# for discovering which bazel roots to scan.
PRIMARY_OUTPUT_BASES=""
while IFS= read -r primary_repo; do
[[ -n "$primary_repo" ]] || continue
primary_ob=$(get_repo_output_base "$primary_repo")
[[ -n "$primary_ob" && -d "$primary_ob" ]] || continue
PRIMARY_OUTPUT_BASES="${PRIMARY_OUTPUT_BASES}${primary_ob}"$'\n'
done <<<"$PRIMARY_WORKTREES"
# Count linked worktrees
worktree_count=$(get_worktrees | wc -l | tr -d ' ')
# Header
start_time=$SECONDS
echo ""
if $dry_run && $full; then
echo -e "🔍 ${YELLOW}DRY RUN (full)${RESET} - showing what would be deleted"
elif $dry_run; then
echo -e "🔍 ${YELLOW}DRY RUN${RESET} - showing what would be deleted"
elif $full; then
echo -e "🧹 ${GREEN}Deep cleaning disk space...${RESET}"
else
echo -e "🧹 ${GREEN}Cleaning disk space...${RESET}"
fi
echo ""
# Show disk before
disk_info=$(df -h ~ | tail -1)
avail_before=$(echo "$disk_info" | awk '{print $4}')
pct_before=$(echo "$disk_info" | awk '{gsub(/%/,"",$5); print $5}')
echo -e "💾 Disk: ${YELLOW}$pct_before%${RESET} full (${avail_before} available)"
echo ""
# ═══════════════════════════════════════════════════════════════════
echo -e "━━━ ${BLUE}Bazel${RESET} ${DIM}(secondary worktree builds first, java logs after)${RESET}"
# Per-worktree bazel output bases (~/.cache/bazel/_userroot/<hash>/ when
# ~/.bazelrc sets --output_user_root, /private/var/tmp/_bazel_$USER/<hash>/ on
# default Bazel). Each one is identified
# by DO_NOT_BUILD_HERE, which records the workspace path. Preserve the main
# workspace's output base and the shared cache/ and install/ directories.
# Bazel output bases re-link from the preserved disk cache, so recovery is one
# extra incremental build rather than a from-scratch rebuild.
if ! $dry_run; then
echo -e " ${DIM}shutting down bazel...${RESET}"
pkill -9 -f "bazel.*_bazel_$USER" 2>/dev/null || true
while IFS= read -r repo; do
[[ -n "$repo" && -x "$repo/tools/mybazel.sh" ]] || continue
"$repo/tools/mybazel.sh" shutdown 2>/dev/null </dev/null || true
done <<<"$PRIMARY_WORKTREES"
sleep 1
fi
# Scan the output_user_root of every primary checkout (repos can use different
# bazel layouts) plus the legacy root, deduped.
bazel_roots=()
legacy_is_separate=true
while IFS= read -r ob_entry; do
[[ -n "$ob_entry" ]] || continue
ob_root=$(dirname "$ob_entry")
[[ "$ob_root" == "$BAZEL_ROOT" ]] && legacy_is_separate=false
root_known=false
for known_root in ${bazel_roots[@]+"${bazel_roots[@]}"}; do
[[ "$known_root" == "$ob_root" ]] && {
root_known=true
break
}
done
$root_known || bazel_roots+=("$ob_root")
done <<<"$PRIMARY_OUTPUT_BASES"
$legacy_is_separate && bazel_roots+=("$BAZEL_ROOT")
ob_count=0
ob_freed=0
for bazel_root in "${bazel_roots[@]}"; do
[[ -d "$bazel_root" ]] || continue
for ob in "$bazel_root"/*/; do
ob="${ob%/}"
is_primary_output_base "$ob" && continue
ws=$(cat "$ob/DO_NOT_BUILD_HERE" 2>/dev/null)
if [[ "$(basename "$ob")" =~ $EXPUNGE_LEFTOVER_RE ]]; then
# `bazel clean --expunge_async` renames the output base to this name and
# deletes it in the background. When that delete never finishes (sleep,
# reboot, crash), the copy stays forever. DO_NOT_BUILD_HERE still names
# the primary checkout (or is already gone), so match on the name and
# skip only while the Bazel server or the background rm is alive.
expunge_pid="${BASH_REMATCH[1]}"
ps -p "$expunge_pid" >/dev/null 2>&1 && continue
pgrep -f "$ob" >/dev/null 2>&1 && continue
wsname=$(basename "${ws:-$ob}")
short="pid $expunge_pid"
reason="interrupted clean"
else
# Only real output bases have DO_NOT_BUILD_HERE; skips cache/, install/, etc.
[[ -f "$ob/DO_NOT_BUILD_HERE" ]] || continue
is_primary_worktree "$ws" && continue
wsname=$(basename "$ws")
short=$(basename "$ob" | cut -c1-8)
reason="worktree"
[[ ! -d "$ws" ]] && reason="orphan"
fi
size_kb=$(get_size "$ob")
size_str=$(format_size "$size_kb")
if $dry_run; then
echo -e " ${BLUE}○${RESET} $wsname ${DIM}($short, $reason)${RESET} ${YELLOW}$size_str${RESET}"
ob_freed=$((ob_freed + size_kb))
((ob_count++))
else
chmod -R u+w "$ob" 2>/dev/null
chflags -R nouchg "$ob" 2>/dev/null
if rm_or_rmz "$ob" 2>/dev/null; then
echo -e " ${GREEN}✓${RESET} $wsname ${DIM}($short, $reason)${RESET} ${GREEN}$size_str${RESET}"
ob_freed=$((ob_freed + size_kb))
((ob_count++))
else
echo -e " ${RED}✗${RESET} $wsname ${DIM}($short, $reason)${RESET} ${RED}$size_str${RESET} (need sudo)"
((items_failed++))
fi
fi
done
safe_rm_pattern "$bazel_root" "java.log.*" "java logs"
done
if $full && $legacy_is_separate && [[ -d "$BAZEL_ROOT" ]]; then
# The legacy root can contain shared cache/install entries without
# DO_NOT_BUILD_HERE. Keep this broad sweep behind -f.
for legacy_entry in "$BAZEL_ROOT"/*/; do
legacy_entry="${legacy_entry%/}"
is_primary_output_base "$legacy_entry" && continue
[[ -e "$legacy_entry/DO_NOT_BUILD_HERE" ]] && continue
safe_rm "$legacy_entry" "legacy Bazel $(basename "$legacy_entry")"
done
fi
if [[ $ob_count -gt 0 ]]; then
freed_total=$((freed_total + ob_freed))
((items_deleted += ob_count))
echo -e " ${DIM}── $ob_count output base(s), $(format_size "$ob_freed") total${RESET}"
else
echo -e " ${DIM}· no secondary-worktree output bases${RESET}"
((items_skipped++))
fi
# Bazel's default repository cache is <output_user_root>/cache/repos. Once
# ~/.bazelrc sends every command to a shared cache (`common --repository_cache`),
# nothing uses the default one. Output
# bases may still link external repos into its contents/; Bazel sees the missing
# target and fetches those repos again (into the shared cache) on next use.
# Without that global line, worktrees (no .bazelrc.user) and commands that skip
# `build` options (query, mod) still use the default cache, so keep it.
bazel_user_root=$(bazelrc_flag_value "$HOME/.bazelrc" startup output_user_root)
default_repo_cache="${bazel_user_root:-$BAZEL_ROOT}/cache/repos"
shared_repo_cache=$(bazelrc_flag_value "$HOME/.bazelrc" common repository_cache)
if [[ -d "$default_repo_cache" && -n "$shared_repo_cache" && "$shared_repo_cache" != *%* ]]; then
default_repo_cache=$(physical_path "$default_repo_cache")
shared_repo_cache=$(physical_path "$shared_repo_cache")
if [[ "$shared_repo_cache/" != "$default_repo_cache/"* ]]; then
safe_rm "$default_repo_cache" "duplicate default repository cache"
fi
elif [[ -d "$default_repo_cache" ]]; then
while IFS= read -r repo; do
[[ -n "$(bazelrc_flag_value "$repo/.bazelrc.user" build repository_cache)" ]] || continue
echo -e " ${YELLOW}!${RESET} default repository cache ${YELLOW}$(format_size "$(get_size "$default_repo_cache")")${RESET} ${DIM}(kept: worktrees still use it; set a shared `common --repository_cache` in ~/.bazelrc)${RESET}"
((items_skipped++))
break
done <<<"$PRIMARY_WORKTREES"
fi
# ═══════════════════════════════════════════════════════════════════
echo -e "━━━ ${BLUE}Build Caches${RESET} ${DIM}(auto-regenerate)${RESET}"
# Repo-scoped build caches, for every primary checkout.
while IFS= read -r repo; do
[[ -n "$repo" && -d "$repo" ]] || continue
tag=""
[[ $primary_count -gt 1 ]] && tag=" ($(basename "$repo"))"
safe_rm_pattern "$repo/.git/objects/pack" "tmp_pack_*" "git temp packs$tag"
# Stale .git/index.stash.* — leftovers from interrupted stash/rebase/autostash.
# Top-level only (no recursion); harmless to delete.
stash_count=0
stash_freed=0
for f in "$repo"/.git/index.stash.*; do
[[ -f "$f" ]] || continue
sz=$(get_size "$f")
stash_freed=$((stash_freed + sz))
((stash_count++))
$dry_run || rm_or_rmz "$f" 2>/dev/null
done
if [[ $stash_count -gt 0 ]]; then
sz_str=$(format_size "$stash_freed")
if $dry_run; then
echo -e " ${BLUE}○${RESET} stale .git/index.stash.*$tag ${DIM}($stash_count)${RESET} ${YELLOW}$sz_str${RESET}"
else
echo -e " ${GREEN}✓${RESET} stale .git/index.stash.*$tag ${DIM}($stash_count)${RESET} ${GREEN}$sz_str${RESET}"
fi
freed_total=$((freed_total + stash_freed))
((items_deleted++))
else
echo -e " ${DIM}· stale .git/index.stash.*$tag (none)${RESET}"
((items_skipped++))
fi
safe_rm "$repo/storybook-static" "storybook-static$tag"
safe_rm "$repo/.swc" ".swc$tag"
safe_rm "$repo/.mypy_cache" ".mypy_cache$tag"
safe_rm "$repo/.pytest_cache" ".pytest_cache$tag"
safe_rm "$repo/.ruff_cache" ".ruff_cache$tag"
safe_rm "$repo/.next" ".next$tag"
safe_rm "$repo/.turbo" ".turbo$tag"
# __pycache__ directories (skips node_modules, .git, and virtualenvs)
if [[ -d "$repo" ]]; then
pycache_size=0
pycache_count=0
while IFS= read -r -d '' dir; do
size=$(get_size "$dir")
pycache_size=$((pycache_size + size))
pycache_count=$((pycache_count + 1))
if ! $dry_run; then
rm_or_rmz "$dir" 2>/dev/null
fi
done < <(find "$repo" -type d \( -name node_modules -o -name .git -o -name .venv -o -name venv \) -prune -o -type d -name "__pycache__" -print0 2>/dev/null)
if [[ $pycache_count -gt 0 ]]; then
size_str=$(format_size "$pycache_size")
if $dry_run; then
echo -e " ${BLUE}○${RESET} __pycache__$tag ${DIM}($pycache_count dirs)${RESET} ${YELLOW}$size_str${RESET}"
else
echo -e " ${GREEN}✓${RESET} __pycache__$tag ${DIM}($pycache_count dirs)${RESET} ${GREEN}$size_str${RESET}"
fi
freed_total=$((freed_total + pycache_size))
((items_deleted++))
else
echo -e " ${DIM}· __pycache__$tag (none)${RESET}"
((items_skipped++))
fi
fi
done <<<"$PRIMARY_WORKTREES"
# ═══════════════════════════════════════════════════════════════════
echo ""
echo -e "━━━ ${BLUE}App Caches${RESET} ${DIM}(~/Library/Caches)${RESET}"
safe_rm "$HOME/Library/Caches/com.apple.dt.Xcode" "Xcode"
safe_rm "$HOME/Library/Caches/com.microsoft.VSCode" "VSCode"
safe_rm "$HOME/Library/Caches/com.todesktop.230313mzl4w4u92" "Cursor"
safe_rm "$HOME/Library/Caches/com.todesktop.230313mzl4w4u92.ShipIt" "Cursor ShipIt"
safe_rm "$HOME/Library/Caches/Google" "Google"
safe_rm "$HOME/Library/Caches/com.google.Chrome" "Chrome"
safe_rm "$HOME/Library/Caches/com.google.Chrome.beta" "Chrome Beta"
safe_rm "$HOME/Library/Caches/Arc" "Arc"
safe_rm "$HOME/Library/Caches/Firefox" "Firefox"
safe_rm "$HOME/Library/Caches/Mozilla" "Mozilla"
safe_rm "$HOME/Library/Caches/BraveSoftware" "Brave"
safe_rm "$HOME/Library/Caches/com.operasoftware.Opera" "Opera"
safe_rm "$HOME/Library/Caches/com.microsoft.edgemac" "Edge"
safe_rm "$HOME/Library/Caches/com.openai.atlas" "OpenAI Atlas"
safe_rm "$HOME/Library/Caches/com.openai.chat" "ChatGPT"
safe_rm "$HOME/Library/Caches/com.anthropic.claudefordesktop" "Claude Desktop"
safe_rm "$HOME/Library/Caches/com.anthropic.claudefordesktop.ShipIt" "Claude Desktop ShipIt"
safe_rm "$HOME/Library/Caches/@granolaelectron-updater" "Granola updater"
safe_rm "$HOME/Library/Caches/loom-updater" "Loom updater"
safe_rm "$HOME/Library/Caches/us.zoom.xos" "Zoom"
safe_rm "$HOME/Library/Caches/pip" "pip"
safe_rm "$HOME/Library/Caches/pip-tools" "pip-tools"
safe_rm "$HOME/Library/Caches/virtualenv" "virtualenv"
safe_rm "$HOME/Library/Caches/Homebrew" "Homebrew"
safe_rm "$HOME/Library/Caches/JetBrains" "JetBrains"
safe_rm "$HOME/Library/Caches/go-build" "go-build"
safe_rm "$HOME/Library/Caches/gopls" "gopls"
safe_rm "$HOME/Library/Caches/goimports" "goimports"
safe_rm "$HOME/Library/Caches/pnpm" "pnpm"
safe_rm "$HOME/Library/Caches/Yarn" "Yarn"
safe_rm "$HOME/Library/Caches/node-gyp" "node-gyp"
safe_rm "$HOME/Library/Caches/electron" "electron"
safe_rm "$HOME/Library/Caches/ms-playwright" "Playwright"
safe_rm "$HOME/Library/Caches/bazelisk" "bazelisk"
safe_rm "$HOME/Library/Caches/colima" "colima"
safe_rm "$HOME/Library/Caches/mise" "mise"
safe_rm "$HOME/Library/Caches/helm" "helm"
safe_rm "$HOME/Library/Caches/Coursier" "Coursier"
safe_rm "$HOME/Library/Caches/typescript" "typescript"
safe_rm "$HOME/Library/Caches/com.microsoft.VSCode.ShipIt" "VSCode ShipIt"
# Big loose files at the top of ~/Library/Caches that nothing has written for
# months, e.g. a requests-cache SQLite DB left by a one-off script. Apps must
# tolerate losing anything in Caches; Apple's own com.apple.* files are kept.
stale_cache_count=0
while IFS= read -r -d '' stale_cache; do
safe_rm "$stale_cache" "stale file: $(basename "$stale_cache")"
((stale_cache_count++))
done < <(find "$HOME/Library/Caches" -mindepth 1 -maxdepth 1 -type f -size +100M \
-mtime "+$STALE_CACHE_FILE_DAYS" ! -name 'com.apple.*' -print0 2>/dev/null)
if [[ $stale_cache_count -eq 0 ]]; then
echo -e " ${DIM}· stale files over 100M (none untouched for ${STALE_CACHE_FILE_DAYS}d)${RESET}"
((items_skipped++))
fi
# Updater download caches living under Application Support/Caches/. Stick to
# the *-updater / *Updater naming convention so we never silently nuke
# something a future macOS subsystem or buggy app drops here.
if [[ -d "$HOME/Library/Application Support/Caches" ]]; then
shopt -s nullglob
for upd in "$HOME/Library/Application Support/Caches"/*-updater \
"$HOME/Library/Application Support/Caches"/*Updater; do
[[ -d "$upd" ]] || continue
safe_rm "$upd" "AppSupport updater: $(basename "$upd")"
done
shopt -u nullglob