Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve setup instructions and enforce consistent GOBIN usage #152

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,31 @@ asdf plugin add golang https://github.com/asdf-community/asdf-golang.git

## Use

Check the [asdf](https://github.com/asdf-vm/asdf) readme for instructions on how to install & manage versions of go.
To ensure the Golang environment variables are correctly set when using the `asdf` Go plugin (`asdf-golang`), you should source the appropriate `set-env` script for your shell. This is particularly important if you've customized the `asdf` data directory using the `ASDF_DATA_DIR` environment variable. Below are instructions for various shells:

## `GOROOT`
- **Zsh (`.zshrc`):**

To set `GOROOT` in your shell's initialization add the following:
```bash
. ${ASDF_DATA_DIR:-$HOME/.asdf}/plugins/golang/set-env.zsh
```

**zsh shell**
`. ~/.asdf/plugins/golang/set-env.zsh`
- **Bash (`.bashrc`):**

**fish shell**
`source ~/.asdf/plugins/golang/set-env.fish`
```bash
. ${ASDF_DATA_DIR:-$HOME/.asdf}/plugins/golang/set-env.bash
```

**nushell shell**
Add this to your env.nu
`source ('~/.asdf/plugins/golang/set-env.nu')`
- **Fish (`config.fish`):**

**bash shell**
Add this to your .bashrc:
`. ~/.asdf/plugins/golang/set-env.bash`
```fish
source (echo $ASDF_DATA_DIR | if test -z $it; echo $HOME/.asdf; else echo $it; end)/plugins/golang/set-env.fish
```

- **Nushell (`env.nu`):**

```nu
source (if ($env.ASDF_DATA_DIR | empty?) { echo $nu.env.HOME/.asdf } { echo $env.ASDF_DATA_DIR })/plugins/golang/set-env.nu
```

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

Expand Down
4 changes: 4 additions & 0 deletions bin/exec-env
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ if [ "${ASDF_INSTALL_VERSION}" != 'system' ]; then
if [[ "unset" == "${GOPATH:-unset}" ]]; then
export GOPATH=$ASDF_INSTALL_PATH/packages
fi

if [[ "unset" == "${GOBIN:-unset}" ]]; then
export GOBIN=$ASDF_INSTALL_PATH/bin
fi
fi
2 changes: 2 additions & 0 deletions bin/install
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ install_default_go_pkgs() {

GOROOT="$ASDF_INSTALL_PATH/go" \
GOPATH="$ASDF_INSTALL_PATH/packages" \
GOBIN="$ASDF_INSTALL_PATH/bin" \
PATH="$go_path:$PATH" \
go install "$name" >/dev/null && rc=$? || rc=$?
else
GOROOT="$ASDF_INSTALL_PATH/go" \
GOPATH="$ASDF_INSTALL_PATH/packages" \
PATH="$go_path:$PATH" \
GOBIN="$ASDF_INSTALL_PATH/bin" \
go get -u "$name" >/dev/null && rc=$? || rc=$?
fi

Expand Down
2 changes: 1 addition & 1 deletion bin/list-bin-paths
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash

echo -n "bin go/bin packages/bin"
echo -n "bin go/bin"