Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
BorzdeG committed Jun 27, 2023
1 parent 21d9c32 commit 1d29af5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 33 deletions.
64 changes: 32 additions & 32 deletions bin/install
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ PLUGIN_DIR="$(dirname "${BASH_SOURCE[0]}")/.."
# shellcheck source=/dev/null
source "$PLUGIN_DIR/lib/helpers.sh"

install_golang () {
local version="$1"
local download_path="$2"
local install_path="$3"
created_tmp="0"

if [ -z "$download_path" ] ; then
download_path=$(mktemp -dt asdf-golang.XXXX)
created_tmp="1"
ASDF_INSTALL_VERSION="$version" ASDF_DOWNLOAD_PATH="$download_path" "$PLUGIN_DIR/bin/download"
fi

tar -C "$install_path" -xzf "${download_path}/archive.tar.gz"

if [ "1" = "$created_tmp" ]; then
rm -r "$download_path"
fi
install_golang() {
local version="$1"
local download_path="$2"
local install_path="$3"
created_tmp="0"

if [ -z "$download_path" ]; then
download_path=$(mktemp -dt asdf-golang.XXXX)
created_tmp="1"
ASDF_INSTALL_VERSION="$version" ASDF_DOWNLOAD_PATH="$download_path" "$PLUGIN_DIR/bin/download"
fi

tar -C "$install_path" -xzf "${download_path}/archive.tar.gz"

if [ "1" = "$created_tmp" ]; then
rm -r "$download_path"
fi
}

install_default_go_pkgs() {
Expand All @@ -33,40 +33,40 @@ install_default_go_pkgs() {

if [ ! -f "$default_go_pkgs" ]; then return; fi


while read -r line; do
name=$(echo "$line" | \
sed 's|\(.*\) //.*$|\1|' | \
sed -E 's|^[[:space:]]*//.*||') # the first sed is for comments after package names, the second for full line comments

# Skip empty lines
if [ -z "$name" ]; then continue ; fi
if [ -z "$name" ]; then continue; fi

echo -ne "\nInstalling \033[33m${name}\033[39m go pkg... " >&2

# if using go > 1.16 then use go install as the preferred donwload path
if [ "$go_major_version" -ge 2 ] || [ "${go_minor_version//[!0-9]*}" -ge 16 ]; then
if [[ "$name" != *"@"* ]]; then
name="${name}@latest"
fi

GOROOT="$ASDF_INSTALL_PATH/go" \
GOPATH="$ASDF_INSTALL_PATH/packages" \
PATH="$go_path:$PATH" \
go install "$name" > /dev/null && rc=$? || rc=$?
if [[ "$name" != *"@"* ]]; then
name="${name}@latest"
fi

GOROOT="$ASDF_INSTALL_PATH/go" \
GOPATH="$ASDF_INSTALL_PATH/packages" \
GOBIN="$ASDF_INSTALL_PATH/packages/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" \
go get -u "$name" > /dev/null && rc=$? || rc=$?
GOROOT="$ASDF_INSTALL_PATH/go" \
GOPATH="$ASDF_INSTALL_PATH/packages" \
PATH="$go_path:$PATH" \
go get -u "$name" >/dev/null && rc=$? || rc=$?
fi

if [[ $rc -eq 0 ]]; then
msg "SUCCESS"
else
err "FAIL"
fi
done < "$default_go_pkgs"
done <"$default_go_pkgs"
}

install_golang "$ASDF_INSTALL_VERSION" "${ASDF_DOWNLOAD_PATH:-}" "$ASDF_INSTALL_PATH"
Expand Down
3 changes: 2 additions & 1 deletion set-env.fish
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ function asdf_update_golang_env --on-event fish_prompt
set --local full_path (builtin realpath "$go_path")

set -gx GOROOT (dirname (dirname "$full_path"))
set -gx GOBIN (dirname "$GOROOT")/packages/bin
end
end
end
2 changes: 2 additions & 0 deletions set-env.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ asdf_update_golang_env() {
if [[ -n "${go_path}" ]]; then
export GOROOT
GOROOT="$(dirname "$(dirname "${go_path:A}")")"
export GOBIN
GOBIN="$(dirname "${GOROOT}")/packages/bin"
fi
}

Expand Down

0 comments on commit 1d29af5

Please sign in to comment.