Add dynamic GOPATH settings to zsh and fish (#127)

Co-authored-by: Kenny Parnell <k.parnell@gmail.com>
This commit is contained in:
Bazico 2024-05-20 13:01:13 -04:00 committed by GitHub
parent d1a522ebf2
commit 0e86b1d5a7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 7 deletions

View File

@ -1,8 +1,9 @@
function asdf_update_golang_env --on-event fish_prompt
set --local go_path (asdf which go 2>/dev/null)
if test -n "$go_path"
set --local full_path (builtin realpath "$go_path")
set --local go_bin_path (asdf which go 2>/dev/null)
if test -n "$go_bin_path"
set --local full_path (builtin realpath "$go_bin_path")
set -gx GOROOT (dirname (dirname "$full_path"))
set -gx GOPATH (dirname "$GOROOT")/packages
end
end

View File

@ -1,9 +1,12 @@
asdf_update_golang_env() {
local go_path
go_path="$(asdf which go 2>/dev/null)"
if [[ -n "${go_path}" ]]; then
local go_bin_path
go_bin_path="$(asdf which go 2>/dev/null)"
if [[ -n "${go_bin_path}" ]]; then
export GOROOT
GOROOT="$(dirname "$(dirname "${go_path:A}")")"
GOROOT="$(dirname "$(dirname "${go_bin_path:A}")")"
export GOPATH
GOPATH="$(dirname "${GOROOT:A}")/packages"
fi
}