Merge pull request #1832 from cornfeedhobo/gocomplete

ensure go completion works well with goenv
pull/1835/head
cornfeedhobo 2021-02-06 15:27:12 -06:00 committed by GitHub
commit 133e48229a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 8 deletions

View File

@ -69,6 +69,7 @@ completion/available/docker.completion.bash
completion/available/docker-machine.completion.bash
completion/available/gcloud.completion.bash
completion/available/gem.completion.bash
completion/available/go.completion.bash
completion/available/github-cli.completion.bash
completion/available/helm.completion.bash
completion/available/jungle.completion.bash

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