forked from Bash-it/bash-it
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uninstall.sh
executable file
·50 lines (43 loc) · 2.1 KB
/
uninstall.sh
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
#!/usr/bin/env bash
#
# Since we're uninstalling, avoid depending on any other part of _Bash It_.
# I.e., hard-code colors (avoid `lib/colors.bash`), &c.
: "${BASH_IT:=${HOME?}/.bash_it}"
if [[ ! -e ~/.bashrc && ! -e ~/.bash_profile && ! -e ~/.bashrc.bak && ! -e ~/.bash_profile.bak ]]; then
echo "We can't locate your configuration files, so we can't uninstall..."
return
elif grep -F -q -- BASH_IT ~/.bashrc && grep -F -q -- BASH_IT ~/.bash_profile; then
echo "We can't figure out if Bash-it is loaded from ~/.bashrc or ~/.bash_profile..."
return
elif grep -F -q -- BASH_IT ~/.bashrc || [[ -e ~/.bashrc.bak && ! -e ~/.bashrc ]]; then
CONFIG_FILE=".bashrc"
elif grep -F -q -- BASH_IT ~/.bash_profile || [[ -e ~/.bash_profile.bak && ! -e ~/.bash_profile ]]; then
CONFIG_FILE=".bash_profile"
else
echo "Bash-it does not appear to be installed."
return
fi
# possible states:
# - both .bash* /and/ .bash*.bak, /and/ both config reference `$BASH_IT`: no solution
# - both config and bak, but only one references `$BASH_IT`: that one
# - both config, only one bak, but other references `$BASH_IT`: the other one?
# - both config, no bak, with `$BASH_IT` reference: that one
# - one config, no bak, but no `$BASH_IT` reference: wut
# - no config, with bak, with `$BASH_IT`: re-create???
# - no config, no bak: nothing.
BACKUP_FILE=$CONFIG_FILE.bak
if [[ ! -e "${HOME?}/$BACKUP_FILE" ]]; then
printf '\e[0;33m%s\e[0m\n' "Backup file ~/$BACKUP_FILE not found."
test -w "${HOME?}/$CONFIG_FILE" \
&& mv "${HOME?}/$CONFIG_FILE" "${HOME?}/$CONFIG_FILE.uninstall" \
&& printf '\e[0;32m%s\e[0m\n' "Moved your ~/$CONFIG_FILE to ~/$CONFIG_FILE.uninstall."
else
test -w "${HOME?}/$BACKUP_FILE" \
&& cp -a "${HOME?}/$BACKUP_FILE" "${HOME?}/$CONFIG_FILE" \
&& rm "${HOME?}/$BACKUP_FILE" \
&& printf '\e[0;32m%s\e[0m\n' "Your original ~/$CONFIG_FILE has been restored."
fi
printf '\n\e[0;32m%s\e[0m\n\n' "Uninstallation finished successfully! Sorry to see you go!"
printf '%s\n' "Final steps to complete the uninstallation:"
printf '\t%s\n' "-> Remove the ${BASH_IT//${HOME?}/\~} folder"
printf '\t%s\n' "-> Open a new shell/tab/terminal"