From ee5f1d4ad5417d213be54bafe08cff10ef332ef2 Mon Sep 17 00:00:00 2001 From: Arcueid Date: Wed, 25 Oct 2023 17:54:25 +0800 Subject: [PATCH] update go setting --- dotfiles/zsh/.env | 48 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/dotfiles/zsh/.env b/dotfiles/zsh/.env index 2ba7285..f659e03 100644 --- a/dotfiles/zsh/.env +++ b/dotfiles/zsh/.env @@ -1,5 +1,10 @@ # -*- mode: sh -*- +path_remove() { + # only work in zsh + path=("${(@)path:#"$1"}") +} + prepend_path() { APPEND_PATH=$1 if [ -d $APPEND_PATH ]; then @@ -93,18 +98,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