From a683039a72b2c13c77e15abb11dd5da4cb384b6d Mon Sep 17 00:00:00 2001 From: cornfeedhobo Date: Wed, 9 Sep 2020 19:49:21 -0500 Subject: [PATCH] ensure go and goenv play well together --- completion/available/go.completion.bash | 2 +- completion/available/goenv.completion.bash | 5 +++++ plugins/available/go.plugin.bash | 11 ++++++++--- plugins/available/goenv.plugin.bash | 6 ++++-- 4 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 completion/available/goenv.completion.bash diff --git a/completion/available/go.completion.bash b/completion/available/go.completion.bash index dcc5cb98..90c39100 100644 --- a/completion/available/go.completion.bash +++ b/completion/available/go.completion.bash @@ -9,5 +9,5 @@ # gocomplete -install if _command_exists gocomplete && _command_exists go ; then - complete -C "${GOBIN}"/gocomplete go + complete -C gocomplete go fi diff --git a/completion/available/goenv.completion.bash b/completion/available/goenv.completion.bash new file mode 100644 index 00000000..131d689b --- /dev/null +++ b/completion/available/goenv.completion.bash @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +if _command_exists goenv && [[ -r "$GOENV_ROOT/completions/goenv.bash" ]] ; then + source "$GOENV_ROOT/completions/goenv.bash" +fi diff --git a/plugins/available/go.plugin.bash b/plugins/available/go.plugin.bash index 566d7669..107d4916 100755 --- a/plugins/available/go.plugin.bash +++ b/plugins/available/go.plugin.bash @@ -1,9 +1,14 @@ -#!/usr/bin/env bash - cite about-plugin about-plugin 'go environment variables & path configuration' -command -v go &>/dev/null || return +# Load late to ensure goenv runs first, if enabled +# BASH_IT_LOAD_PRIORITY: 275 + +_command_exists go || return 0 + +# If using goenv, make sure it can find go +go version &>/dev/null +[[ $? -eq 0 ]] || return 0 function _go_pathmunge_wrap() { IFS=':' local -a 'a=($1)' diff --git a/plugins/available/goenv.plugin.bash b/plugins/available/goenv.plugin.bash index ecc1b1c2..df6f5268 100644 --- a/plugins/available/goenv.plugin.bash +++ b/plugins/available/goenv.plugin.bash @@ -8,13 +8,15 @@ about-plugin 'load goenv, if you are using it' _command_exists goenv || [[ -n "$GOENV_ROOT" && -x "$GOENV_ROOT/bin/goenv" ]] || [[ -x "$HOME/.goenv/bin/goenv" ]] || - return + return 0 # Set GOENV_ROOT, if not already set export GOENV_ROOT="${GOENV_ROOT:-$HOME/.goenv}" # Add GOENV_ROOT/bin to PATH, if that's where it's installed -! _command_exists goenv && [[ -x "$GOENV_ROOT/bin/goenv" ]] && pathmunge "$GOENV_ROOT/bin" +if ! _command_exists goenv && [[ -x "$GOENV_ROOT/bin/goenv" ]] ; then + pathmunge "$GOENV_ROOT/bin" +fi # Initialize goenv eval "$(goenv init - bash)"