Repository navigation
Expand file tree
/
Copy pathuninstall.sh
More file actions
executable file
·587 lines (489 loc) · 17.7 KB
/
Copy pathuninstall.sh
File metadata and controls
executable file
·587 lines (489 loc) · 17.7 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
#!/usr/bin/env bash
# Uninstall dotfiles and optionally remove installed packages
# Usage: ./uninstall.sh [options]
set -euo pipefail
# Get the directory where this script is located
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Source common functions
# shellcheck source=install/common.sh
source "${SCRIPT_DIR}/install/common.sh"
# Get dotfiles directory
# shellcheck disable=SC2034
DOTFILES_DIR="$(get_dotfiles_dir)"
#------------------------------------------------------------------------
# Configuration
#------------------------------------------------------------------------
# What to uninstall (set via command line flags)
REMOVE_SYMLINKS=false
REMOVE_MISE_TOOLS=false
REMOVE_MISE=false
REMOVE_CONFIGS=false
REMOVE_LOCAL_FILES=false
REMOVE_LOGS=false
REMOVE_GIT_HOOKS=false
REMOVE_HOMEBREW=false
DRY_RUN=false
INTERACTIVE=true
# Backup directory with timestamp
BACKUP_DIR="${HOME}/.dotfiles.backup.uninstall.$(date +%Y%m%d_%H%M%S)"
#------------------------------------------------------------------------
# Helper Functions
#------------------------------------------------------------------------
print_usage() {
cat <<EOF
Usage: $0 [options]
Uninstall dotfiles and optionally remove installed packages.
Options:
--all Remove everything (nuclear option)
--symlinks Remove dotfile symlinks only (default if no options)
--mise-tools Uninstall mise-managed tools (50+ packages)
--mise Remove mise binary and data directories
--configs Remove config directories (~/.config/mise, ~/.config/ghostty)
--local-files Remove local files (~/.env.local, ~/.gitconfig.local)
--logs Remove installation log directory (~/.dotfiles-install-logs)
--git-hooks Remove git hooks (lefthook)
--homebrew Remove Homebrew (USE WITH CAUTION!)
--dry-run, -n Show what would be removed without doing it
--yes, -y Skip confirmation prompts
--help, -h Show this help message
Safety Levels:
Safe: --symlinks, --logs
Moderate: --configs, --local-files, --git-hooks
Risky: --mise-tools, --mise
Dangerous: --homebrew (may break other applications!)
Examples:
# Remove only symlinks (safest)
$0 --symlinks
# Remove symlinks and local files
$0 --symlinks --local-files
# Remove symlinks, configs, and logs (keeps mise/tools)
$0 --symlinks --configs --logs
# Remove everything except Homebrew
$0 --symlinks --configs --mise-tools --mise --local-files --logs --git-hooks
# Nuclear option - remove EVERYTHING including Homebrew
$0 --all
# Dry run to see what would be removed (recommended first!)
$0 --all --dry-run
EOF
}
confirm() {
local prompt="$1"
local default="${2:-n}"
if [[ "$INTERACTIVE" == "false" ]]; then
return 0
fi
local response
if [[ "$default" == "y" ]]; then
read -rp "$prompt [Y/n]: " response
response="${response:-y}"
else
read -rp "$prompt [y/N]: " response
response="${response:-n}"
fi
[[ "$response" =~ ^[Yy] ]]
}
create_backup() {
local file="$1"
if [[ ! -e "$file" && ! -L "$file" ]]; then
return 0
fi
if [[ ! -d "$BACKUP_DIR" ]]; then
mkdir -p "$BACKUP_DIR"
log_info "Created backup directory: $BACKUP_DIR"
fi
local name
name="$(basename "$file")"
if is_dry_run; then
log_dry_run "Would backup: $file -> ${BACKUP_DIR}/${name}"
else
cp -r "$file" "${BACKUP_DIR}/${name}" 2>/dev/null || true
log_info "Backed up: $name"
fi
}
#------------------------------------------------------------------------
# Uninstall Functions
#------------------------------------------------------------------------
remove_symlinks() {
log_step "Removing dotfile symlinks..."
# Source the symlinks script for its remove function
# shellcheck source=install/symlinks.sh
source "${SCRIPT_DIR}/install/symlinks.sh"
# Use the existing remove_symlinks function
if is_dry_run; then
log_dry_run "Would remove all dotfile symlinks"
log_info "See install/symlinks.sh:352 for full list"
else
# The function is already defined from sourcing symlinks.sh
remove_symlinks
fi
}
remove_mise_tools() {
log_step "Removing mise-managed tools..."
if ! command -v mise >/dev/null 2>&1; then
log_info "mise not installed, skipping tool removal"
return 0
fi
# Get list of installed tools
local installed_tools
installed_tools=$(mise list 2>/dev/null | awk '{print $1}' | sort -u)
if [[ -z "$installed_tools" ]]; then
log_info "No mise tools installed"
return 0
fi
log_info "Found mise tools:"
echo "$installed_tools" | while IFS= read -r tool; do
echo " - $tool"
done
if ! confirm "Remove all mise-managed tools?" "n"; then
log_info "Skipping mise tool removal"
return 0
fi
echo "$installed_tools" | while IFS= read -r tool; do
if is_dry_run; then
log_dry_run "Would uninstall: $tool"
else
log_info "Uninstalling: $tool"
mise uninstall "$tool" --all || log_warning "Failed to uninstall: $tool"
fi
done
log_success "Mise tools removed"
}
remove_mise_binary() {
log_step "Removing mise..."
if ! command -v mise >/dev/null 2>&1; then
log_info "mise not installed"
return 0
fi
local mise_path
mise_path=$(command -v mise)
log_info "Found mise at: $mise_path"
if ! confirm "Remove mise binary?" "n"; then
log_info "Keeping mise"
return 0
fi
if is_dry_run; then
log_dry_run "Would remove: $mise_path"
log_dry_run "Would remove: ~/.local/share/mise"
log_dry_run "Would remove: ~/.local/state/mise"
log_dry_run "Would remove: ~/.cache/mise"
else
# Backup mise binary
create_backup "$mise_path"
# Remove mise binary
rm -f "$mise_path"
log_success "Removed mise binary"
# Remove mise directories
if [[ -d "${HOME}/.local/share/mise" ]]; then
create_backup "${HOME}/.local/share/mise"
rm -rf "${HOME}/.local/share/mise"
log_success "Removed ~/.local/share/mise"
fi
if [[ -d "${HOME}/.local/state/mise" ]]; then
create_backup "${HOME}/.local/state/mise"
rm -rf "${HOME}/.local/state/mise"
log_success "Removed ~/.local/state/mise"
fi
if [[ -d "${HOME}/.cache/mise" ]]; then
rm -rf "${HOME}/.cache/mise"
log_success "Removed ~/.cache/mise"
fi
fi
}
remove_config_directories() {
log_step "Removing config directories..."
local configs=(
"${HOME}/.config/mise"
"${HOME}/.config/ghostty"
)
for config in "${configs[@]}"; do
if [[ -e "$config" || -L "$config" ]]; then
if is_dry_run; then
log_dry_run "Would remove: $config"
else
create_backup "$config"
rm -rf "$config"
log_success "Removed: $config"
fi
fi
done
}
remove_local_files() {
log_step "Removing local configuration files..."
local files=(
"${HOME}/.env.local"
"${HOME}/.gitconfig.local"
)
log_warning "These files may contain your personal settings and secrets!"
for file in "${files[@]}"; do
if [[ -f "$file" ]]; then
if is_dry_run; then
log_dry_run "Would remove: $file"
else
if confirm "Remove $file?" "n"; then
create_backup "$file"
rm -f "$file"
log_success "Removed: $file"
else
log_info "Keeping: $file"
fi
fi
fi
done
}
remove_install_logs() {
log_step "Removing installation logs..."
if [[ -d "${HOME}/.dotfiles-install-logs" ]]; then
if is_dry_run; then
log_dry_run "Would remove: ~/.dotfiles-install-logs"
else
rm -rf "${HOME}/.dotfiles-install-logs"
log_success "Removed: ~/.dotfiles-install-logs"
fi
else
log_info "No installation logs found"
fi
}
remove_git_hooks() {
log_step "Removing git hooks..."
if [[ ! -d "${SCRIPT_DIR}/.git/hooks" ]]; then
log_info "Not a git repository or no hooks installed"
return 0
fi
if ! command -v lefthook >/dev/null 2>&1; then
log_info "lefthook not installed, skipping"
return 0
fi
if is_dry_run; then
log_dry_run "Would run: lefthook uninstall"
else
cd "${SCRIPT_DIR}" && lefthook uninstall
log_success "Git hooks removed"
fi
}
remove_homebrew() {
log_step "Removing Homebrew..."
if ! command -v brew >/dev/null 2>&1; then
log_info "Homebrew not installed"
return 0
fi
local brew_prefix
brew_prefix="$(brew --prefix)"
log_warning "╔════════════════════════════════════════════════════════════╗"
log_warning "║ WARNING: This will uninstall Homebrew completely! ║"
log_warning "║ All Homebrew packages will be removed! ║"
log_warning "║ This may break other applications on your system! ║"
log_warning "╚════════════════════════════════════════════════════════════╝"
echo ""
log_info "Homebrew prefix: $brew_prefix"
echo ""
if ! confirm "Are you ABSOLUTELY SURE you want to uninstall Homebrew?" "n"; then
log_info "Keeping Homebrew"
return 0
fi
if ! confirm "Last chance! Uninstall Homebrew and all its packages?" "n"; then
log_info "Keeping Homebrew"
return 0
fi
if is_dry_run; then
log_dry_run "Would download and run Homebrew uninstall script"
else
log_info "Downloading Homebrew uninstall script..."
if command -v curl >/dev/null 2>&1; then
bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"
else
log_error "curl not found, cannot download uninstall script"
log_info "Manual uninstall: /bin/bash -c \"\$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)\""
return 1
fi
log_success "Homebrew removed"
fi
}
reset_iterm2_preferences() {
log_step "Resetting iTerm2 preferences..."
if [[ "$OSTYPE" != "darwin"* ]]; then
log_info "Skipping iTerm2 reset (macOS only)"
return 0
fi
# Check if iTerm2 preferences were configured
local prefs_folder
prefs_folder=$(defaults read com.googlecode.iterm2 PrefsCustomFolder 2>/dev/null || echo "")
if [[ -z "$prefs_folder" ]]; then
log_info "iTerm2 not configured to use custom preferences"
return 0
fi
if is_dry_run; then
log_dry_run "Would reset iTerm2 preferences to system default"
else
if confirm "Reset iTerm2 to use system preferences?" "n"; then
defaults delete com.googlecode.iterm2 PrefsCustomFolder 2>/dev/null || true
defaults write com.googlecode.iterm2 LoadPrefsFromCustomFolder -bool false
log_success "iTerm2 reset to system preferences"
log_info "Restart iTerm2 for changes to take effect"
else
log_info "Keeping iTerm2 custom preferences"
fi
fi
}
cleanup_shell_integration() {
log_step "Cleaning up shell integration..."
# Note: We don't remove shell rc files since user may have customized them
# We just notify the user
log_info "Shell integration is in your dotfile symlinks"
log_info "Symlink removal will revert to your original shell configs"
if [[ -d "$BACKUP_DIR" ]]; then
log_info "Original configs backed up to: $BACKUP_DIR"
fi
}
#------------------------------------------------------------------------
# Main Execution
#------------------------------------------------------------------------
main() {
# Parse command line arguments
if [[ $# -eq 0 ]]; then
# Default: just remove symlinks
REMOVE_SYMLINKS=true
fi
while [[ $# -gt 0 ]]; do
case "$1" in
--all)
REMOVE_SYMLINKS=true
REMOVE_MISE_TOOLS=true
REMOVE_MISE=true
REMOVE_CONFIGS=true
REMOVE_LOCAL_FILES=true
REMOVE_LOGS=true
REMOVE_GIT_HOOKS=true
REMOVE_HOMEBREW=true
;;
--symlinks)
REMOVE_SYMLINKS=true
;;
--mise-tools)
REMOVE_MISE_TOOLS=true
;;
--mise)
REMOVE_MISE=true
;;
--configs)
REMOVE_CONFIGS=true
;;
--local-files)
REMOVE_LOCAL_FILES=true
;;
--logs)
REMOVE_LOGS=true
;;
--git-hooks)
REMOVE_GIT_HOOKS=true
;;
--homebrew)
REMOVE_HOMEBREW=true
;;
--dry-run|-n)
# shellcheck disable=SC2034
DRY_RUN=true
;;
--yes|-y)
INTERACTIVE=false
;;
--help|-h)
print_usage
exit 0
;;
*)
log_error "Unknown option: $1"
print_usage
exit 1
;;
esac
shift
done
print_header "Dotfiles Uninstaller"
if is_dry_run; then
log_info "DRY RUN MODE: No changes will be made"
echo ""
fi
# Show what will be removed
log_step "Uninstall Summary"
echo ""
echo "The following will be removed:"
[[ "$REMOVE_SYMLINKS" == "true" ]] && echo " ✓ Dotfile symlinks (.bashrc, .zshrc, .gitconfig, etc.)"
[[ "$REMOVE_CONFIGS" == "true" ]] && echo " ✓ Config directories (~/.config/mise, ~/.config/ghostty)"
[[ "$REMOVE_LOCAL_FILES" == "true" ]] && echo " ✓ Local files (~/.env.local, ~/.gitconfig.local)"
[[ "$REMOVE_LOGS" == "true" ]] && echo " ✓ Installation logs (~/.dotfiles-install-logs)"
[[ "$REMOVE_GIT_HOOKS" == "true" ]] && echo " ✓ Git hooks (lefthook)"
[[ "$REMOVE_MISE_TOOLS" == "true" ]] && echo " ✓ Mise-managed tools (50+ packages)"
[[ "$REMOVE_MISE" == "true" ]] && echo " ✓ Mise binary and data directories"
[[ "$REMOVE_HOMEBREW" == "true" ]] && echo " ✓ Homebrew (DANGEROUS - will remove ALL brew packages!)"
echo ""
if [[ "$REMOVE_SYMLINKS" == "false" && "$REMOVE_CONFIGS" == "false" && \
"$REMOVE_MISE_TOOLS" == "false" && "$REMOVE_MISE" == "false" && \
"$REMOVE_LOCAL_FILES" == "false" && "$REMOVE_LOGS" == "false" && \
"$REMOVE_GIT_HOOKS" == "false" && "$REMOVE_HOMEBREW" == "false" ]]; then
log_warning "Nothing selected to remove"
echo ""
print_usage
exit 0
fi
# Final confirmation
if ! is_dry_run; then
log_warning "This operation cannot be easily undone!"
log_info "Backups will be created in: $BACKUP_DIR"
echo ""
if ! confirm "Continue with uninstall?" "n"; then
log_info "Uninstall cancelled"
exit 0
fi
echo ""
fi
# Execute uninstall steps in order (safest to most destructive)
[[ "$REMOVE_GIT_HOOKS" == "true" ]] && remove_git_hooks
[[ "$REMOVE_LOGS" == "true" ]] && remove_install_logs
[[ "$REMOVE_SYMLINKS" == "true" ]] && remove_symlinks
[[ "$REMOVE_SYMLINKS" == "true" ]] && reset_iterm2_preferences
[[ "$REMOVE_CONFIGS" == "true" ]] && remove_config_directories
[[ "$REMOVE_LOCAL_FILES" == "true" ]] && remove_local_files
[[ "$REMOVE_MISE_TOOLS" == "true" ]] && remove_mise_tools
[[ "$REMOVE_MISE" == "true" ]] && remove_mise_binary
[[ "$REMOVE_HOMEBREW" == "true" ]] && remove_homebrew
cleanup_shell_integration
# Print summary
echo ""
print_header "Uninstall Complete"
echo ""
if [[ -d "$BACKUP_DIR" ]] && ! is_dry_run; then
log_success "Backups saved to: $BACKUP_DIR"
echo ""
log_info "To restore your dotfiles:"
log_info " cp -r ${BACKUP_DIR}/. ~/"
echo ""
fi
if [[ "$REMOVE_SYMLINKS" == "true" ]]; then
log_info "Your shell configs have been restored to pre-dotfiles state"
log_info "Restart your shell or source your config:"
log_info " source ~/.zshrc (or ~/.bashrc)"
echo ""
fi
if [[ "$REMOVE_MISE" == "true" ]] || [[ "$REMOVE_MISE_TOOLS" == "true" ]]; then
log_info "Mise and its tools have been removed"
log_info "If you had other mise configurations, you may need to reinstall"
echo ""
fi
if [[ "$REMOVE_HOMEBREW" == "true" ]] && ! is_dry_run; then
log_info "Homebrew has been removed"
log_info "To reinstall: /bin/bash -c \"\$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)\""
echo ""
fi
if [[ "$REMOVE_LOCAL_FILES" == "true" ]]; then
log_info "Local configuration files removed"
log_info "Remember to reconfigure secrets if you reinstall"
echo ""
fi
log_success "Uninstall complete!"
if is_dry_run; then
echo ""
log_info "This was a dry run. To actually uninstall, run without --dry-run"
fi
}
# Run main function
main "$@"