-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvscode-tools-uninstall.sh
More file actions
executable file
·190 lines (170 loc) · 4.98 KB
/
vscode-tools-uninstall.sh
File metadata and controls
executable file
·190 lines (170 loc) · 4.98 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
#!/bin/bash
# =============================================
# 🧹 VS Code + Extensions Uninstaller
# =============================================
# --- Status tracking ---
declare -A STATUS
mark_status() {
local name="$1"
local status="$2"
STATUS["$name"]="$status"
}
# --- Determine if sudo is needed ---
if [ "$(id -u)" -eq 0 ]; then
SUDO=""
else
if command -v sudo &>/dev/null; then
SUDO="sudo"
else
echo "⚠️ No sudo and not root. Package removal may fail."
SUDO=""
fi
fi
# --- Check if VS Code is present ---
if ! command -v code &>/dev/null; then
echo "ℹ️ VS Code is not installed. Nothing to do."
exit 0
fi
# =============================================
# 1. Remove Extensions
# =============================================
echo "🧹 VS Code Uninstaller"
echo ""
EXTENSIONS=(
aaron-bond.better-comments
almenon.arepl
ash-blade.postgresql-hacker-helper
eamodio.gitlens
esbenp.prettier-vscode
github.copilot-chat
johnpapa.vscode-peacock
kevinrose.vsc-python-indent
ms-azuretools.vscode-containers
ms-azuretools.vscode-docker
ms-python.debugpy
ms-python.python
ms-python.vscode-pylance
ms-python.vscode-python-envs
ms-vscode-remote.remote-containers
ms-vscode-remote.remote-ssh
ms-vscode-remote.remote-ssh-edit
ms-vscode.cmake-tools
ms-vscode.cpp-devtools
ms-vscode.cpptools
ms-vscode.cpptools-extension-pack
ms-vscode.cpptools-themes
ms-vscode.makefile-tools
ms-vscode.remote-explorer
mumarshahbaz.als
nstechbytes.html-view
oderwat.indent-rainbow
pkief.material-icon-theme
quicktype.quicktype
tonybaloney.vscode-pets
wolfieshorizon.python-auto-venv
)
read -rp "🧩 Remove all listed extensions? [Y/n]: " answer
answer="${answer:-Y}"
if [[ "$answer" =~ ^[Yy]$ ]]; then
echo ""
INSTALLED=$(code --list-extensions 2>/dev/null)
for ext in "${EXTENSIONS[@]}"; do
ext_lower=$(echo "$ext" | tr '[:upper:]' '[:lower:]')
if echo "$INSTALLED" | tr '[:upper:]' '[:lower:]' | grep -qx "$ext_lower"; then
if code --uninstall-extension "$ext" 2>/dev/null; then
echo " 🟢 $ext — removed"
mark_status "$ext" "removed"
else
echo " 🔴 $ext — failed"
mark_status "$ext" "failed"
fi
else
echo " ⚪ $ext — not installed"
mark_status "$ext" "not found"
fi
done
else
echo "⏭️ Skipping extension removal."
for ext in "${EXTENSIONS[@]}"; do
mark_status "$ext" "skipped"
done
fi
# =============================================
# 2. Remove VS Code
# =============================================
echo ""
read -rp "🗑️ Also remove VS Code itself? [y/N]: " answer
answer="${answer:-N}"
if [[ "$answer" =~ ^[Yy]$ ]]; then
echo "⬇️ Removing VS Code..."
if $SUDO apt remove --purge code -y -qq 2>/dev/null; then
# Clean up repo and key
$SUDO rm -f /etc/apt/sources.list.d/vscode.list
$SUDO rm -f /etc/apt/keyrings/packages.microsoft.gpg
# Clean up user data (optional)
read -rp "🗂️ Also remove VS Code settings and data? [y/N]: " data_answer
data_answer="${data_answer:-N}"
if [[ "$data_answer" =~ ^[Yy]$ ]]; then
rm -rf "$HOME/.config/Code"
rm -rf "$HOME/.vscode"
mark_status "vscode" "removed + data cleaned"
else
mark_status "vscode" "removed"
fi
else
mark_status "vscode" "failed"
fi
else
echo "⏭️ Keeping VS Code."
mark_status "vscode" "kept"
fi
# =============================================
# Summary
# =============================================
echo ""
echo "==========================================="
echo " 📋 Uninstall Summary"
echo "==========================================="
# VS Code status
st="${STATUS[vscode]:-kept}"
case "$st" in
"removed") icon="🟢 Removed" ;;
"removed + data cleaned") icon="🟢 Removed + data cleaned" ;;
"kept") icon="🔵 Kept" ;;
"failed") icon="🔴 Failed" ;;
*) icon="⚪ Unknown" ;;
esac
printf "\n %-40s %s\n" "VS Code" "$icon"
# Extensions summary
ext_removed=0
ext_notfound=0
ext_failed=0
ext_skipped=0
failed_list=()
for ext in "${EXTENSIONS[@]}"; do
st="${STATUS[$ext]:-unknown}"
case "$st" in
"removed") ((ext_removed++)) ;;
"not found") ((ext_notfound++)) ;;
"failed") ((ext_failed++)); failed_list+=("$ext") ;;
"skipped") ((ext_skipped++)) ;;
esac
done
echo ""
echo " Extensions:"
echo " ────────────────────────────────────────"
printf " 🟢 Removed: %d\n" "$ext_removed"
printf " ⚪ Not installed: %d\n" "$ext_notfound"
printf " 🟡 Skipped: %d\n" "$ext_skipped"
printf " 🔴 Failed: %d\n" "$ext_failed"
if [ ${#failed_list[@]} -gt 0 ]; then
echo ""
echo " Failed extensions:"
for f in "${failed_list[@]}"; do
echo " ❌ $f"
done
fi
echo ""
echo "==========================================="
echo ""
echo "✅ Done! 🎉"