clean up goenv and go resources

pull/1666/head
cornfeedhobo 2020-09-25 16:37:25 -05:00
parent a953a1a6b9
commit 176abe43b5
No known key found for this signature in database
GPG Key ID: 724357093F994B26
5 changed files with 39 additions and 16 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)"

View File

@ -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