3 # Protect against running with shells other than zsh
4 if [ -z "$ZSH_VERSION" ]; then
8 # Protect against unwanted sourcing
9 case "$ZSH_EVAL_CONTEXT" in
10 *:file) echo "error: this file should not be sourced" && return ;;
15 # Use colors, but only if connected to a terminal
16 # and that terminal supports them.
18 # The [ -t 1 ] check only works when the function is not called from
19 # a subshell (like in `$(...)` or `(...)`, so this hack redefines the
20 # function at the top level to always return false when stdout is not
32 # This function uses the logic from supports-hyperlinks[1][2], which is
33 # made by Kat Marchán (@zkat) and licensed under the Apache License 2.0.
34 # [1] https://github.com/zkat/supports-hyperlinks
35 # [2] https://crates.io/crates/supports-hyperlinks
37 # Copyright (c) 2021 Kat Marchán
39 # Licensed under the Apache License, Version 2.0 (the "License");
40 # you may not use this file except in compliance with the License.
41 # You may obtain a copy of the License at
43 # http://www.apache.org/licenses/LICENSE-2.0
45 # Unless required by applicable law or agreed to in writing, software
46 # distributed under the License is distributed on an "AS IS" BASIS,
47 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
48 # See the License for the specific language governing permissions and
49 # limitations under the License.
50 supports_hyperlinks() {
51 # $FORCE_HYPERLINK must be set and be non-zero (this acts as a logic bypass)
52 if [ -n "$FORCE_HYPERLINK" ]; then
53 [ "$FORCE_HYPERLINK" != 0 ]
57 # If stdout is not a tty, it doesn't support hyperlinks
60 # DomTerm terminal emulator (domterm.org)
61 if [ -n "$DOMTERM" ]; then
65 # VTE-based terminals above v0.50 (Gnome Terminal, Guake, ROXTerm, etc)
66 if [ -n "$VTE_VERSION" ]; then
67 [ $VTE_VERSION -ge 5000 ]
71 # If $TERM_PROGRAM is set, these terminals support hyperlinks
72 case "$TERM_PROGRAM" in
73 Hyper|iTerm.app|terminology|WezTerm) return 0 ;;
76 # kitty supports hyperlinks
77 if [ "$TERM" = xterm-kitty ]; then
81 # Windows Terminal also supports hyperlinks
82 if [ -n "$WT_SESSION" ]; then
86 # Konsole supports hyperlinks, but it's an opt-in setting that can't be detected
87 # https://github.com/ohmyzsh/ohmyzsh/issues/10964
88 # if [ -n "$KONSOLE_VERSION" ]; then
95 # Adapted from code and information by Anton Kochkov (@XVilka)
96 # Source: https://gist.github.com/XVilka/8346728
97 supports_truecolor() {
99 truecolor|24bit) return 0 ;;
107 screen-truecolor) return 0 ;;
114 # $1: text, $2: url, $3: fallback mode
115 if supports_hyperlinks; then
116 printf '\033]8;;%s\033\\%s\033]8;;\033\\\n' "$2" "$1"
121 --text) printf '%s\n' "$1" ;;
122 --url|*) fmt_underline "$2" ;;
127 is_tty && printf '\033[4m%s\033[24m\n' "$*" || printf '%s\n' "$*"
130 setopt typeset_silent
134 if supports_truecolor; then
136 "$(printf '\033[38;2;255;0;0m')"
137 "$(printf '\033[38;2;255;97;0m')"
138 "$(printf '\033[38;2;247;255;0m')"
139 "$(printf '\033[38;2;0;255;30m')"
140 "$(printf '\033[38;2;77;0;255m')"
141 "$(printf '\033[38;2;168;0;255m')"
142 "$(printf '\033[38;2;245;0;172m')"
146 "$(printf '\033[38;5;196m')"
147 "$(printf '\033[38;5;202m')"
148 "$(printf '\033[38;5;226m')"
149 "$(printf '\033[38;5;082m')"
150 "$(printf '\033[38;5;021m')"
151 "$(printf '\033[38;5;093m')"
152 "$(printf '\033[38;5;163m')"
156 RED=$(printf '\033[31m')
157 GREEN=$(printf '\033[32m')
158 YELLOW=$(printf '\033[33m')
159 BLUE=$(printf '\033[34m')
160 BOLD=$(printf '\033[1m')
161 RESET=$(printf '\033[0m')
164 # Update upstream remote to ohmyzsh org
165 git remote -v | while read remote url extra; do
167 https://github.com/robbyrussell/oh-my-zsh(|.git))
168 git remote set-url "$remote" "https://github.com/ohmyzsh/ohmyzsh.git"
170 git@github.com:robbyrussell/oh-my-zsh(|.git))
171 git remote set-url "$remote" "git@github.com:ohmyzsh/ohmyzsh.git"
173 # Update out-of-date "unauthenticated git protocol on port 9418" to https
174 git://github.com/robbyrussell/oh-my-zsh(|.git))
175 git remote set-url "$remote" "https://github.com/ohmyzsh/ohmyzsh.git"
180 # Set git-config values known to fix git errors
181 # Line endings (#4069)
182 git config core.eol lf
183 git config core.autocrlf false
184 # zeroPaddedFilemode fsck errors (#4963)
185 git config fsck.zeroPaddedFilemode ignore
186 git config fetch.fsck.zeroPaddedFilemode ignore
187 git config receive.fsck.zeroPaddedFilemode ignore
188 # autostash on rebase (#7172)
189 resetAutoStash=$(git config --bool rebase.autoStash 2>/dev/null)
190 git config rebase.autoStash true
194 # repository settings
195 remote=${"$(git config --local oh-my-zsh.remote)":-origin}
196 branch=${"$(git config --local oh-my-zsh.branch)":-master}
199 last_head=$(git symbolic-ref --quiet --short HEAD || git rev-parse HEAD)
200 # checkout update branch
201 git checkout -q "$branch" -- || exit 1
202 # branch commit before update (used in changelog)
203 last_commit=$(git rev-parse "$branch")
206 printf "${BLUE}%s${RESET}\n" "Updating Oh My Zsh"
207 if LANG= git pull --quiet --rebase $remote $branch; then
208 # Check if it was really updated or not
209 if [[ "$(git rev-parse HEAD)" = "$last_commit" ]]; then
210 message="Oh My Zsh is already at the latest version."
212 message="Hooray! Oh My Zsh has been updated!"
214 # Save the commit prior to updating
215 git config oh-my-zsh.lastVersion "$last_commit"
217 # Print changelog to the terminal
218 if [[ "$1" = --interactive ]]; then
219 "$ZSH/tools/changelog.sh" HEAD "$last_commit"
222 printf "${BLUE}%s \`${BOLD}%s${RESET}${BLUE}\`${RESET}\n" "You can see the changelog with" "omz changelog"
225 printf '%s %s__ %s %s %s %s %s__ %s\n' $RAINBOW $RESET
226 printf '%s ____ %s/ /_ %s ____ ___ %s__ __ %s ____ %s_____%s/ /_ %s\n' $RAINBOW $RESET
227 printf '%s / __ \\%s/ __ \\ %s / __ `__ \\%s/ / / / %s /_ / %s/ ___/%s __ \\ %s\n' $RAINBOW $RESET
228 printf '%s/ /_/ /%s / / / %s / / / / / /%s /_/ / %s / /_%s(__ )%s / / / %s\n' $RAINBOW $RESET
229 printf '%s\\____/%s_/ /_/ %s /_/ /_/ /_/%s\\__, / %s /___/%s____/%s_/ /_/ %s\n' $RAINBOW $RESET
230 printf '%s %s %s %s /____/ %s %s %s %s\n' $RAINBOW $RESET
232 printf "${BLUE}%s${RESET}\n\n" "$message"
233 printf "${BLUE}${BOLD}%s %s${RESET}\n" "To keep up with the latest news and updates, follow us on Twitter:" "$(fmt_link @ohmyzsh https://twitter.com/ohmyzsh)"
234 printf "${BLUE}${BOLD}%s %s${RESET}\n" "Want to get involved in the community? Join our Discord:" "$(fmt_link "Discord server" https://discord.gg/ohmyzsh)"
235 printf "${BLUE}${BOLD}%s %s${RESET}\n" "Get your Oh My Zsh swag at:" "$(fmt_link "Planet Argon Shop" https://shop.planetargon.com/collections/oh-my-zsh)"
238 printf "${RED}%s${RESET}\n" 'There was an error updating. Try again later?'
241 # go back to HEAD previous to update
242 git checkout -q "$last_head" --
244 # Unset git-config values set just for the upgrade
245 case "$resetAutoStash" in
246 "") git config --unset rebase.autoStash ;;
247 *) git config rebase.autoStash "$resetAutoStash" ;;
250 # Exit with `1` if the update failed