-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathuninstall.sh
More file actions
executable file
·132 lines (105 loc) · 3.21 KB
/
uninstall.sh
File metadata and controls
executable file
·132 lines (105 loc) · 3.21 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
#!/usr/bin/env bash
# Remove symlinks created by the dotfiles installer - no admin required
set -e
DOTFILES_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Colors
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m'
info() { echo -e "${GREEN}[INFO]${NC} $1"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
is_under_home() {
local path="$1"
[[ "$path" == "$HOME"/* ]]
}
# Remove a symlink only when it points to the expected file in this repository.
unlink_dotfile() {
local src="$DOTFILES_DIR/$1"
local dst="$2"
local target
if [[ ! -e "$dst" && ! -L "$dst" ]]; then
warn "Missing: $dst"
return
fi
if [[ ! -L "$dst" ]]; then
warn "Skipping non-symlink: $dst"
return
fi
target="$(readlink "$dst")"
if [[ "$target" != "$src" ]]; then
warn "Skipping symlink with unexpected target: $dst -> $target"
return
fi
rm "$dst"
info "Removed: $dst"
}
cleanup_beads_rc_lines() {
local rc
for rc in "$HOME/.bashrc" "$HOME/.zshrc" "$HOME/.profile" "$HOME/.config/fish/config.fish"; do
if [[ ! -f "$rc" ]]; then
continue
fi
if ! grep -q "# br installer" "$rc" 2>/dev/null; then
continue
fi
if [[ -L "$rc" ]]; then
warn "Skipping br rc cleanup for symlink: $rc"
continue
fi
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i '' '/# br installer/d' "$rc" 2>/dev/null || true
else
sed -i '/# br installer/d' "$rc" 2>/dev/null || true
fi
info "Cleaned br installer lines from: $rc"
done
}
remove_beads() {
local binary_name="br"
local dest="${BR_INSTALL_DIR:-$HOME/.local/bin}"
local bin
local active_br
case "$(uname -s)" in
MINGW*|MSYS*|CYGWIN*) binary_name="br.exe" ;;
esac
if ! is_under_home "$dest"; then
warn "Skipping beads install dir outside HOME: $dest"
return
fi
bin="$dest/$binary_name"
if [[ -e "$bin" || -L "$bin" ]]; then
rm -f "$bin"
info "Removed beads CLI: $bin"
else
info "beads CLI not found at: $bin"
fi
cleanup_beads_rc_lines
hash -r 2>/dev/null || true
active_br="$(command -v "$binary_name" 2>/dev/null || true)"
if [[ -n "$active_br" && "$active_br" != "$bin" ]]; then
warn "br still found elsewhere, leaving it untouched: $active_br"
fi
}
echo "=== Dotfiles Uninstaller ==="
echo ""
# Shell
unlink_dotfile config/zshrc "$HOME/.zshrc"
# Editors
unlink_dotfile config/nvim "$HOME/.config/nvim"
unlink_dotfile config/vimrc "$HOME/.vimrc"
unlink_dotfile modules/vim-plug/plug.vim "$HOME/.vim/autoload/plug.vim"
unlink_dotfile config/ycm_extra_conf.py "$HOME/.ycm_extra_conf.py"
# Tools
unlink_dotfile bin "$HOME/bin/common"
unlink_dotfile config/ghostty "$HOME/.config/ghostty/config"
unlink_dotfile config/tmux.conf "$HOME/.tmux.conf"
unlink_dotfile config/gitconfig "$HOME/.gitconfig"
unlink_dotfile config/gitignore_global "$HOME/.gitignore_global"
unlink_dotfile config/gdbinit "$HOME/.gdbinit"
unlink_dotfile config/gdb "$HOME/.gdb"
unlink_dotfile config/pryrc "$HOME/.pryrc"
echo ""
info "Removing beads CLI tool..."
remove_beads
echo ""
info "Uninstall complete!"