-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuninstall
executable file
·185 lines (139 loc) · 3.27 KB
/
uninstall
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
#!/usr/bin/env bash
set -e
# ---------------------------------------------- #
#
# "uninstall --help" for more information.
#
# ---------------------------------------------- #
# ---------------------------------------------- #
# shell-utils #
# ---------------------------------------------- #
# Colors
red="\e[31m"
green="\e[32m"
yellow="\e[33m"
normal="\e[0m"
function alert_die() {
local error="${1}"
print_new_line
alert "Error: ${error}"
die
}
function print() {
echo "${*}"
}
function print_error() {
print >&2 "${*}"
}
function print_new_line() {
print ""
}
# Prints a green success message.
function success() {
print "${green}${*}${normal}"
}
# Prints a yellow warning message.
function warning() {
print "${yellow}${*}${normal}"
}
# Prints a red error message.
function alert() {
print_error "${red}${*}${normal}"
}
# Wrapper for "exit" when error.
function die() {
exit 1
}
# Wrapper for "exit" without error.
function close() {
exit 0
}
# Remove directory and its files.
function remove() {
print "Remove ${1}"
rm -rf "${1}"
}
# Remove files in a directory from a pattern.
function remove_by_pattern() {
local target_dir=${1}
local target_files=$2
if [[ ! -d $target_dir ]]; then
warning "$target_dir already removed: skipped"
return 0
fi
print "Remove $target_files in $target_dir"
find "$target_dir" -name "$target_files" -delete
}
# ---------------------------------------------- #
# Uninstall #
# ---------------------------------------------- #
function help() {
cat <<EOF
Uninstall dotfiles.
Syntax: $0
Options:
-h, --help: Show this message"
EOF
}
function uninstall_zsh() {
sudo apt remove -y zsh
remove "${HOME}"/.zinit
remove_by_pattern "${HOME}" .zcompdump*
remove "${HOME}"/.cache/p10k*
remove_by_pattern "${HOME}"/.cache p10k*
remove "${HOME}"/.p10k.zsh
remove_by_pattern "${HOME}" .zsh*
remove "${HOME}"/.config/lsd
remove "${HOME}"/.config/znt
remove "${HOME}/.cache/gitstatus"
success "✓ zinit uninstalled"
}
function uninstall_fonts() {
fonts_dir=${HOME}/.local/share/fonts
remove_by_pattern "${fonts_dir}" Fura*Code*.ttf
success "✓ Fonts uninstalled"
}
function uninstall_asdf() {
remove "${HOME}/.asdf"
remove "${HOME}/.tool-versions"
sed -i "/^. \$HOME\/.asdf\/asdf.sh$/d" "${dot_bashrc}"
sed -i "/^. \$HOME\/.asdf\/completions\/asdf.bash$/d" "${dot_bashrc}"
success "✓ asdf uninstalled"
}
function remove_wsl_gpg() {
remove "${HOME}/.gnupg/gpg-agent.conf"
gpg-connect-agent reloadagent /bye
success "✓ Setup for SSH for WSL removed"
}
function remove_wsl_ssh() {
sudo apt remove -y keychain
remove "${HOME}/.keychain"
sed -i "/^eval \"\$(keychain --eval --agents ssh id_rsa)\"$/d" "${dot_bashrc}"
success "✓ Setup for GPG for WSL removed"
}
function parse_options() {
for opt in "$@"; do
case $opt in
-h | --help)
help
close
;;
--* | -*)
alert "Error: Unknown option $opt"
help
die
;;
esac
done
}
function uninstall() {
remove_wsl_ssh
remove_wsl_gpg
uninstall_fonts
uninstall_zsh
uninstall_asdf
success "✓ Uninstall done"
}
parse_options "$@"
dot_bashrc="${HOME}/.bashrc"
uninstall "$@"