More fixes to the 'tools' shell-scripts.

This commit is contained in:
Chris2038 2011-09-16 21:30:26 +01:00
commit 08f8ce1ca8
4 changed files with 92 additions and 40 deletions

View file

@ -1,5 +1,7 @@
#!/bin/sh #!/bin/sh
source ./common
function _current_epoch() { function _current_epoch() {
echo $(($(date +%s) / 60 / 60 / 24)) echo $(($(date +%s) / 60 / 60 / 24))
} }
@ -19,15 +21,17 @@ then
epoch_diff=$(($(_current_epoch) - $LAST_EPOCH)) epoch_diff=$(($(_current_epoch) - $LAST_EPOCH))
if [ $epoch_diff -gt 6 ] if [ $epoch_diff -gt 6 ]
then then
echo "[Oh My Zsh] Would you like to check for updates?" note '[Oh My Zsh] Would you like to check for updates?'
echo "Type Y to update oh-my-zsh: \c" query 'Type Y to update oh-my-zsh:'
read line read line
if [ "$line" = Y ] || [ "$line" = y ] if [ "$line" = Y ] || [ "$line" = y ]
then then
/bin/sh $ZSH/tools/upgrade.sh ./upgrade.sh
# update the zsh file # update the zsh file
_update_zsh_update _update_zsh_update
fi fi
else
proclaim 'Updated recently.'
fi fi
else else
# create the zsh file # create the zsh file

View file

@ -1,36 +1,47 @@
################
# install.sh #
################
source ./common
if [ -d ~/.oh-my-zsh ] if [ -d ~/.oh-my-zsh ]
then 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 exit 1
fi 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 \ /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 ] if [ -f ~/.zshrc ] || [ -h ~/.zshrc ]
then 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 \ 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 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 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" info 'Copying your current PATH and adding it to the end of ~/.zshrc for you.'
echo "export PATH=$PATH" >> ~/.zshrc; echo "export PATH=$PATH" >> ~/.zshrc
echo -e "\033[0;34mYou might need to change your default shell to zsh:\033[0m" note 'You might need to change your default shell to zsh:'
echo "chsh -s $(which zsh)" shell_example 'chsh -s $(which zsh)'
echo -e "\033[0;32m"' __ __ '"\033[0m" proclaim ' __ __ '
echo -e "\033[0;32m"' ____ / /_ ____ ___ __ __ ____ _____/ /_ '"\033[0m" proclaim ' ____ / /_ ____ ___ __ __ ____ _____/ /_ '
echo -e "\033[0;32m"' / __ \/ __ \ / __ `__ \/ / / / /_ / / ___/ __ \ '"\033[0m" proclaim ' / __ \/ __ \ / __ `__ \/ / / / /_ / / ___/ __ \ '
echo -e "\033[0;32m"'/ /_/ / / / / / / / / / / /_/ / / /_(__ ) / / / '"\033[0m" proclaim '/ /_/ / / / / / / / / / / /_/ / / /_(__ ) / / / '
echo -e "\033[0;32m"'\____/_/ /_/ /_/ /_/ /_/\__, / /___/____/_/ /_/ '"\033[0m" proclaim '\____/_/ /_/ /_/ /_/ /_/\__, / /___/____/_/ /_/ '
echo -e "\033[0;32m"' /____/ '"\033[0m" proclaim ' /____/ '
proclaim ' is now installed.'
echo -e "\n\n \033[0;32m....is now installed.\033[0m"
/usr/bin/env zsh && source ~/.zshrc; /usr/bin/env zsh && source ~/.zshrc;

View file

@ -1,22 +1,41 @@
##################
# uninstall.sh #
##################
source ./common
proclaim 'Uninstalling Oh-My-Zsh'
if [[ -d ~/.oh-my-zsh ]]; then 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; rm -rf ~/.oh-my-zsh;
else else
echo "Cannot find '~/.oh-my-zsh'"; warn 'Cannot find ~/.oh-my-zsh'
exit 1 exit 2
fi fi
if [ -f ~/.zshrc.pre-oh-my-zsh ] || [ -h ~/.zshrc.pre-oh-my-zsh ] if [ -f ~/.zshrc.pre-oh-my-zsh ] || [ -h ~/.zshrc.pre-oh-my-zsh ]
then 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 \ mv ~/.zshrc.pre-oh-my-zsh ~/.zshrc \
|| ( echo "cannot restore '~/.zshrc'!"; exit 2) || ( warn 'Cannot restore ~/.zshrc!'; exit 3 )
source ~/.zshrc; source ~/.zshrc;
else else
echo "You might want to switch back to bash:"; note 'You might want to switch back to bash:'
echo "chsh -s /bin/bash"; shell_example \
echo "source /etc/profile"; 'chsh -s /bin/bash' \
'source /etc/profile'
fi 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'

View file

@ -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` 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) # Is there a better way to ensure $ZSH is passed?
echo -e "\033[0;32m"' __ __ '"\033[0m" cd "${ZSH:-$HOME/.oh-my-zsh}" \
echo -e "\033[0;32m"' ____ / /_ ____ ___ __ __ ____ _____/ /_ '"\033[0m" && git pull origin master \
echo -e "\033[0;32m"' / __ \/ __ \ / __ `__ \/ / / / /_ / / ___/ __ \ '"\033[0m" || ( warn 'Cannot upgrade Zsh!'; cd "$current_path"; exit 1 )
echo -e "\033[0;32m"'/ /_/ / / / / / / / / / / /_/ / / /_(__ ) / / / '"\033[0m"
echo -e "\033[0;32m"'\____/_/ /_/ /_/ /_/ /_/\__, / /___/____/_/ /_/ '"\033[0m" proclaim ' __ __ '
echo -e "\033[0;32m"' /____/ '"\033[0m" proclaim ' ____ / /_ ____ ___ __ __ ____ _____/ /_ '
echo -e "\033[0;34mHooray! Oh My Zsh has been updated and/or is at the current version.\033[0m" proclaim ' / __ \/ __ \ / __ `__ \/ / / / /_ / / ___/ __ \ '
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" 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" cd "$current_path"