asdf-direnv: bug: direnv, no shims in PATH, asdf global, asdf direnv shell issue/question
Describe the Bug
I’m not sure if this is a bug in asdf/asdf-direnv/asdf-golang or just a pilot error, but I thought I’d try reporting it here anyway for thoughts.
The setup in question is
- asdf v0.9.0, asdf shims not in PATH per the “pro tip”
- asdf-golang current master, Go 1.17.8 and 1.18 installed with it, 1.17.8 set to global
- asdf-direnv current master
I’ve implemented the “pro tip” basically by just this:
export ASDF_DIR=~/.asdf
PATH=$ASDF_DIR/bin:$PATH
…i.e. I’m not sourcing ~/.asdf/asdf.sh
.
In this state, there are two problems
- the Go 1.17.8 global setting actually isn’t global in a sense – there is no
go
in$PATH
at all - I thought I could make one appear in a new shell with e.g.
asdf direnv shell golang 1.18
, but that doesn’t work even though I’m getting “using asdf golang 1.18” in the output:
$ asdf direnv shell golang 1.18
direnv: using asdf golang 1.18
direnv: loading ~/.asdf/plugins/golang/bin/exec-env
$ go version
bash: go: command not found
To start to resolve this I’ve added ~/.envrc
with contents use asdf
. ~No ~/.tool-versions
is present nor any other in effect~ (see correction in a comment below). That fixes 1) above, the Go set to global with asdf is now in my $PATH
along with other its settings.
However, the problem with 2) remains. I would like to open a new shell with a different Go every now and then, and the way I read https://github.com/asdf-community/asdf-direnv#temporary-environments-for-one-shot-commands it would seem that asdf direnv shell golang x.xx.x
should accomplish that. But it doesn’t:
$ go version
go version go1.17.8 linux/amd64
$ asdf direnv shell golang 1.18
direnv: using asdf golang 1.18
direnv: loading ~/.asdf/plugins/golang/bin/exec-env
$ go version
go version go1.17.8 linux/amd64
I’ve found that a asdf global golang x.xx
serves as a workaround for 2) – it does change the Go version in the current shell (if the shell is using the global, naturally, and not overridden by a dir specific one). But the obvious problem is that it “leaks” to other new shells because of the altered global. asdf shell golang x.xx
is not available, asdf barfs
Shell integration is not enabled. Please ensure you source asdf in your shell setup.
So, boils down to 2 questions:
a) Is adding use asdf
to this effect in ~/.envrc
something that one usually does with the “pro tip”, or what’s the “correct” way to get the asdf globals to work with it? If that’s the way, perhaps amend the pro tip doc with that?
b) Is there something wrong with asdf direnv shell golang ...
, or my use or expectation of it?
Steps to Reproduce
See above.
Expected Behaviour
I hope the description above covers this.
Actual Behaviour
I hope the description above covers this.
Debug Output
$ env ASDF_DIRENV_DEBUG=true direnv reload
direnv: loading ~/.envrc
direnv: using asdf
direnv: Creating env file /home/scop/.cache/asdf-direnv/env/1511531071-511866787-3894808579-3581694273
direnv: loading ~/.cache/asdf-direnv/env/1511531071-511866787-3894808579-3581694273
direnv: using asdf golang 1.17.8
direnv: loading ~/.asdf/plugins/golang/bin/exec-env
direnv: export +GOPATH +GOROOT ~PATH
$ cat ~/.cache/asdf-direnv/env/1511531071-511866787-3894808579-3581694273
### Do not edit. This was autogenerated by 'asdf direnv envrc' from /home/scop/.tool-versions ###
log_status using asdf golang 1.17.8
PATH_add /home/scop/.asdf/installs/golang/1.17.8/packages/bin
PATH_add /home/scop/.asdf/installs/golang/1.17.8/go/bin
ASDF_INSTALL_TYPE='version' ASDF_INSTALL_VERSION='1.17.8' ASDF_INSTALL_PATH='/home/scop/.asdf/installs/golang/1.17.8' source_env /home/scop/.asdf/plugins/golang/bin/exec-env
watch_file /home/scop/.tool-versions
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 20 (18 by maintainers)
Commits related to this issue
- Add couple tests for shell command. One for testing that the tool version can override those from global and local .tool-versions file. One for testing that we spawn a SHELL and that it has the corr... — committed to asdf-community/asdf-direnv by vic 2 years ago
- Use `set -u` nounset on all commands. This helps prevent bugs like those uncovered on #151. Related issue #149. — committed to asdf-community/asdf-direnv by vic 2 years ago
- exec-env: set GOROOT and GOPATH unconditionally Otherwise, existing values from the environment may continue to point to a wrong version. Refs https://github.com/asdf-community/asdf-direnv/issues/14... — committed to scop/asdf-golang by scop 2 years ago
- Ensure no asdf shims are on PATH for shell tests Related issue #149 — committed to asdf-community/asdf-direnv by vic 2 years ago
- exec-env: set GOROOT and GOPATH unconditionally Otherwise, existing values from the environment may continue to point to a wrong version. Refs https://github.com/asdf-community/asdf-direnv/issues/14... — committed to scop/asdf-golang by scop 2 years ago
- Add a note that removing shims will break globals This fixes https://github.com/asdf-community/asdf-direnv/issues/149 — committed to asdf-community/asdf-direnv by jfly a year ago
- Add a note that removing shims will break globals This fixes https://github.com/asdf-community/asdf-direnv/issues/149 — committed to asdf-community/asdf-direnv by jfly a year ago
- Add a note that removing shims will break globals This fixes https://github.com/asdf-community/asdf-direnv/issues/149 — committed to asdf-community/asdf-direnv by jfly a year ago
#151 fixes the incomplete
$PATH
setup. Problem with$GOPATH
and$GOROOT
remains, will try to find time for that soonish.