diff --git a/dotfiles/zsh/.env b/dotfiles/zsh/.env index 2ba7285..f6f5fb6 100644 --- a/dotfiles/zsh/.env +++ b/dotfiles/zsh/.env @@ -93,18 +93,41 @@ if [[ $(command_exists virtualenvwrapper.sh) == true ]]; then fi # Go -if [ -d "/usr/local/go/bin" ]; then - APPEND_PATH="/usr/local/go/bin" - if [[ $PATH != *"$APPEND_PATH"* ]]; then - export PATH=$APPEND_PATH:$PATH - fi +go-arm64() { + mkdir -p $HOME/go-arm64/go + export GOPATH=$HOME/go-arm64/go + export GOROOT="/usr/local/go-arm64/go" + go env -w GOPATH=$GOPATH GOROOT=$GOROOT + mkdir -p "$GOROOT/bin" "$GOPATH/bin" + path_remove "$GOROOT/bin" + path_remove "$GOPATH/bin" + prepend_path "$GOROOT/bin" + prepend_path "$GOPATH/bin" +} + +go-amd64() { + mkdir -p $HOME/go-amd64/go + export GOPATH=$HOME/go-amd64/go + export GOROOT="/usr/local/go-amd64/go" + go env -w GOPATH=$GOPATH GOROOT=$GOROOT + mkdir -p "$GOROOT/bin" "$GOPATH/bin" + path_remove "$GOROOT/bin" + path_remove "$GOPATH/bin" + prepend_path "$GOROOT/bin" + prepend_path "$GOPATH/bin" +} + +# Mac 默认用 go-arm64 +if [[ $(uname -s) == "Darwin" ]]; then + go-arm64 fi -if [[ $(command_exists go) == true ]]; then - export GOPATH=~/go - APPEND_PATH="$GOPATH/bin" - if [[ $PATH != *"$APPEND_PATH"* ]]; then - export PATH=$APPEND_PATH:$PATH +# 如果是 Linux,那么就使用 go-amd64 +if [[ $(uname -s) == "Linux" ]]; then + if [[ $(uname -m) == "arm64" ]]; then + go-arm64 + else + go-amd64 fi fi diff --git a/dotfiles/zsh/.zshenv b/dotfiles/zsh/.zshenv index b769281..47901d9 100644 --- a/dotfiles/zsh/.zshenv +++ b/dotfiles/zsh/.zshenv @@ -1,6 +1,7 @@ # -*- mode: sh -*- source $HOME/.shutils +source $HOME/.zshutils if [[ $name != "nix-shell" ]]; then source $HOME/.env diff --git a/dotfiles/zsh/.zshutils b/dotfiles/zsh/.zshutils new file mode 100644 index 0000000..83e24f2 --- /dev/null +++ b/dotfiles/zsh/.zshutils @@ -0,0 +1,4 @@ +path_remove() { + # only work in zsh + path=("${(@)path:#"$1"}") +} diff --git a/dotfiles/zsh/install.sh b/dotfiles/zsh/install.sh index 1733504..79e802a 100755 --- a/dotfiles/zsh/install.sh +++ b/dotfiles/zsh/install.sh @@ -29,12 +29,13 @@ fi cd -rm -f .zshenv .zshrc .app .env .shutils .starship +rm -f .zshenv .zshrc .app .env .shutils .starship .zshutils ln -s ${CONFIG_PATH}/.zshenv .zshenv ln -s ${CONFIG_PATH}/.zshrc .zshrc ln -s ${CONFIG_PATH}/.env .env ln -s ${CONFIG_PATH}/.app .app ln -s ${CONFIG_PATH}/.shutils .shutils +ln -s ${CONFIG_PATH}/.zshutils .zshutils ln -s ${CONFIG_PATH}/.starship .starship chsh -s $(which zsh)