diff --git a/tools/check_for_upgrade.sh b/tools/check_for_upgrade.sh index e1e4eb99f..4193f7a83 100755 --- a/tools/check_for_upgrade.sh +++ b/tools/check_for_upgrade.sh @@ -1,5 +1,7 @@ #!/bin/sh +source ./common + function _current_epoch() { echo $(($(date +%s) / 60 / 60 / 24)) } @@ -19,15 +21,17 @@ then epoch_diff=$(($(_current_epoch) - $LAST_EPOCH)) if [ $epoch_diff -gt 6 ] then - echo "[Oh My Zsh] Would you like to check for updates?" - echo "Type Y to update oh-my-zsh: \c" + note '[Oh My Zsh] Would you like to check for updates?' + query 'Type Y to update oh-my-zsh:' read line if [ "$line" = Y ] || [ "$line" = y ] then - /bin/sh $ZSH/tools/upgrade.sh + ./upgrade.sh # update the zsh file _update_zsh_update fi + else + proclaim 'Updated recently.' fi else # create the zsh file diff --git a/tools/install.sh b/tools/install.sh index 761c91fcd..da837d24c 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -1,36 +1,47 @@ + + ################ + # install.sh # + ################ + +source ./common + if [ -d ~/.oh-my-zsh ] then - echo -e "\033[0;33mYou already have Oh My Zsh installed.\033[0m You'll need to remove ~/.oh-my-zsh if you want to install"; + proclaim 'You already have Oh My Zsh installed' + note 'You\47ll need to remove ~/.oh-my-zsh if you want to install' exit 1 fi -echo -e "\033[0;34mCloning Oh My Zsh...\033[0m" +proclaim 'Installing Oh-My-Zsh' +info 'Cloning Oh My Zsh...' /usr/bin/env git clone https://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh \ - || ( echo "Couldn't clone repository."; exit 2) + || ( warn 'Couldn\47t clone repository.'; exit 2) -echo -e "\033[0;34mLooking for an existing zsh config...\033[0m" +info 'Looking for an existing zsh config...' if [ -f ~/.zshrc ] || [ -h ~/.zshrc ] then - echo -e "\033[0;33mFound ~/.zshrc.\033[0m \033[0;32]Backing up to ~/.zshrc.pre-oh-my-zsh\033[0m"; + info 'Found ~/.zshrc.' + info 'Backing up to ~/.zshrc.pre-oh-my-zsh' cp -n ~/.zshrc ~/.zshrc.pre-oh-my-zsh && rm ~/.zshrc \ - || ( echo "Couldn't backup .zshrc!"; exit 3) + || ( warn 'Couldn\47t backup .zshrc!'; exit 3) fi -echo -e "\033[0;34mUsing the Oh My Zsh template file and adding it to ~/.zshrc\033[0m" +info 'Using the Oh My Zsh template file and adding it to ~/.zshrc' cp -n ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc || exit 4 -echo -e "\033[0;34mCopying your current PATH and adding it to the end of ~/.zshrc for you.\033[0m" -echo "export PATH=$PATH" >> ~/.zshrc; +info 'Copying your current PATH and adding it to the end of ~/.zshrc for you.' +echo "export PATH=$PATH" >> ~/.zshrc -echo -e "\033[0;34mYou might need to change your default shell to zsh:\033[0m" -echo "chsh -s $(which zsh)" +note 'You might need to change your default shell to zsh:' +shell_example 'chsh -s $(which zsh)' -echo -e "\033[0;32m"' __ __ '"\033[0m" -echo -e "\033[0;32m"' ____ / /_ ____ ___ __ __ ____ _____/ /_ '"\033[0m" -echo -e "\033[0;32m"' / __ \/ __ \ / __ `__ \/ / / / /_ / / ___/ __ \ '"\033[0m" -echo -e "\033[0;32m"'/ /_/ / / / / / / / / / / /_/ / / /_(__ ) / / / '"\033[0m" -echo -e "\033[0;32m"'\____/_/ /_/ /_/ /_/ /_/\__, / /___/____/_/ /_/ '"\033[0m" -echo -e "\033[0;32m"' /____/ '"\033[0m" +proclaim ' __ __ ' +proclaim ' ____ / /_ ____ ___ __ __ ____ _____/ /_ ' +proclaim ' / __ \/ __ \ / __ `__ \/ / / / /_ / / ___/ __ \ ' +proclaim '/ /_/ / / / / / / / / / / /_/ / / /_(__ ) / / / ' +proclaim '\____/_/ /_/ /_/ /_/ /_/\__, / /___/____/_/ /_/ ' +proclaim ' /____/ ' +proclaim ' is now installed.' -echo -e "\n\n \033[0;32m....is now installed.\033[0m" /usr/bin/env zsh && source ~/.zshrc; + diff --git a/tools/uninstall.sh b/tools/uninstall.sh index 9f66f6242..3164335b7 100755 --- a/tools/uninstall.sh +++ b/tools/uninstall.sh @@ -1,22 +1,41 @@ + + ################## + # uninstall.sh # + ################## + +source ./common +proclaim 'Uninstalling Oh-My-Zsh' + if [[ -d ~/.oh-my-zsh ]]; then - echo "Removing '~/.oh-my-zsh'"; + changes=`diff --unchanged-group-format='' --suppress-common-lines ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc` + changes=`echo "$changes" | grep -v "^export PATH=$PATH$"` + if [ ! -z "$changes" ]; then + info 'Appending changes to ~/.zshrc to ~/.zshrc.changes:' + text "$changes" + echo "$changes" >> ~/.zshrc.changes \ + || ( warn 'Cannot append to ~/.zshrc.changes!'; exit 1 ) + fi + info 'Removing ~/.zshrc' + rm ~/.zshrc + info 'Removing ~/.oh-my-zsh' rm -rf ~/.oh-my-zsh; else - echo "Cannot find '~/.oh-my-zsh'"; - exit 1 + warn 'Cannot find ~/.oh-my-zsh' + exit 2 fi if [ -f ~/.zshrc.pre-oh-my-zsh ] || [ -h ~/.zshrc.pre-oh-my-zsh ] then - echo "Found '~/.zshrc.pre-oh-my-zsh', Restoring to ~/.zshrc"; + info 'Found ~/.zshrc.pre-oh-my-zsh, Restoring to ~/.zshrc' mv ~/.zshrc.pre-oh-my-zsh ~/.zshrc \ - || ( echo "cannot restore '~/.zshrc'!"; exit 2) + || ( warn 'Cannot restore ~/.zshrc!'; exit 3 ) source ~/.zshrc; else - echo "You might want to switch back to bash:"; - echo "chsh -s /bin/bash"; - echo "source /etc/profile"; + note 'You might want to switch back to bash:' + shell_example \ + 'chsh -s /bin/bash' \ + 'source /etc/profile' fi -echo "Thanks for trying out 'Oh My Zsh', It is no longer installed."; +proclaim 'Thanks for trying out \47Oh My Zsh\47, It is no longer installed' diff --git a/tools/upgrade.sh b/tools/upgrade.sh index 395a21d9e..cf3400426 100755 --- a/tools/upgrade.sh +++ b/tools/upgrade.sh @@ -1,12 +1,30 @@ + +source ./common + +if [ ! -d ~/.oh-my-zsh ]; then + warn 'Cannot find ~/.oh-my-zsh' + exit 1 +fi +proclaim 'Upgrading Oh My Zsh' + +# I think pushd/popd might be cleaner, +# but more of a risk if they are over-ridden? current_path=`pwd` -echo -e "\033[0;34mUpgrading Oh My Zsh\033[0m" -cd "${ZSH:-$HOME/.oh-my-zsh}" && git pull origin master || (echo "Cannot upgrade ZSH!"; exit 1) -echo -e "\033[0;32m"' __ __ '"\033[0m" -echo -e "\033[0;32m"' ____ / /_ ____ ___ __ __ ____ _____/ /_ '"\033[0m" -echo -e "\033[0;32m"' / __ \/ __ \ / __ `__ \/ / / / /_ / / ___/ __ \ '"\033[0m" -echo -e "\033[0;32m"'/ /_/ / / / / / / / / / / /_/ / / /_(__ ) / / / '"\033[0m" -echo -e "\033[0;32m"'\____/_/ /_/ /_/ /_/ /_/\__, / /___/____/_/ /_/ '"\033[0m" -echo -e "\033[0;32m"' /____/ '"\033[0m" -echo -e "\033[0;34mHooray! Oh My Zsh has been updated and/or is at the current version.\033[0m" -echo -e "\033[0;34mTo keep up on the latest, be sure to follow Oh My Zsh on twitter: \033[1mhttp://twitter.com/ohmyzsh\033[0m" + +# Is there a better way to ensure $ZSH is passed? +cd "${ZSH:-$HOME/.oh-my-zsh}" \ + && git pull origin master \ + || ( warn 'Cannot upgrade Zsh!'; cd "$current_path"; exit 1 ) + +proclaim ' __ __ ' +proclaim ' ____ / /_ ____ ___ __ __ ____ _____/ /_ ' +proclaim ' / __ \/ __ \ / __ `__ \/ / / / /_ / / ___/ __ \ ' +proclaim '/ /_/ / / / / / / / / / / /_/ / / /_(__ ) / / / ' +proclaim '\____/_/ /_/ /_/ /_/ /_/\__, / /___/____/_/ /_/ ' +proclaim ' /____/ ' +proclaim 'Hooray! Oh My Zsh has been updated and/or is at the current version.' +proclaim 'To keep up on the latest, be sure to follow Oh My Zsh on twitter:' +proclaim "${COLOR_WHITE}http://twitter.com/ohmyzsh" + cd "$current_path" +