mirror of
https://github.com/kennyp/asdf-golang.git
synced 2024-10-06 04:32:07 +08:00
Add dynamic GOROOT setting for zsh (#56)
Co-authored-by: Kenny Parnell <k.parnell@gmail.com>
This commit is contained in:
parent
99f0baf0af
commit
0f6f356b85
@ -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
17
set-env.zsh
Normal 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
|
Loading…
Reference in New Issue
Block a user