Repository navigation
Expand file tree
/
Copy pathuninstall.sh
More file actions
executable file
·228 lines (200 loc) · 5.36 KB
/
Copy pathuninstall.sh
File metadata and controls
executable file
·228 lines (200 loc) · 5.36 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
#!/usr/bin/env bash
#
# Uninstall git-wrapper
#
# Removes:
# - Wrapper symlink from ~/.local/bin/git (or $GIT_WRAPPER_BIN)
# - Optionally removes plugin config directory
# - Removes git config entries
#
# Options:
# --bin-dir DIR Look for wrapper in DIR (default: ~/.local/bin)
# --config-dir DIR Plugin directory location (default: ~/.git.d)
# --remove-config Also remove the config/plugins directory
# --keep-git-config Don't remove wrapper.* git config entries
# --dry-run Show what would be done without doing it
# -y, --yes Don't prompt for confirmation
# -h, --help Show this help message
#
set -euo pipefail
# Script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Installation defaults
BIN_DIR="${GIT_WRAPPER_BIN:-${HOME}/.local/bin}"
CONFIG_DIR="${GIT_WRAPPER_CONFIG:-${HOME}/.git.d}"
# Options
REMOVE_CONFIG=false
KEEP_GIT_CONFIG=false
DRY_RUN=false
YES=false
# Colors
C_RED=$'\033[31m'
C_GREEN=$'\033[32m'
C_YELLOW=$'\033[33m'
C_CYAN=$'\033[36m'
C_BOLD=$'\033[1m'
C_RESET=$'\033[0m'
usage() {
cat << EOF
Usage: $(basename "$0") [OPTIONS]
Uninstall git-wrapper.
Options:
--bin-dir DIR Look for wrapper in DIR (default: ~/.local/bin)
--config-dir DIR Plugin directory location (default: ~/.git.d)
--remove-config Also remove the config/plugins directory
--keep-git-config Don't remove wrapper.* git config entries
--dry-run Show what would be done without doing it
-y, --yes Don't prompt for confirmation
-h, --help Show this help message
Environment variables:
GIT_WRAPPER_BIN Override default bin directory
GIT_WRAPPER_CONFIG Override default config directory
EOF
}
log() {
echo "${C_GREEN}==>${C_RESET} ${C_BOLD}$*${C_RESET}"
}
log_action() {
echo " ${C_RED}$1${C_RESET} $2"
}
warn() {
echo "${C_YELLOW}Warning:${C_RESET} $*" >&2
}
run() {
if ${DRY_RUN}; then
echo " ${C_YELLOW}[dry-run]${C_RESET} $*"
else
"$@"
fi
}
confirm() {
if ${YES}; then
return 0
fi
local response
read -rp "$1 [y/N] " response
[[ "${response}" =~ ^[Yy] ]]
}
# Parse arguments
while [[ $# -gt 0 ]]; do
case $1 in
--bin-dir)
BIN_DIR="$2"
shift 2
;;
--bin-dir=*)
BIN_DIR="${1#*=}"
shift
;;
--config-dir)
CONFIG_DIR="$2"
shift 2
;;
--config-dir=*)
CONFIG_DIR="${1#*=}"
shift
;;
--remove-config)
REMOVE_CONFIG=true
shift
;;
--keep-git-config)
KEEP_GIT_CONFIG=true
shift
;;
--dry-run)
DRY_RUN=true
shift
;;
-y|--yes)
YES=true
shift
;;
-h|--help)
usage
exit 0
;;
*)
echo "Unknown option: $1" >&2
usage >&2
exit 1
;;
esac
done
# Expand paths
BIN_DIR="${BIN_DIR/#\~/$HOME}"
CONFIG_DIR="${CONFIG_DIR/#\~/$HOME}"
echo "${C_BOLD}git-wrapper uninstaller${C_RESET}"
echo ""
# Check what exists
WRAPPER_EXISTS=false
CONFIG_EXISTS=false
if [[ -e "${BIN_DIR}/git" ]]; then
WRAPPER_EXISTS=true
fi
if [[ -d "${CONFIG_DIR}" ]]; then
CONFIG_EXISTS=true
fi
if ! ${WRAPPER_EXISTS} && ! ${CONFIG_EXISTS}; then
echo "Nothing to uninstall."
echo " Wrapper not found at: ${BIN_DIR}/git"
echo " Config not found at: ${CONFIG_DIR}/"
exit 0
fi
# Show what will be removed
echo "The following will be removed:"
if ${WRAPPER_EXISTS}; then
echo " ${C_CYAN}${BIN_DIR}/git${C_RESET}"
fi
if ${REMOVE_CONFIG} && ${CONFIG_EXISTS}; then
echo " ${C_CYAN}${CONFIG_DIR}/${C_RESET} (and all plugins)"
fi
if ! ${KEEP_GIT_CONFIG}; then
echo " ${C_CYAN}git config --global wrapper.*${C_RESET}"
fi
echo ""
if ! ${DRY_RUN} && ! confirm "Continue?"; then
echo "Aborted."
exit 1
fi
# Remove wrapper
if ${WRAPPER_EXISTS}; then
log "Removing wrapper"
if [[ -L "${BIN_DIR}/git" ]]; then
log_action "remove" "${BIN_DIR}/git (symlink)"
run rm "${BIN_DIR}/git"
else
warn "${BIN_DIR}/git is not a symlink, skipping"
warn "Remove it manually if desired"
fi
fi
# Remove config directory
if ${REMOVE_CONFIG} && ${CONFIG_EXISTS}; then
log "Removing config directory"
log_action "remove" "${CONFIG_DIR}/"
run rm -rf "${CONFIG_DIR}"
fi
# Remove git config
if ! ${KEEP_GIT_CONFIG}; then
log "Removing git config"
# Get all wrapper.* config keys
if ! ${DRY_RUN}; then
wrapper_keys=$(git config --global --list 2>/dev/null | grep '^wrapper\.' | cut -d= -f1 || true)
for key in ${wrapper_keys}; do
log_action "unset" "${key}"
git config --global --unset "${key}" 2>/dev/null || true
done
if [[ -z "${wrapper_keys}" ]]; then
echo " (no wrapper.* config entries found)"
fi
else
echo " ${C_YELLOW}[dry-run]${C_RESET} git config --global --unset wrapper.*"
fi
fi
echo ""
log "Uninstall complete!"
if ! ${REMOVE_CONFIG} && ${CONFIG_EXISTS}; then
echo ""
echo "Config directory preserved at: ${C_CYAN}${CONFIG_DIR}/${C_RESET}"
echo "Run with ${C_CYAN}--remove-config${C_RESET} to remove it."
fi