summaryrefslogtreecommitdiff
path: root/tools/upgrade.sh
diff options
context:
space:
mode:
Diffstat (limited to 'tools/upgrade.sh')
-rwxr-xr-x[-rw-r--r--]tools/upgrade.sh133
1 files changed, 100 insertions, 33 deletions
diff --git a/tools/upgrade.sh b/tools/upgrade.sh
index 25b2de27a..38fac3ce0 100644..100755
--- a/tools/upgrade.sh
+++ b/tools/upgrade.sh
@@ -1,39 +1,106 @@
+#!/usr/bin/env zsh
-# Use colors, but only if connected to a terminal, and that terminal
-# supports them.
-if which tput >/dev/null 2>&1; then
- ncolors=$(tput colors)
-fi
-if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
- RED="$(tput setaf 1)"
- GREEN="$(tput setaf 2)"
- YELLOW="$(tput setaf 3)"
- BLUE="$(tput setaf 4)"
- BOLD="$(tput bold)"
- NORMAL="$(tput sgr0)"
-else
- RED=""
- GREEN=""
- YELLOW=""
- BLUE=""
- BOLD=""
- NORMAL=""
+if [ -z "$ZSH_VERSION" ]; then
+ exec zsh "$0" "$@"
fi
-printf "${BLUE}%s${NORMAL}\n" "Updating Oh My Zsh"
cd "$ZSH"
-if git pull --rebase --stat origin master
-then
- printf '%s' "$GREEN"
- printf '%s\n' ' __ __ '
- printf '%s\n' ' ____ / /_ ____ ___ __ __ ____ _____/ /_ '
- printf '%s\n' ' / __ \/ __ \ / __ `__ \/ / / / /_ / / ___/ __ \ '
- printf '%s\n' '/ /_/ / / / / / / / / / / /_/ / / /_(__ ) / / / '
- printf '%s\n' '\____/_/ /_/ /_/ /_/ /_/\__, / /___/____/_/ /_/ '
- printf '%s\n' ' /____/ '
- printf "${BLUE}%s\n" "Hooray! Oh My Zsh has been updated and/or is at the current version."
- printf "${BLUE}${BOLD}%s${NORMAL}\n" "To keep up on the latest news and updates, follow us on twitter: https://twitter.com/ohmyzsh"
- printf "${BLUE}${BOLD}%s${NORMAL}\n" "Get your Oh My Zsh swag at: https://shop.planetargon.com/"
+
+# Use colors, but only if connected to a terminal
+# and that terminal supports them.
+
+local -a RAINBOW
+local RED GREEN YELLOW BLUE BOLD DIM UNDER RESET
+
+if [ -t 1 ]; then
+ RAINBOW=(
+ "$(printf '\033[38;5;196m')"
+ "$(printf '\033[38;5;202m')"
+ "$(printf '\033[38;5;226m')"
+ "$(printf '\033[38;5;082m')"
+ "$(printf '\033[38;5;021m')"
+ "$(printf '\033[38;5;093m')"
+ "$(printf '\033[38;5;163m')"
+ )
+
+ RED=$(printf '\033[31m')
+ GREEN=$(printf '\033[32m')
+ YELLOW=$(printf '\033[33m')
+ BLUE=$(printf '\033[34m')
+ BOLD=$(printf '\033[1m')
+ DIM=$(printf '\033[2m')
+ UNDER=$(printf '\033[4m')
+ RESET=$(printf '\033[m')
+fi
+
+# Update upstream remote to ohmyzsh org
+git remote -v | while read remote url extra; do
+ case "$url" in
+ https://github.com/robbyrussell/oh-my-zsh(|.git))
+ git remote set-url "$remote" "https://github.com/ohmyzsh/ohmyzsh.git"
+ break ;;
+ git@github.com:robbyrussell/oh-my-zsh(|.git))
+ git remote set-url "$remote" "git@github.com:ohmyzsh/ohmyzsh.git"
+ break ;;
+ esac
+done
+
+# Set git-config values known to fix git errors
+# Line endings (#4069)
+git config core.eol lf
+git config core.autocrlf false
+# zeroPaddedFilemode fsck errors (#4963)
+git config fsck.zeroPaddedFilemode ignore
+git config fetch.fsck.zeroPaddedFilemode ignore
+git config receive.fsck.zeroPaddedFilemode ignore
+# autostash on rebase (#7172)
+resetAutoStash=$(git config --bool rebase.autoStash 2>/dev/null)
+git config rebase.autoStash true
+
+local ret=0
+
+# Update Oh My Zsh
+printf "${BLUE}%s${RESET}\n" "Updating Oh My Zsh"
+last_commit=$(git rev-parse HEAD)
+if git pull --rebase --stat origin master; then
+ # Check if it was really updated or not
+ if [[ "$(git rev-parse HEAD)" = "$last_commit" ]]; then
+ message="Oh My Zsh is already at the latest version."
+ else
+ message="Hooray! Oh My Zsh has been updated!"
+
+ # Save the commit prior to updating
+ git config oh-my-zsh.lastVersion "$last_commit"
+
+ # Print changelog to the terminal
+ if [[ "$1" = --interactive ]]; then
+ "$ZSH/tools/changelog.sh" HEAD "$last_commit"
+ fi
+
+ printf "${BLUE}%s \`${BOLD}%s${RESET}${BLUE}\`${RESET}\n" "You can see the changelog with" "omz changelog"
+ fi
+
+ printf '%s %s__ %s %s %s %s %s__ %s\n' $RAINBOW $RESET
+ printf '%s ____ %s/ /_ %s ____ ___ %s__ __ %s ____ %s_____%s/ /_ %s\n' $RAINBOW $RESET
+ printf '%s / __ \%s/ __ \ %s / __ `__ \%s/ / / / %s /_ / %s/ ___/%s __ \ %s\n' $RAINBOW $RESET
+ printf '%s/ /_/ /%s / / / %s / / / / / /%s /_/ / %s / /_%s(__ )%s / / / %s\n' $RAINBOW $RESET
+ printf '%s\____/%s_/ /_/ %s /_/ /_/ /_/%s\__, / %s /___/%s____/%s_/ /_/ %s\n' $RAINBOW $RESET
+ printf '%s %s %s %s /____/ %s %s %s %s\n' $RAINBOW $RESET
+ printf '\n'
+ printf "${BLUE}%s${RESET}\n" "$message"
+ printf "${BLUE}${BOLD}%s ${UNDER}%s${RESET}\n" "To keep up with the latest news and updates, follow us on Twitter:" "https://twitter.com/ohmyzsh"
+ printf "${BLUE}${BOLD}%s ${UNDER}%s${RESET}\n" "Want to get involved in the community? Join our Discord:" "https://discord.gg/ohmyzsh"
+ printf "${BLUE}${BOLD}%s ${UNDER}%s${RESET}\n" "Get your Oh My Zsh swag at:" "https://shop.planetargon.com/collections/oh-my-zsh"
else
- printf "${RED}%s${NORMAL}\n" 'There was an error updating. Try again later?'
+ ret=$?
+ printf "${RED}%s${RESET}\n" 'There was an error updating. Try again later?'
fi
+
+# Unset git-config values set just for the upgrade
+case "$resetAutoStash" in
+ "") git config --unset rebase.autoStash ;;
+ *) git config rebase.autoStash "$resetAutoStash" ;;
+esac
+
+# Exit with `1` if the update failed
+exit $ret