-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuninstall.sh
More file actions
executable file
·199 lines (177 loc) · 5.92 KB
/
Copy pathuninstall.sh
File metadata and controls
executable file
·199 lines (177 loc) · 5.92 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
#!/bin/bash
# Dotfiles Uninstallation Script
# This script removes the symlinks created by install.sh
set -e
DOTFILES_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Files and directories to uninstall
TARGETS=(
"$HOME/.tmux.conf"
"$HOME/.vimrc"
"$HOME/.vimrc.plug"
"$HOME/.config/nvim"
"$HOME/.config/clangd"
"$HOME/.zshrc"
"$HOME/.neomuttrc"
"$HOME/.slconfig"
"$HOME/.mbsyncrc"
"$HOME/.notmuch-config"
"$HOME/.neomutt/macos.rc"
"$HOME/.neomutt/linux.rc"
"$HOME/.claude/skills"
"$HOME/bin"
)
uninstall_via_packagefile() {
trap 'warn "${FUNCNAME[0]}: command failed: $BASH_COMMAND"; trap - ERR' ERR
local pkg_file remove_cmd
if command -v apt &>/dev/null; then
pkg_file="$DOTFILES_DIR/packages/apt.txt"
remove_cmd="sudo apt remove -y"
elif command -v dnf &>/dev/null; then
pkg_file="$DOTFILES_DIR/packages/dnf.txt"
remove_cmd="sudo dnf remove -y"
elif command -v pacman &>/dev/null; then
pkg_file="$DOTFILES_DIR/packages/pacman.txt"
remove_cmd="sudo pacman -Rs --noconfirm"
else
warn "No supported package manager found (apt/dnf/pacman)"
return 1
fi
if [[ ! -f "$pkg_file" ]]; then
warn "Package file not found: $pkg_file"
return 1
fi
info "Removing packages from $(basename "$pkg_file")..."
local pkg
while IFS= read -r pkg || [[ -n "$pkg" ]]; do
[[ -z "$pkg" || "$pkg" == \#* ]] && continue
# </dev/null: see the matching note in install.sh -- without it a
# package manager that reads stdin eats the rest of the list and the
# loop ends early and silently.
$remove_cmd "$pkg" </dev/null || warn "failed to remove $pkg — skipping"
done < "$pkg_file"
info "Package removal complete"
}
uninstall_ghostty() {
trap 'warn "${FUNCNAME[0]}: command failed: $BASH_COMMAND"; trap - ERR' ERR
if command -v ghostty &> /dev/null; then
info "Uninstalling ghostty..."
if command -v brew &> /dev/null; then
brew uninstall ghostty
elif command -v apt &> /dev/null; then
sudo apt remove -y ghostty
# Optionally remove the repository
sudo rm -f /etc/apt/sources.list.d/ghostty.list
sudo rm -f /usr/share/keyrings/ghostty-keyring.gpg
elif command -v dnf &> /dev/null; then
sudo dnf remove -y ghostty
elif command -v pacman &> /dev/null; then
sudo pacman -Rs --noconfirm ghostty
else
warn "Could not detect package manager. Please uninstall ghostty manually."
return 1
fi
info "ghostty uninstalled"
else
info "ghostty is not installed"
fi
}
uninstall_ohmyzsh() {
trap 'warn "${FUNCNAME[0]}: command failed: $BASH_COMMAND"; trap - ERR' ERR
if [ -d "$HOME/.oh-my-zsh" ]; then
info "Removing oh-my-zsh..."
rm -rf "$HOME/.oh-my-zsh"
info "oh-my-zsh removed"
else
info "oh-my-zsh is not installed"
fi
}
restore_default_shell() {
trap 'warn "${FUNCNAME[0]}: command failed: $BASH_COMMAND"; trap - ERR' ERR
local bash_path
bash_path="$(which bash)"
if [ "$SHELL" != "$bash_path" ]; then
info "Restoring bash as default shell..."
chsh -s "$bash_path"
info "Default shell changed to bash (restart your terminal to take effect)"
else
info "bash is already the default shell"
fi
}
main() {
local skip_packages=false
while [[ $# -gt 0 ]]; do
case "$1" in
--skip-packages)
skip_packages=true
shift
;;
*)
error "Unknown option: $1"
echo "Usage: $0 [--skip-packages]"
exit 1
;;
esac
done
echo "=========================================="
echo " Dotfiles Uninstallation Script "
echo "=========================================="
echo ""
# Remove symlinks
info "Removing symlinks..."
for target in "${TARGETS[@]}"; do
if [ -L "$target" ]; then
# Check if symlink points to our dotfiles directory
link_target="$(readlink "$target")"
if [[ "$link_target" == "$DOTFILES_DIR"* ]]; then
rm "$target"
info "Removed symlink: $target"
else
warn "Skipping $target - symlink points elsewhere: $link_target"
fi
elif [ -e "$target" ]; then
warn "Skipping $target - not a symlink (may be original file)"
else
warn "Skipping $target - does not exist"
fi
done
echo ""
if [ "$skip_packages" = true ]; then
info "Skipping package uninstallation (--skip-packages)"
else
read -p "Do you want to uninstall packages (tmux, neovim, neomutt, ghostty, zsh, oh-my-zsh)? [y/N] " -n 1 -r
echo ""
fi
if [ "$skip_packages" = false ] && [[ $REPLY =~ ^[Yy]$ ]]; then
echo ""
uninstall_via_packagefile || warn "package removal incomplete — check output above"
echo ""
uninstall_ghostty || warn "ghostty uninstallation failed — remove manually"
echo ""
uninstall_ohmyzsh || warn "oh-my-zsh removal failed — remove manually"
echo ""
restore_default_shell || warn "could not restore default shell — run: chsh -s \$(which bash)"
else
info "Skipping package uninstallation"
fi
echo ""
echo "=========================================="
info "Uninstallation complete!"
echo ""
echo "To restore backups, check ~/.dotfiles_backup_* directories"
echo "=========================================="
}
main "$@"