upgrade.sh 3.59 KB
Newer Older
1
2
#!/usr/bin/env zsh

3
if [ -z "$ZSH_VERSION" ]; then
4
  exec zsh "$0" "$@"
5
6
fi

7
8
9
10
11
12
cd "$ZSH"

# Use colors, but only if connected to a terminal
# and that terminal supports them.

local -a RAINBOW
13
local RED GREEN YELLOW BLUE BOLD DIM UNDER RESET
14

15
if [ -t 1 ]; then
16
17
18
19
20
21
22
23
24
  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')"
  )
25

26
27
28
29
30
  RED=$(printf '\033[31m')
  GREEN=$(printf '\033[32m')
  YELLOW=$(printf '\033[33m')
  BLUE=$(printf '\033[34m')
  BOLD=$(printf '\033[1m')
31
  DIM=$(printf '\033[2m')
32
  UNDER=$(printf '\033[4m')
33
  RESET=$(printf '\033[0m')
34
35
fi

36
# Update upstream remote to ohmyzsh org
37
git remote -v | while read remote url extra; do
38
39
40
41
42
43
44
45
46
  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
47
48
49
50
51
52
53
54
55

# 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
56
# autostash on rebase (#7172)
57
resetAutoStash=$(git config --bool rebase.autoStash 2>/dev/null)
58
git config rebase.autoStash true
59

60
local ret=0
61

62
# Update Oh My Zsh
63
printf "${BLUE}%s${RESET}\n" "Updating Oh My Zsh"
64
65
66
67
68
69
70
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!"
71

72
73
74
    # Save the commit prior to updating
    git config oh-my-zsh.lastVersion "$last_commit"

75
    # Print changelog to the terminal
76
    if [[ "$1" = --interactive ]]; then
77
      "$ZSH/tools/changelog.sh" HEAD "$last_commit"
78
    fi
79

80
    printf "${BLUE}%s \`${BOLD}%s${RESET}${BLUE}\`${RESET}\n" "You can see the changelog with" "omz changelog"
81
82
83
84
85
86
87
88
89
90
91
  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"
92
93
  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"
94
else
95
  ret=$?
96
  printf "${RED}%s${RESET}\n" 'There was an error updating. Try again later?'
97
fi
98
99
100
101
102
103

# Unset git-config values set just for the upgrade
case "$resetAutoStash" in
  "") git config --unset rebase.autoStash ;;
  *) git config rebase.autoStash "$resetAutoStash" ;;
esac
104
105

# Exit with `1` if the update failed
106
exit $ret