upgrade.sh 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 BOLD DIM UNDER 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. DIM=$(printf '\033[2m')
  26. UNDER=$(printf '\033[4m')
  27. RESET=$(printf '\033[m')
  28. fi
  29. # Update upstream remote to ohmyzsh org
  30. git remote -v | while read remote url extra; do
  31. case "$url" in
  32. https://github.com/robbyrussell/oh-my-zsh(|.git))
  33. git remote set-url "$remote" "https://github.com/ohmyzsh/ohmyzsh.git"
  34. break ;;
  35. git@github.com:robbyrussell/oh-my-zsh(|.git))
  36. git remote set-url "$remote" "git@github.com:ohmyzsh/ohmyzsh.git"
  37. break ;;
  38. esac
  39. done
  40. # Set git-config values known to fix git errors
  41. # Line endings (#4069)
  42. git config core.eol lf
  43. git config core.autocrlf false
  44. # zeroPaddedFilemode fsck errors (#4963)
  45. git config fsck.zeroPaddedFilemode ignore
  46. git config fetch.fsck.zeroPaddedFilemode ignore
  47. git config receive.fsck.zeroPaddedFilemode ignore
  48. # autostash on rebase (#7172)
  49. resetAutoStash=$(git config --bool rebase.autoStash 2>/dev/null)
  50. git config rebase.autoStash true
  51. local ret=0
  52. # Update Oh My Zsh
  53. printf "${BLUE}%s${RESET}\n" "Updating Oh My Zsh"
  54. last_commit=$(git rev-parse HEAD)
  55. if git pull --rebase --stat origin master; then
  56. # Check if it was really updated or not
  57. if [[ "$(git rev-parse HEAD)" = "$last_commit" ]]; then
  58. message="Oh My Zsh is already at the latest version."
  59. else
  60. message="Hooray! Oh My Zsh has been updated!"
  61. # Save the commit prior to updating
  62. git config oh-my-zsh.lastVersion "$last_commit"
  63. # Print changelog to the terminal
  64. if [[ "$1" = --interactive ]]; then
  65. "$ZSH/tools/changelog.sh" HEAD "$last_commit"
  66. fi
  67. printf "${BLUE}%s \`${BOLD}%s${RESET}${BLUE}\`${RESET}\n" "You can see the changelog with" "omz changelog"
  68. fi
  69. printf '%s %s__ %s %s %s %s %s__ %s\n' $RAINBOW $RESET
  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 '\n'
  76. printf "${BLUE}%s${RESET}\n" "$message"
  77. 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"
  78. printf "${BLUE}${BOLD}%s ${UNDER}%s${RESET}\n" "Want to get involved in the community? Join our Discord:" "https://discord.gg/ohmyzsh"
  79. printf "${BLUE}${BOLD}%s ${UNDER}%s${RESET}\n" "Get your Oh My Zsh swag at:" "https://shop.planetargon.com/collections/oh-my-zsh"
  80. else
  81. ret=$?
  82. printf "${RED}%s${RESET}\n" 'There was an error updating. Try again later?'
  83. fi
  84. # Unset git-config values set just for the upgrade
  85. case "$resetAutoStash" in
  86. "") git config --unset rebase.autoStash ;;
  87. *) git config rebase.autoStash "$resetAutoStash" ;;
  88. esac
  89. # Exit with `1` if the update failed
  90. exit $ret