Last active
August 29, 2015 14:05
-
-
Save robfig/3f8abe1e3023b7bae5fe to your computer and use it in GitHub Desktop.
bash autocompletion for Go packages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# Bash completion script for the go commandline tool. Presently it activates | |
# to show packages under $GOPATH on these subcommands: | |
# - go install | |
# - go build | |
# - go test | |
# | |
# Install by sourcing this file from your .bash_profile, or copy it in. | |
# | |
# Author: Rob Figueiredo ([email protected]) | |
function _gocomplete() { | |
subcmd="${COMP_WORDS[1]}" | |
case $subcmd in | |
build|install|test) | |
COMPREPLY=($(cd $GOPATH/src && ls -d $2*/ 2>/dev/null | sed 's#/$##g')) | |
if [[ ${#COMPREPLY[@]} == 1 ]]; then | |
COMPREPLY=($(cd $GOPATH/src && ls -d ${COMPREPLY[0]}/*/ 2>/dev/null | sed 's#/$##g')) | |
fi | |
return 0 | |
;; | |
esac | |
return 1 | |
} | |
complete -o default -o nospace -F _gocomplete go |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment