diff --git a/completion/available/go.completion.bash b/completion/available/go.completion.bash index dcc5cb98..153fd3a5 100644 --- a/completion/available/go.completion.bash +++ b/completion/available/go.completion.bash @@ -8,6 +8,8 @@ # go get -u github.com/posener/complete/gocomplete # gocomplete -install -if _command_exists gocomplete && _command_exists go ; then - complete -C "${GOBIN}"/gocomplete go +if _command_exists go ; then + if _command_exists gocomplete "gocomplete missing, please visit github.com/posener/complete/" ; then + complete -C gocomplete go + fi fi diff --git a/completion/available/goenv.completion.bash b/completion/available/goenv.completion.bash new file mode 100644 index 00000000..23ff91f1 --- /dev/null +++ b/completion/available/goenv.completion.bash @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +# Bash completion support for goenv + +if _command_exists goenv && [[ -r "$(dirname $(readlink -f $(which goenv)))/../completions/goenv.bash" ]] ; then + source "$(dirname $(readlink -f $(which goenv)))/../completions/goenv.bash" +fi diff --git a/plugins/available/go.plugin.bash b/plugins/available/go.plugin.bash index 566d7669..cb859999 100755 --- a/plugins/available/go.plugin.bash +++ b/plugins/available/go.plugin.bash @@ -1,14 +1,17 @@ -#!/usr/bin/env bash - cite about-plugin about-plugin 'go environment variables & path configuration' -command -v go &>/dev/null || return +# Load after goenv +# BASH_IT_LOAD_PRIORITY: 285 +{ _command_exists go && go version &>/dev/null ; } || return 0 + +# Wrapper function to iterate, in reverse, through a list of colon +# separated paths to support multiple entries in GOPATH. function _go_pathmunge_wrap() { IFS=':' local -a 'a=($1)' local i=${#a[@]} - while [ $i -gt 0 ] ; do + while [[ $i -gt 0 ]] ; do i=$(( i - 1 )) pathmunge "${a[i]}/bin" done diff --git a/plugins/available/goenv.plugin.bash b/plugins/available/goenv.plugin.bash index ecc1b1c2..00c5ed03 100644 --- a/plugins/available/goenv.plugin.bash +++ b/plugins/available/goenv.plugin.bash @@ -1,6 +1,9 @@ cite about-plugin about-plugin 'load goenv, if you are using it' +# Load after basher +# BASH_IT_LOAD_PRIORITY: 275 + # Don't modify the environment if we can't find the tool: # - Check if in $PATH already # - Check if installed manually to $GOENV_ROOT @@ -8,13 +11,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)" diff --git a/test/plugins/go.plugin.bats b/test/plugins/go.plugin.bats index d511bd24..2c3bdc0d 100644 --- a/test/plugins/go.plugin.bats +++ b/test/plugins/go.plugin.bats @@ -4,15 +4,27 @@ load ../test_helper load ../../lib/helpers load ../../lib/composure -@test 'ensure _go_pathmunge_wrap is defined' { - { [[ $CI ]] || _command_exists go; } || skip 'golang not found' +function local_setup { + setup_test_fixture + + # mock out go if it doesn't exist + if ! _command_exists go || ! go version &>/dev/null ; then + function go { + case "$2" in + GOROOT) echo '/tmp/goroot' ;; + GOPATH) echo '/tmp/gopath' ;; + esac + } + fi +} + +@test 'plugins go: ensure _go_pathmunge_wrap is defined' { load ../../plugins/available/go.plugin run type -t _go_pathmunge_wrap assert_line 'function' } @test 'plugins go: single entry in GOPATH' { - { [[ $CI ]] || _command_exists go; } || skip 'golang not found' export GOPATH="/foo" export GOROOT="/baz" load ../../plugins/available/go.plugin @@ -20,7 +32,6 @@ load ../../lib/composure } @test 'plugins go: single entry in GOPATH, with space' { - { [[ $CI ]] || _command_exists go; } || skip 'golang not found' export GOPATH="/foo bar" export GOROOT="/baz" load ../../plugins/available/go.plugin @@ -28,7 +39,6 @@ load ../../lib/composure } @test 'plugins go: single entry in GOPATH, with escaped space' { - { [[ $CI ]] || _command_exists go; } || skip 'golang not found' export GOPATH="/foo\ bar" export GOROOT="/baz" load ../../plugins/available/go.plugin @@ -36,7 +46,6 @@ load ../../lib/composure } @test 'plugins go: multiple entries in GOPATH' { - { [[ $CI ]] || _command_exists go; } || skip 'golang not found' export GOPATH="/foo:/bar" export GOROOT="/baz" load ../../plugins/available/go.plugin @@ -44,7 +53,6 @@ load ../../lib/composure } @test 'plugins go: multiple entries in GOPATH, with space' { - { [[ $CI ]] || _command_exists go; } || skip 'golang not found' export GOPATH="/foo:/foo bar" export GOROOT="/baz" load ../../plugins/available/go.plugin @@ -52,7 +60,6 @@ load ../../lib/composure } @test 'plugins go: multiple entries in GOPATH, with escaped space' { - { [[ $CI ]] || _command_exists go; } || skip 'golang not found' export GOPATH="/foo:/foo\ bar" export GOROOT="/baz" load ../../plugins/available/go.plugin