Skip to content

Commit

Permalink
update go setting
Browse files Browse the repository at this point in the history
  • Loading branch information
zy9306 committed Oct 25, 2023
1 parent b0735d2 commit 025d2bb
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 11 deletions.
41 changes: 31 additions & 10 deletions dotfiles/zsh/.env
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,39 @@ 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-add-env-and-path() {
mkdir -p "$GOROOT/bin" "$GOPATH/bin"
go env -w GOPATH=$GOPATH GOROOT=$GOROOT
path_remove "$GOROOT/bin"
path_remove "$GOPATH/bin"
prepend_path "$GOROOT/bin"
prepend_path "$GOPATH/bin"
}
go-arm64() {
mkdir -p $HOME/go-arm64/go
export GOPATH=$HOME/go-arm64/go
export GOROOT="/usr/local/go-arm64/go"
go-add-env-and-path
}

go-amd64() {
mkdir -p $HOME/go-amd64/go
export GOPATH=$HOME/go-amd64/go
export GOROOT="/usr/local/go-amd64/go"
go-add-env-and-path
}

# 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

Expand Down
1 change: 1 addition & 0 deletions dotfiles/zsh/.zshenv
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- mode: sh -*-

source $HOME/.shutils
source $HOME/.zshutils

if [[ $name != "nix-shell" ]]; then
source $HOME/.env
Expand Down
4 changes: 4 additions & 0 deletions dotfiles/zsh/.zshutils
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
path_remove() {
# only work in zsh
path=("${(@)path:#"$1"}")
}
3 changes: 2 additions & 1 deletion dotfiles/zsh/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 025d2bb

Please sign in to comment.