upgrade.sh 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #!/usr/bin/env zsh
  2. if [ -z "$ZSH_VERSION" ]; then
  3. exec zsh "$0"
  4. fi
  5. cd "$ZSH"
  6. # Use colors, but only if connected to a terminal
  7. # and that terminal supports them.
  8. local -a RAINBOW
  9. local RED GREEN YELLOW BLUE UNDER BOLD RESET
  10. if [ -t 1 ]; then
  11. RAINBOW=(
  12. "$(printf '\033[38;5;196m')"
  13. "$(printf '\033[38;5;202m')"
  14. "$(printf '\033[38;5;226m')"
  15. "$(printf '\033[38;5;082m')"
  16. "$(printf '\033[38;5;021m')"
  17. "$(printf '\033[38;5;093m')"
  18. "$(printf '\033[38;5;163m')"
  19. )
  20. RED=$(printf '\033[31m')
  21. GREEN=$(printf '\033[32m')
  22. YELLOW=$(printf '\033[33m')
  23. BLUE=$(printf '\033[34m')
  24. BOLD=$(printf '\033[1m')
  25. UNDER=$(printf '\033[4m')
  26. RESET=$(printf '\033[m')
  27. fi
  28. # Update upstream remote to ohmyzsh org
  29. git remote -v | while read remote url extra; do
  30. case "$url" in
  31. https://github.com/robbyrussell/oh-my-zsh(|.git))
  32. git remote set-url "$remote" "https://github.com/ohmyzsh/ohmyzsh.git"
  33. break ;;
  34. git@github.com:robbyrussell/oh-my-zsh(|.git))
  35. git remote set-url "$remote" "git@github.com:ohmyzsh/ohmyzsh.git"
  36. break ;;
  37. esac
  38. done
  39. # Set git-config values known to fix git errors
  40. # Line endings (#4069)
  41. git config core.eol lf
  42. git config core.autocrlf false
  43. # zeroPaddedFilemode fsck errors (#4963)
  44. git config fsck.zeroPaddedFilemode ignore
  45. git config fetch.fsck.zeroPaddedFilemode ignore
  46. git config receive.fsck.zeroPaddedFilemode ignore
  47. # autostash on rebase (#7172)
  48. resetAutoStash=$(git config --bool rebase.autoStash 2>/dev/null)
  49. git config rebase.autoStash true
  50. local ret=0
  51. # Update Oh My Zsh
  52. printf "${BLUE}%s${RESET}\n" "Updating Oh My Zsh"
  53. last_commit=$(git rev-parse HEAD)
  54. if git pull --rebase --stat origin master; then
  55. # Check if it was really updated or not
  56. if [[ "$(git rev-parse HEAD)" = "$last_commit" ]]; then
  57. message="Oh My Zsh is already at the latest version."
  58. ret=80 # non-zero exit code to indicate no changes pulled
  59. else
  60. message="Hooray! Oh My Zsh has been updated!"
  61. # Display changelog with less if available, otherwise just print it to the terminal
  62. if [[ "$1" = --interactive ]]; then
  63. if (( $+commands[less] )); then
  64. "$ZSH/tools/changelog.sh" HEAD "$last_commit" --text | LESS= command less -R
  65. else
  66. "$ZSH/tools/changelog.sh" HEAD "$last_commit"
  67. fi
  68. fi
  69. fi
  70. printf '%s %s__ %s %s %s %s %s__ %s\n' $RAINBOW $RESET
  71. printf '%s ____ %s/ /_ %s ____ ___ %s__ __ %s ____ %s_____%s/ /_ %s\n' $RAINBOW $RESET
  72. printf '%s / __ \%s/ __ \ %s / __ `__ \%s/ / / / %s /_ / %s/ ___/%s __ \ %s\n' $RAINBOW $RESET
  73. printf '%s/ /_/ /%s / / / %s / / / / / /%s /_/ / %s / /_%s(__ )%s / / / %s\n' $RAINBOW $RESET
  74. printf '%s\____/%s_/ /_/ %s /_/ /_/ /_/%s\__, / %s /___/%s____/%s_/ /_/ %s\n' $RAINBOW $RESET
  75. printf '%s %s %s %s /____/ %s %s %s %s\n' $RAINBOW $RESET
  76. printf '\n'
  77. printf "${BLUE}%s${RESET}\n" "$message"
  78. 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"
  79. printf "${BLUE}${BOLD}%s ${UNDER}%s${RESET}\n" "Want to get involved in the community? Join our Discord:" "https://discord.gg/ohmyzsh"
  80. printf "${BLUE}${BOLD}%s ${UNDER}%s${RESET}\n" "Get your Oh My Zsh swag at:" "https://shop.planetargon.com/collections/oh-my-zsh"
  81. else
  82. ret=$?
  83. printf "${RED}%s${RESET}\n" 'There was an error updating. Try again later?'
  84. fi
  85. # Unset git-config values set just for the upgrade
  86. case "$resetAutoStash" in
  87. "") git config --unset rebase.autoStash ;;
  88. *) git config rebase.autoStash "$resetAutoStash" ;;
  89. esac
  90. # Exit with `1` if the update failed
  91. exit $ret