clean up goenv and go resources
parent
a953a1a6b9
commit
176abe43b5
|
|
@ -8,6 +8,8 @@
|
||||||
# go get -u github.com/posener/complete/gocomplete
|
# go get -u github.com/posener/complete/gocomplete
|
||||||
# gocomplete -install
|
# gocomplete -install
|
||||||
|
|
||||||
if _command_exists gocomplete && _command_exists go ; then
|
if _command_exists go ; then
|
||||||
complete -C "${GOBIN}"/gocomplete go
|
if _command_exists gocomplete "gocomplete missing, please visit github.com/posener/complete/" ; then
|
||||||
|
complete -C gocomplete go
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
@ -1,14 +1,17 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
cite about-plugin
|
cite about-plugin
|
||||||
about-plugin 'go environment variables & path configuration'
|
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() {
|
function _go_pathmunge_wrap() {
|
||||||
IFS=':' local -a 'a=($1)'
|
IFS=':' local -a 'a=($1)'
|
||||||
local i=${#a[@]}
|
local i=${#a[@]}
|
||||||
while [ $i -gt 0 ] ; do
|
while [[ $i -gt 0 ]] ; do
|
||||||
i=$(( i - 1 ))
|
i=$(( i - 1 ))
|
||||||
pathmunge "${a[i]}/bin"
|
pathmunge "${a[i]}/bin"
|
||||||
done
|
done
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
cite about-plugin
|
cite about-plugin
|
||||||
about-plugin 'load goenv, if you are using it'
|
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:
|
# Don't modify the environment if we can't find the tool:
|
||||||
# - Check if in $PATH already
|
# - Check if in $PATH already
|
||||||
# - Check if installed manually to $GOENV_ROOT
|
# - Check if installed manually to $GOENV_ROOT
|
||||||
|
|
@ -8,13 +11,15 @@ about-plugin 'load goenv, if you are using it'
|
||||||
_command_exists goenv ||
|
_command_exists goenv ||
|
||||||
[[ -n "$GOENV_ROOT" && -x "$GOENV_ROOT/bin/goenv" ]] ||
|
[[ -n "$GOENV_ROOT" && -x "$GOENV_ROOT/bin/goenv" ]] ||
|
||||||
[[ -x "$HOME/.goenv/bin/goenv" ]] ||
|
[[ -x "$HOME/.goenv/bin/goenv" ]] ||
|
||||||
return
|
return 0
|
||||||
|
|
||||||
# Set GOENV_ROOT, if not already set
|
# Set GOENV_ROOT, if not already set
|
||||||
export GOENV_ROOT="${GOENV_ROOT:-$HOME/.goenv}"
|
export GOENV_ROOT="${GOENV_ROOT:-$HOME/.goenv}"
|
||||||
|
|
||||||
# Add GOENV_ROOT/bin to PATH, if that's where it's installed
|
# 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
|
# Initialize goenv
|
||||||
eval "$(goenv init - bash)"
|
eval "$(goenv init - bash)"
|
||||||
|
|
|
||||||
|
|
@ -4,15 +4,27 @@ load ../test_helper
|
||||||
load ../../lib/helpers
|
load ../../lib/helpers
|
||||||
load ../../lib/composure
|
load ../../lib/composure
|
||||||
|
|
||||||
@test 'ensure _go_pathmunge_wrap is defined' {
|
function local_setup {
|
||||||
{ [[ $CI ]] || _command_exists go; } || skip 'golang not found'
|
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
|
load ../../plugins/available/go.plugin
|
||||||
run type -t _go_pathmunge_wrap
|
run type -t _go_pathmunge_wrap
|
||||||
assert_line 'function'
|
assert_line 'function'
|
||||||
}
|
}
|
||||||
|
|
||||||
@test 'plugins go: single entry in GOPATH' {
|
@test 'plugins go: single entry in GOPATH' {
|
||||||
{ [[ $CI ]] || _command_exists go; } || skip 'golang not found'
|
|
||||||
export GOPATH="/foo"
|
export GOPATH="/foo"
|
||||||
export GOROOT="/baz"
|
export GOROOT="/baz"
|
||||||
load ../../plugins/available/go.plugin
|
load ../../plugins/available/go.plugin
|
||||||
|
|
@ -20,7 +32,6 @@ load ../../lib/composure
|
||||||
}
|
}
|
||||||
|
|
||||||
@test 'plugins go: single entry in GOPATH, with space' {
|
@test 'plugins go: single entry in GOPATH, with space' {
|
||||||
{ [[ $CI ]] || _command_exists go; } || skip 'golang not found'
|
|
||||||
export GOPATH="/foo bar"
|
export GOPATH="/foo bar"
|
||||||
export GOROOT="/baz"
|
export GOROOT="/baz"
|
||||||
load ../../plugins/available/go.plugin
|
load ../../plugins/available/go.plugin
|
||||||
|
|
@ -28,7 +39,6 @@ load ../../lib/composure
|
||||||
}
|
}
|
||||||
|
|
||||||
@test 'plugins go: single entry in GOPATH, with escaped space' {
|
@test 'plugins go: single entry in GOPATH, with escaped space' {
|
||||||
{ [[ $CI ]] || _command_exists go; } || skip 'golang not found'
|
|
||||||
export GOPATH="/foo\ bar"
|
export GOPATH="/foo\ bar"
|
||||||
export GOROOT="/baz"
|
export GOROOT="/baz"
|
||||||
load ../../plugins/available/go.plugin
|
load ../../plugins/available/go.plugin
|
||||||
|
|
@ -36,7 +46,6 @@ load ../../lib/composure
|
||||||
}
|
}
|
||||||
|
|
||||||
@test 'plugins go: multiple entries in GOPATH' {
|
@test 'plugins go: multiple entries in GOPATH' {
|
||||||
{ [[ $CI ]] || _command_exists go; } || skip 'golang not found'
|
|
||||||
export GOPATH="/foo:/bar"
|
export GOPATH="/foo:/bar"
|
||||||
export GOROOT="/baz"
|
export GOROOT="/baz"
|
||||||
load ../../plugins/available/go.plugin
|
load ../../plugins/available/go.plugin
|
||||||
|
|
@ -44,7 +53,6 @@ load ../../lib/composure
|
||||||
}
|
}
|
||||||
|
|
||||||
@test 'plugins go: multiple entries in GOPATH, with space' {
|
@test 'plugins go: multiple entries in GOPATH, with space' {
|
||||||
{ [[ $CI ]] || _command_exists go; } || skip 'golang not found'
|
|
||||||
export GOPATH="/foo:/foo bar"
|
export GOPATH="/foo:/foo bar"
|
||||||
export GOROOT="/baz"
|
export GOROOT="/baz"
|
||||||
load ../../plugins/available/go.plugin
|
load ../../plugins/available/go.plugin
|
||||||
|
|
@ -52,7 +60,6 @@ load ../../lib/composure
|
||||||
}
|
}
|
||||||
|
|
||||||
@test 'plugins go: multiple entries in GOPATH, with escaped space' {
|
@test 'plugins go: multiple entries in GOPATH, with escaped space' {
|
||||||
{ [[ $CI ]] || _command_exists go; } || skip 'golang not found'
|
|
||||||
export GOPATH="/foo:/foo\ bar"
|
export GOPATH="/foo:/foo\ bar"
|
||||||
export GOROOT="/baz"
|
export GOROOT="/baz"
|
||||||
load ../../plugins/available/go.plugin
|
load ../../plugins/available/go.plugin
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue