diff options
author | Tuowen Zhao <ztuowen@gmail.com> | 2021-12-18 17:46:06 -0600 |
---|---|---|
committer | Tuowen Zhao <ztuowen@gmail.com> | 2021-12-18 17:46:06 -0600 |
commit | 1bc186dabe12b3d01b2257e82f3a104c48b8b3c7 (patch) | |
tree | 54576312318c406b6ce2a35423198fcc92c8bf71 /tools | |
parent | 2a977876c6e85847652f097cc128e4ed5bec147a (diff) | |
parent | 904f8685f75ff5dd3f544f8c6f2cabb8e5952e9a (diff) | |
download | zsh-1bc186dabe12b3d01b2257e82f3a104c48b8b3c7.tar.gz zsh-1bc186dabe12b3d01b2257e82f3a104c48b8b3c7.tar.bz2 zsh-1bc186dabe12b3d01b2257e82f3a104c48b8b3c7.zip |
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'tools')
-rw-r--r-- | tools/check_for_upgrade.sh | 46 | ||||
-rwxr-xr-x | tools/install.sh | 12 | ||||
-rwxr-xr-x | tools/upgrade.sh | 12 |
3 files changed, 37 insertions, 33 deletions
diff --git a/tools/check_for_upgrade.sh b/tools/check_for_upgrade.sh index 8264762b6..293f48edf 100644 --- a/tools/check_for_upgrade.sh +++ b/tools/check_for_upgrade.sh @@ -34,11 +34,11 @@ function current_epoch() { function is_update_available() { local branch - branch=${"$(git -C "$ZSH" config --local oh-my-zsh.branch)":-master} + branch=${"$(cd "$ZSH"; git config --local oh-my-zsh.branch)":-master} local remote remote_url remote_repo - remote=${"$(git -C "$ZSH" config --local oh-my-zsh.remote)":-origin} - remote_url=$(git -C "$ZSH" config remote.$remote.url) + remote=${"$(cd "$ZSH"; git config --local oh-my-zsh.remote)":-origin} + remote_url=$(cd "$ZSH"; git config remote.$remote.url) local repo case "$remote_url" in @@ -56,25 +56,22 @@ function is_update_available() { # Get local HEAD. If this fails assume there are updates local local_head - local_head=$(git -C "$ZSH" rev-parse $branch 2>/dev/null) || return 0 + local_head=$(cd "$ZSH"; git rev-parse $branch 2>/dev/null) || return 0 - # Get remote HEAD. If we can't get it assume there are updates unless there is no connection: - # - curl: 6 (could not resolve) or 7 (could not connect) - # - wget: 4 (network unreachable) - # - fetch: 1 (no route to host) - local remote_head ret + # Get remote HEAD. If no suitable command is found assume there are updates + # On any other error, skip the update (connection may be down) + local remote_head remote_head=$( - curl -fsSL -H 'Accept: application/vnd.github.v3.sha' $api_url 2>/dev/null || { - [[ $? -eq 6 || $? -eq 7 ]] && exit 1 - } || wget -O- --header='Accept: application/vnd.github.v3.sha' $api_url 2>/dev/null || { - [[ $? -eq 4 ]] && exit 1 - } || HTTP_ACCEPT='Accept: application/vnd.github.v3.sha' fetch -o - $api_url 2>/dev/null || { - [[ $? -eq 1 ]] && exit 1 - } || exit 0 - ) - - # If can't fetch remote HEAD, return exit code - ret=$?; [[ -n "$remote_head" ]] || return $ret + if (( ${+commands[curl]} )); then + curl -fsSL -H 'Accept: application/vnd.github.v3.sha' $api_url 2>/dev/null + elif (( ${+commands[wget]} )); then + wget -O- --header='Accept: application/vnd.github.v3.sha' $api_url 2>/dev/null + elif (( ${+commands[fetch]} )); then + HTTP_ACCEPT='Accept: application/vnd.github.v3.sha' fetch -o - $api_url 2>/dev/null + else + exit 0 + fi + ) || return 1 # Compare local and remote HEADs [[ "$local_head" != "$remote_head" ]] @@ -136,6 +133,12 @@ function update_ohmyzsh() { return fi + # Test if Oh My Zsh directory is a git repository + if ! (cd "$ZSH" && LANG= git rev-parse &>/dev/null); then + echo >&2 "[oh-my-zsh] Can't update: not a git repository." + return + fi + # Check if there are updates available before proceeding if ! is_update_available; then return @@ -157,7 +160,8 @@ function update_ohmyzsh() { [[ "$option" != $'\n' ]] && echo case "$option" in [yY$'\n']) update_ohmyzsh ;; - [nN]) update_last_updated_file ;; + [nN]) update_last_updated_file ;& + *) echo "[oh-my-zsh] You can update manually by running \`omz update\`" ;; esac fi } diff --git a/tools/install.sh b/tools/install.sh index 7704107c8..47166059d 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -311,7 +311,7 @@ EOF # 1. Use the most preceding one based on $PATH, then check that it's in the shells file # 2. If that fails, get a zsh path from the shells file, then check it actually exists if ! zsh=$(command -v zsh) || ! grep -qx "$zsh" "$shells_file"; then - if ! zsh=$(grep '^/.*/zsh$' "$shells_file" | tail -1) || [ ! -f "$zsh" ]; then + if ! zsh=$(grep '^/.*/zsh$' "$shells_file" | tail -n 1) || [ ! -f "$zsh" ]; then fmt_error "no zsh binary found or not present in '$shells_file'" fmt_error "change your default shell manually." return @@ -339,11 +339,11 @@ EOF # shellcheck disable=SC2183 # printf string has more %s than arguments ($RAINBOW expands to multiple arguments) print_success() { - 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 '%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....is now installed!%s\n' $RAINBOW $GREEN $RESET printf '\n' printf '\n' diff --git a/tools/upgrade.sh b/tools/upgrade.sh index 7642858fe..994ffe9c9 100755 --- a/tools/upgrade.sh +++ b/tools/upgrade.sh @@ -182,12 +182,12 @@ if git pull --rebase --stat $remote $branch; then 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 '%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\n" "$message" 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)" |