From 4886eea1aaf41f8df8b790cc7cdd4dc6c1a064b9 Mon Sep 17 00:00:00 2001 From: Jerome Charaoui Date: Mon, 17 Mar 2014 22:00:59 -0400 Subject: [PATCH] Save current shell when installing * Don't change login shell to zsh if already zsh * Restore previous shell instead of bash when uninstalling * Fix bashism in tools/uninstall.sh --- tools/install.sh | 11 +++++++++-- tools/uninstall.sh | 17 +++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/tools/install.sh b/tools/install.sh index 71e19a389..f3ba0fe67 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -32,8 +32,15 @@ sed -i -e "/export PATH=/ c\\ export PATH=\"$PATH\" " ~/.zshrc -echo "\033[0;34mTime to change your default shell to zsh!\033[0m" -chsh -s `which zsh` +[ -x "$(which getent)" ] && CURSHELL=$(getent passwd $LOGNAME | cut -d: -f7) +[ -x "$(which dscl)" ] && CURSHELL=$(dscl /Search -read "/Users/$USER" UserShell | awk '{print $2}') + +if [ -n "$CURSHELL" ] && [ "$CURSHELL" != "$(which zsh)" ]; then + echo "\033[0;34mSaving your current default shell to ~/.pre-oh-my-zsh-shell\033[0m" + [ -n "$CURSHELL" ] && echo $CURSHELL > ~/.pre-oh-my-zsh-shell + echo "\033[0;34mTime to change your default shell to zsh!\033[0m" + chsh -s `which zsh` +fi echo "\033[0;32m"' __ __ '"\033[0m" echo "\033[0;32m"' ____ / /_ ____ ___ __ __ ____ _____/ /_ '"\033[0m" diff --git a/tools/uninstall.sh b/tools/uninstall.sh index 41d601576..10dad72db 100644 --- a/tools/uninstall.sh +++ b/tools/uninstall.sh @@ -1,5 +1,5 @@ echo "Removing ~/.oh-my-zsh" -if [[ -d ~/.oh-my-zsh ]] +if [ -d ~/.oh-my-zsh ] then rm -rf ~/.oh-my-zsh fi @@ -17,12 +17,17 @@ then fi mv ~/.zshrc.pre-oh-my-zsh ~/.zshrc; +fi - source ~/.zshrc; -else - echo "Switching back to bash" - chsh -s /bin/bash - source /etc/profile +echo "Looking for previous default shell..." +if [ -f ~/.pre-oh-my-zsh-shell ] || [ -h ~/.pre-oh-my-zsh-shell ] +then + PREVSHELL=$(cat ~/.pre-oh-my-zsh-shell) + if [ -x "$PREVSHELL" ] + then + echo "Switching back to $PREVSHELL" + chsh -s $PREVSHELL + fi fi echo "Thanks for trying out Oh My Zsh. It's been uninstalled."