diff --git a/plugins/available/go.plugin.bash b/plugins/available/go.plugin.bash index 629bcc12..9c503319 100644 --- a/plugins/available/go.plugin.bash +++ b/plugins/available/go.plugin.bash @@ -19,18 +19,14 @@ export GOPATH="${GOPATH:-$(go env GOPATH)}" _bash-it-gopath-pathmunge() { _about 'Ensures paths in GOPATH are added to PATH using pathmunge, with /bin appended' _group 'go' - if [[ -z $GOPATH ]]; then - echo 'GOPATH empty' >&2 + if [[ -z "${GOPATH:-}" ]]; then + _log_warning 'GOPATH empty' return 1 fi - local paths i + local paths apath IFS=: read -r -a paths <<< "$GOPATH" - i=${#paths[@]} - while [[ $i -gt 0 ]]; do - i=$((i - 1)) - if [[ -n "${paths[i]}" ]]; then - pathmunge "${paths[i]}/bin" || true - fi + for apath in "${paths[@]}"; do + pathmunge "${apath}/bin" || true done } _bash-it-gopath-pathmunge diff --git a/test/plugins/go.plugin.bats b/test/plugins/go.plugin.bats index ebb9cd88..4eba8d6b 100644 --- a/test/plugins/go.plugin.bats +++ b/test/plugins/go.plugin.bats @@ -53,7 +53,7 @@ function setup_go_path() setup_go_path "$BASH_IT/test/fixtures/go/gopath" setup_go_path "$BASH_IT/test/fixtures/go/gopath2" load ../../plugins/available/go.plugin - assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "$BASH_IT/test/fixtures/go/gopath2/bin:$BASH_IT/test/fixtures/go/gopath/bin" + assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "$BASH_IT/test/fixtures/go/gopath/bin:$BASH_IT/test/fixtures/go/gopath2/bin" } @test 'plugins go: multiple entries in GOPATH, with space' { @@ -61,7 +61,7 @@ function setup_go_path() setup_go_path "$BASH_IT/test/fixtures/go/gopath" setup_go_path "$BASH_IT/test/fixtures/go/go path" load ../../plugins/available/go.plugin - assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "$BASH_IT/test/fixtures/go/go path/bin:$BASH_IT/test/fixtures/go/gopath/bin" + assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "$BASH_IT/test/fixtures/go/gopath/bin:$BASH_IT/test/fixtures/go/go path/bin" } @test 'plugins go: multiple entries in GOPATH, with escaped space' {