安装oh my zsh失败:curl: (7) Failed t

2020-05-22  本文已影响0人  _moses

记得以前macOS 10.14安装oh my zsh是没问题的,新mac上是macOS 10.15,安装oh my zsh会报错curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused
百度了很多办法都不能解决。

后来看到了这篇文章下载加速Clone、AWS、Git镜像试了试果然成功了(不用翻墙)

## GitHub Start

192.30.253.112 github.com
192.30.253.113 github.com
151.101.184.133 assets-cdn.github.com
151.101.185.194 github.global.ssl.fastly.net 


192.30.253.112 github.com
192.30.253.113 github.com
192.30.253.118 gist.github.com
151.101.185.194 github.global.ssl.fastly.net
151.101.129.194 github.global.ssl.fastly.net
151.101.65.194 github.global.ssl.fastly.net
151.101.1.194 github.global.ssl.fastly.net
151.101.193.194 github.global.ssl.fastly.net
151.101.77.194 github.global.ssl.fastly.net
151.101.229.194 github.global.ssl.fastly.net
151.101.113.194 github.global.ssl.fastly.net
151.101.196.133 assets-cdn.github.com
151.101.24.133 assets-cdn.github.com
185.199.111.153 assets-cdn.github.com
185.199.110.153 assets-cdn.github.com
185.199.108.153 assets-cdn.github.com
185.199.109.153 assets-cdn.github.com
151.101.112.133 assets-cdn.github.com

151.101.112.133 avatars0.githubusercontent.com
151.101.112.133 avatars1.githubusercontent.com
151.101.184.133 avatars2.githubusercontent.com
151.101.12.133 avatars3.githubusercontent.com
151.101.12.133 avatars4.githubusercontent.com
151.101.184.133 avatars5.githubusercontent.com
151.101.184.133 avatars6.githubusercontent.com
151.101.184.133 avatars7.githubusercontent.com
151.101.12.133 avatars8.githubusercontent.com

151.101.184.133 raw.githubusercontent.com
151.101.112.133 gist.githubusercontent.com
151.101.184.133 cloud.githubusercontent.com
151.101.112.133 camo.githubusercontent.com
52.216.227.168 github-cloud.s3.amazonaws.com

192.30.253.112 github.com
185.199.108.153 assets-cdn.github.com
151.101.185.194 github.global.ssl.fastly.net
140.82.113.10 codeload.github.com

## GitHub End

闲麻烦不想配置hosts,也可以直接执行下面这些命令,把这些命令拷贝到sh文件然后执行即可。这些命令就是https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh里面的命令,拷贝出来方便以后使用

#!/bin/sh

set -e

ZSH=${ZSH:-~/.oh-my-zsh}
REPO=${REPO:-ohmyzsh/ohmyzsh}
REMOTE=${REMOTE:-https://github.com/${REPO}.git}
BRANCH=${BRANCH:-master}

CHSH=${CHSH:-yes}
RUNZSH=${RUNZSH:-yes}
KEEP_ZSHRC=${KEEP_ZSHRC:-no}


command_exists() {
    command -v "$@" >/dev/null 2>&1
}

error() {
    echo ${RED}"Error: $@"${RESET} >&2
}

setup_color() {
    
    if [ -t 1 ]; then
        RED=$(printf '\033[31m')
        GREEN=$(printf '\033[32m')
        YELLOW=$(printf '\033[33m')
        BLUE=$(printf '\033[34m')
        BOLD=$(printf '\033[1m')
        RESET=$(printf '\033[m')
    else
        RED=""
        GREEN=""
        YELLOW=""
        BLUE=""
        BOLD=""
        RESET=""
    fi
}

setup_ohmyzsh() {
    
    umask g-w,o-w

    echo "${BLUE}Cloning Oh My Zsh...${RESET}"

    command_exists git || {
        error "git is not installed"
        exit 1
    }

    if [ "$OSTYPE" = cygwin ] && git --version | grep -q msysgit; then
        error "Windows/MSYS Git is not supported on Cygwin"
        error "Make sure the Cygwin git package is installed and is first on the \$PATH"
        exit 1
    fi

    git clone -c core.eol=lf -c core.autocrlf=false \
        -c fsck.zeroPaddedFilemode=ignore \
        -c fetch.fsck.zeroPaddedFilemode=ignore \
        -c receive.fsck.zeroPaddedFilemode=ignore \
        --depth=1 --branch "$BRANCH" "$REMOTE" "$ZSH" || {
        error "git clone of oh-my-zsh repo failed"
        exit 1
    }

    echo
}

setup_zshrc() {
    
    echo "${BLUE}Looking for an existing zsh config...${RESET}"

    OLD_ZSHRC=~/.zshrc.pre-oh-my-zsh
    if [ -f ~/.zshrc ] || [ -h ~/.zshrc ]; then
        
        if [ $KEEP_ZSHRC = yes ]; then
            echo "${YELLOW}Found ~/.zshrc.${RESET} ${GREEN}Keeping...${RESET}"
            return
        fi
        if [ -e "$OLD_ZSHRC" ]; then
            OLD_OLD_ZSHRC="${OLD_ZSHRC}-$(date +%Y-%m-%d_%H-%M-%S)"
            if [ -e "$OLD_OLD_ZSHRC" ]; then
                error "$OLD_OLD_ZSHRC exists. Can't back up ${OLD_ZSHRC}"
                error "re-run the installer again in a couple of seconds"
                exit 1
            fi
            mv "$OLD_ZSHRC" "${OLD_OLD_ZSHRC}"

            echo "${YELLOW}Found old ~/.zshrc.pre-oh-my-zsh." \
                "${GREEN}Backing up to ${OLD_OLD_ZSHRC}${RESET}"
        fi
        echo "${YELLOW}Found ~/.zshrc.${RESET} ${GREEN}Backing up to ${OLD_ZSHRC}${RESET}"
        mv ~/.zshrc "$OLD_ZSHRC"
    fi

    echo "${GREEN}Using the Oh My Zsh template file and adding it to ~/.zshrc.${RESET}"

    sed "/^export ZSH=/ c\\
export ZSH=\"$ZSH\"
" "$ZSH/templates/zshrc.zsh-template" > ~/.zshrc-omztemp
    mv -f ~/.zshrc-omztemp ~/.zshrc

    echo
}

setup_shell() {

    if [ $CHSH = no ]; then
        return
    fi

    if [ "$(basename "$SHELL")" = "zsh" ]; then
        return
    fi

    if ! command_exists chsh; then
        cat <<-EOF
            I cannot change your shell automatically because this system does not have chsh.
            ${BLUE}Please manually change your default shell to zsh${RESET}
        EOF
        return
    fi

    echo "${BLUE}Time to change your default shell to zsh:${RESET}"

    printf "${YELLOW}Do you want to change your default shell to zsh? [Y/n]${RESET} "
    read opt
    case $opt in
        y*|Y*|"") echo "Changing the shell..." ;;
        n*|N*) echo "Shell change skipped."; return ;;
        *) echo "Invalid choice. Shell change skipped."; return ;;
    esac

    case "$PREFIX" in
        *com.termux*) termux=true; zsh=zsh ;;
        *) termux=false ;;
    esac

    if [ "$termux" != true ]; then
        
        if [ -f /etc/shells ]; then
            shells_file=/etc/shells
        elif [ -f /usr/share/defaults/etc/shells ]; then 
            shells_file=/usr/share/defaults/etc/shells
        else
            error "could not find /etc/shells file. Change your default shell manually."
            return
        fi

        if ! zsh=$(which zsh) || ! grep -qx "$zsh" "$shells_file"; then
            if ! zsh=$(grep '^/.*/zsh$' "$shells_file" | tail -1) || [ ! -f "$zsh" ]; then
                error "no zsh binary found or not present in '$shells_file'"
                error "change your default shell manually."
                return
            fi
        fi
    fi

    if [ -n "$SHELL" ]; then
        echo $SHELL > ~/.shell.pre-oh-my-zsh
    else
        grep "^$USER:" /etc/passwd | awk -F: '{print $7}' > ~/.shell.pre-oh-my-zsh
    fi

    if ! chsh -s "$zsh"; then
        error "chsh command unsuccessful. Change your default shell manually."
    else
        export SHELL="$zsh"
        echo "${GREEN}Shell successfully changed to '$zsh'.${RESET}"
    fi

    echo
}

main() {

    if [ ! -t 0 ]; then
        RUNZSH=no
        CHSH=no
    fi

    while [ $# -gt 0 ]; do
        case $1 in
            --unattended) RUNZSH=no; CHSH=no ;;
            --skip-chsh) CHSH=no ;;
            --keep-zshrc) KEEP_ZSHRC=yes ;;
        esac
        shift
    done

    setup_color

    if ! command_exists zsh; then
        echo "${YELLOW}Zsh is not installed.${RESET} Please install zsh first."
        exit 1
    fi

    if [ -d "$ZSH" ]; then
        cat <<-EOF
            ${YELLOW}You already have Oh My Zsh installed.${RESET}
            You will need to remove '$ZSH' if you want to reinstall.
        EOF
        exit 1
    fi

    setup_ohmyzsh
    setup_zshrc
    setup_shell

    printf "$GREEN"
    cat <<-'EOF'
                 __                                     __
          ____  / /_     ____ ___  __  __   ____  _____/ /_
         / __ \/ __ \   / __ `__ \/ / / /  /_  / / ___/ __ \
        / /_/ / / / /  / / / / / / /_/ /    / /_(__  ) / / /
        \____/_/ /_/  /_/ /_/ /_/\__, /    /___/____/_/ /_/
                                /____/                       ....is now installed!


        Please look over the ~/.zshrc file to select plugins, themes, and options.

    EOF
    printf "$RESET"

    if [ $RUNZSH = no ]; then
        echo "${YELLOW}Run zsh to try it out.${RESET}"
        exit
    fi

    exec zsh -l
}

main "$@"

查看当前shell命令echo $SHELL
查看已安装的shell命令cat /etc/shells
切换zsh命令chsh -s /bin/zsh
切换bash命令chsh -s /bin/bash

git常用命令总结

oh my zsh 缩写 原git命令 描述
gst git status 查看当前仓库状态
gaa git add --all 将所有改动添加到暂存区
gcmsg git commit -m 将暂存区提交
gb git branch 查看本地分支
gfo git fetch origin 更新远程分支列表
gba git branch -a 查看所有分支
gbd git branch -d 删除某分支
gbD git branch -D 强制删除某分支
gcb git checkout -b 创建分支并切换
gco git checkout 切换分支
gl git pull 拉代码
gp git push 推代码
gm git merge 合并分支
ggsup git branch --set-upstream-to=origin/$(git_current_branch) 绑定远程同名分支
gpsup git push --set-upstream origin $(git_current_branch) 在远程创建同名分支并关联后将代码推上去
gsta git stash push 将当前改动加入缓存
gstc git stash clear 清空所有缓存
gstl git stash list 查看缓存列表
gstp git stash pop 将最新一条缓存读取出来并删除缓存
grhh git reset --hard 回退到某个commit版本
groh git reset origin/$(git_current_branch) --hard 将远程仓库同名分支回退到某个commit版本
上一篇下一篇

猜你喜欢

热点阅读