complete

Package complete provides a tool for bash writing bash completion in go, and bash completion for the go command line.
Writing bash completion scripts is a hard work. This package provides an easy way
to create bash completion scripts for any command, and also an easy way to install/uninstall
the completion of the command.
Go Command Bash Completion
In ./cmd/gocomplete there is an example for bash completion for the go
command line.
This is an example that uses the complete
package on the go
command - the complete
package
can also be used to implement any completions, see #usage.
Install
go get -u github.com/posener/complete/gocomplete
gocomplete -install
Uninstall by gocomplete -uninstall
Features
- Complete
go
command, including sub commands and all flags.
- Complete packages names or
.go
files when necessary.
- Complete test names after
-run
flag.
Complete package
Supported shells:
Usage
Assuming you have program called run
and you want to have bash completion
for it, meaning, if you type run
then space, then press the Tab
key,
the shell will suggest relevant complete options.
In that case, we will create a program called runcomplete
, a go program,
with a func main()
and so, that will make the completion of the run
program. Once the runcomplete
will be in a binary form, we could
runcomplete -install
and that will add to our shell all the bash completion
options for run
.
So here it is:
import "github.com/posener/complete"
func main() {
run := complete.Command{
Sub: complete.Commands{
"build": complete.Command {
Flags: complete.Flags{
"-cpus": complete.PredictAnything,
},
},
},
Flags: complete.Flags{
"-o": complete.PredictFiles("*.out"),
},
GlobalFlags: complete.Flags{
"-h": complete.PredictNothing,
},
}
complete.New("run", run).Run()
}
Self completing program
In case that the program that we want to complete is written in go we
can make it self completing.
Here is an example: ./example/self/main.go .
Sub Packages
-
cmd: Package cmd used for command line options for the complete tool
-
gocomplete: Package main is complete tool for the go command line
-
match: Package match contains matchers that decide if to apply completion.
Created by goreadme