ensure go completion works well with goenv

This commit is contained in:
cornfeedhobo
2021-02-06 14:13:49 -06:00
parent fe9ef1e4bd
commit 6870abc4fc
2 changed files with 11 additions and 8 deletions

View File

@@ -1,13 +1,15 @@
#!/usr/bin/env bash
# shellcheck shell=bash
about-completion "completion for go command using gocomplete"
# bash completion for go tool
# https://github.com/posener/complete
# https://pkg.go.dev/github.com/posener/complete?tab=doc
# Install gocomplete:
# go get -u github.com/posener/complete/gocomplete
# gocomplete -install
if _command_exists gocomplete && _command_exists go ; then
complete -C "${GOBIN}"/gocomplete go
# Test `go version` because goenv creates shim scripts that will be found in PATH
# but do not always resolve to a working install.
if _command_exists go && go version &> /dev/null; then
# Same idea here, but no need to test a subcommand
if _command_exists gocomplete && gocomplete &> /dev/null; then
# finally, apply completion
complete -C gocomplete go
fi
fi