Add dynamic GOROOT setting for zsh (#56)

Co-authored-by: Kenny Parnell <k.parnell@gmail.com>
This commit is contained in:
Austin Cawley-Edwards 2023-05-09 10:40:46 -04:00 committed by GitHub
parent 99f0baf0af
commit 0f6f356b85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 0 deletions

View File

@ -25,6 +25,13 @@ asdf plugin-add golang https://github.com/kennyp/asdf-golang.git
Check the [asdf](https://github.com/asdf-vm/asdf) readme for instructions on how to install & manage versions of go.
## `GOROOT`
To set `GOROOT` in your shell's initialization add the following:
**zsh shell**
`. ~/.asdf/plugins/golang/set-env.zsh`
## When using `go get` or `go install`
After using `go get` or `go install` to install a package you need to run `asdf reshim golang` to get any new shims.

17
set-env.zsh Normal file
View File

@ -0,0 +1,17 @@
function absolute_dir_path {
local absolute_path
absolute_path="$( cd -P "$( dirname "$1" )" && pwd )"
echo "$absolute_path"
}
asdf_update_golang_env() {
local go_path
go_path="$(asdf which go)"
if [[ -n "${go_path}" ]]; then
export GOROOT
GOROOT="$(dirname "$(absolute_dir_path "${go_path}")")"
fi
}
autoload -U add-zsh-hook
add-zsh-hook precmd asdf_update_golang_env