From 43b3126b5cd2253330edf73930d37f17eaf4328f Mon Sep 17 00:00:00 2001 From: Andrew Janke Date: Wed, 23 Sep 2015 18:41:48 -0400 Subject: installer: use timestamped backups to preserve all old zshrcs --- tools/uninstall.sh | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'tools/uninstall.sh') diff --git a/tools/uninstall.sh b/tools/uninstall.sh index bf2244be8..9793be2a1 100644 --- a/tools/uninstall.sh +++ b/tools/uninstall.sh @@ -10,16 +10,17 @@ if [ -d ~/.oh-my-zsh ]; then fi echo "Looking for original zsh config..." -if [ -f ~/.zshrc.pre-oh-my-zsh ] || [ -h ~/.zshrc.pre-oh-my-zsh ]; then - echo "Found ~/.zshrc.pre-oh-my-zsh -- Restoring to ~/.zshrc"; +ZSHRC_ORIG=~/.zshrc.pre-oh-my-zsh +if [ -e "$ZSHRC_ORIG" ]; then + echo "Found $ZSHRC_ORIG -- Restoring to ~/.zshrc" - if [ -f ~/.zshrc ] || [ -h ~/.zshrc ]; then - ZSHRC_SAVE=".zshrc.omz-uninstalled-$(date +%Y%m%d%H%M%S)"; - echo "Found ~/.zshrc -- Renaming to ~/${ZSHRC_SAVE}"; - mv ~/.zshrc ~/"${ZSHRC_SAVE}"; + if [ -e ~/.zshrc ]; then + ZSHRC_SAVE=~/.zshrc.omz-uninstalled-$(date +%Y-%m-%d_%H-%M-%S) + echo "Found ~/.zshrc -- Renaming to ${ZSHRC_SAVE}" + mv ~/.zshrc "${ZSHRC_SAVE}" fi - mv ~/.zshrc.pre-oh-my-zsh ~/.zshrc; + mv "$ZSHRC_ORIG" ~/.zshrc echo "Your original zsh config was restored. Please restart your session." else -- cgit v1.2.3-70-g09d2 From 2e54ba2dfb95890c6ea32323ae14486ffc1c46ed Mon Sep 17 00:00:00 2001 From: Zach Whitten Date: Fri, 13 Oct 2017 14:33:22 -0400 Subject: installer: restore previous default shell with uninstall MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Antonio QUINTAVALLE Co-authored-by: Marc Cornellà --- tools/install.sh | 7 +++++++ tools/uninstall.sh | 21 +++++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) (limited to 'tools/uninstall.sh') diff --git a/tools/install.sh b/tools/install.sh index 3f0e468fe..15c7b7703 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -184,6 +184,13 @@ setup_shell() { fi fi + # We're going to change the default shell, so back up the current one + if [ -n $SHELL ]; then + echo $SHELL > ~/.shell.pre-oh-my-zsh + else + grep "^$USER:" /etc/passwd | awk -F: '{print $7}' > ~/.shell.pre-oh-my-zsh + fi + # Actually change the default shell to zsh if ! chsh -s "$zsh"; then error "chsh command unsuccessful. Change your default shell manually." diff --git a/tools/uninstall.sh b/tools/uninstall.sh index 9793be2a1..da31a6a14 100644 --- a/tools/uninstall.sh +++ b/tools/uninstall.sh @@ -22,14 +22,23 @@ if [ -e "$ZSHRC_ORIG" ]; then mv "$ZSHRC_ORIG" ~/.zshrc - echo "Your original zsh config was restored. Please restart your session." -else - if hash chsh >/dev/null 2>&1; then - echo "Switching back to bash" - chsh -s /bin/bash + echo "Your original zsh config was restored." +fi + +if hash chsh >/dev/null 2>&1; then + if [ -f ~/.shell.pre-oh-my-zsh ]; then + old_shell=$(cat ~/.shell.pre-oh-my-zsh) + else + old_shell=/bin/bash + fi + echo "Switching your shell back to '$old_shell':" + if chsh -s "$old_shell"; then + rm -f ~/.shell.pre-oh-my-zsh else - echo "You can edit /etc/passwd to switch your default shell back to bash" + echo "Could not change default shell. Change it manually by running chsh" + echo "or editing the /etc/passwd file." fi fi echo "Thanks for trying out Oh My Zsh. It's been uninstalled." +echo "Don't forget to restart your terminal!" -- cgit v1.2.3-70-g09d2