installer: restore previous default shell with uninstall
Co-authored-by: Antonio QUINTAVALLE <antonio.quintavalle@amadeus.com>
Co-authored-by: Marc Cornellà <marc.cornella@live.com>
Diff
1diff --git a/tools/install.sh b/tools/install.sh
2index 3f0e468fe8ebcfcd7fe0c83c4426e87e58c405ee..15c7b770310230a465a824478fbc56e026b8cf8e 100755
3--- a/tools/install.sh
4+++ b/tools/install.sh
5@@ -184,6 +184,13 @@ setup_shell() {
6 fi
7 fi
8 9+ # We're going to change the default shell, so back up the current one
10+ if [ -n $SHELL ]; then
11+ echo $SHELL > ~/.shell.pre-oh-my-zsh
12+ else
13+ grep "^$USER:" /etc/passwd | awk -F: '{print $7}' > ~/.shell.pre-oh-my-zsh
14+ fi
15+
16 # Actually change the default shell to zsh
17 if ! chsh -s "$zsh"; then
18 error "chsh command unsuccessful. Change your default shell manually."
19diff --git a/tools/uninstall.sh b/tools/uninstall.sh
20index 9793be2a10a5da13f2f0dcb9346bbc3f606efbbf..da31a6a14d6520654aa7a4f590cc4a9e7706573f 100644
21--- a/tools/uninstall.sh
22+++ b/tools/uninstall.sh
23@@ -22,14 +22,23 @@ if [ -e "$ZSHRC_ORIG" ]; then
2425 mv "$ZSHRC_ORIG" ~/.zshrc
2627- echo "Your original zsh config was restored. Please restart your session."
28-else
29- if hash chsh >/dev/null 2>&1; then
30- echo "Switching back to bash"
31- chsh -s /bin/bash
32+ echo "Your original zsh config was restored."
33+fi
34+
35+if hash chsh >/dev/null 2>&1; then
36+ if [ -f ~/.shell.pre-oh-my-zsh ]; then
37+ old_shell=$(cat ~/.shell.pre-oh-my-zsh)
38+ else
39+ old_shell=/bin/bash
40+ fi
41+ echo "Switching your shell back to '$old_shell':"
42+ if chsh -s "$old_shell"; then
43+ rm -f ~/.shell.pre-oh-my-zsh
44 else
45- echo "You can edit /etc/passwd to switch your default shell back to bash"
46+ echo "Could not change default shell. Change it manually by running chsh"
47+ echo "or editing the /etc/passwd file."
48 fi
49 fi
5051 echo "Thanks for trying out Oh My Zsh. It's been uninstalled."
52+echo "Don't forget to restart your terminal!"