We just pushed a support for shell completion in the Bourne-Again Shell. It eases the use of Bazel by expanding its commands and the targets to build.
To use this new functionality, build the
from the Bazel repository:
bazel build //scripts:bash_completion
This will create a
bazel-bin/scripts/bazel-complete.bash completion script.
You can copy then copy this script to your completion directory
/etc/bash_completion.d in Ubuntu). If you don't want to install it globally
or don't have such a directory, simply add the following line to your
~/.bash_profile (the latter is the recommended for OS X):
After that you should be able to type the tab key after the
command in your shell and see the list of possible completions.
If you are interested in supporting other shells, the script is made up of two parts:
scripts/bazel-complete-header.bashis the completion logic.
bazel help completiondumps the list of commands of Bazel, their options and for commands and options that expect a value, a description of what is expected. This description is either:
- an enum of values enclosed into brackets, e.g.,
a type description, currently one of:
label-packagefor a Bazel label for, respectively, a target, a runnable target, a test, and a package,
pathfor a filesystem path,
info-keyfor one of the information keys as listed by
a combination of possible values using
|as a separator, e.g,