Skip to content

Commit b0e3204

Browse files
committed
fix: use hooks in nushell set-env script to properly set GO variables on CWD change
1 parent a75b761 commit b0e3204

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ To ensure the Golang environment variables are correctly set when using the `asd
4343
source (echo $ASDF_DATA_DIR | if test -z $it; echo $HOME/.asdf; else echo $it; end)/plugins/golang/set-env.fish
4444
```
4545

46-
- **Nushell (`env.nu`):**
46+
- **Nushell (`config.nu`):**
4747

4848
```nu
49-
source (if ($env.ASDF_DATA_DIR | empty?) { echo $nu.env.HOME/.asdf } { echo $env.ASDF_DATA_DIR })/plugins/golang/set-env.nu
49+
const asdf_data_dir = '~/.asdf' | path expand # this variable should be already set in your configuration as it is used to configure asdf itself
50+
source ([$asdf_data_dir plugins golang set-env.nu] | path join)
5051
```
5152

5253
## When using `go get` or `go install`

set-env.nu

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,17 @@
1-
$env.GOROOT = (asdf which go | path split | drop 2 | path join)
1+
def --env asdf-update-golang-env [] {
2+
let go_path = asdf which go | complete
3+
if $go_path.exit_code == 0 {
4+
let root = ($go_path.stdout | str trim | path split | drop 2 | path join)
5+
if $root != $env.GOROOT? {
6+
$env.GOROOT = $root
7+
$env.GOPATH = ($root | path dirname | path join packages)
8+
$env.GOBIN = ($root | path dirname | path join bin)
9+
}
10+
}
11+
}
12+
13+
asdf-update-golang-env
14+
15+
$env.config.hooks.env_change.PWD = (
16+
$env.config.hooks.env_change | get -o PWD | default [] | append {|| asdf-update-golang-env }
17+
)

0 commit comments

Comments
 (0)