blob: 0a5d842fd71c03ca3ebed703546b589d7560966a [file] [log] [blame] [view]
Damien Martin-Guillerez21e3a6b2015-04-10 20:24:32 +00001---
2layout: posts
3title: Support for Bash Shell Completion
4---
5
6We just pushed a support for [shell completion in the Bourne-Again
7Shell](https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion.html).
8It eases the use of Bazel by expanding its commands and the targets to build.
9
10To use this new functionality, build the `//scripts:bash_completion` target
11from the Bazel repository:
12```
13bazel build //scripts:bash_completion
14```
15
16This will create a `bazel-bin/scripts/bazel-complete.bash` completion script.
17You can copy then copy this script to your completion directory
18(`/etc/bash_completion.d` in Ubuntu). If you don't want to install it globally
19or don't have such a directory, simply add the following line to your
20`~/.bashrc` or `~/.bash_profile` (the latter is the recommended for OS X):
21```
22source /path/to/bazel/bazel-bin/scripts/bazel-complete.bash
23```
24
25After that you should be able to type the tab key after the `bazel`
26command in your shell and see the list of possible completions.
27
28If you are interested in supporting other shells, the script is made up
29of two parts:
30
Kristina Chodorow2b1763a2015-09-01 09:15:54 +0000311. [`scripts/bazel-complete-header.bash`](https://github.com/bazelbuild/bazel/blob/master/scripts/bazel-complete-template.bash)
Damien Martin-Guillerez21e3a6b2015-04-10 20:24:32 +000032 is the completion logic.
332. `bazel info completion` dumps the list of commands of Bazel, their options
34 and for commands and options that expect a value, a description of what is
35 expected. This description is either:
36
37* an enum of values enclosed into brackets, e.g., `{a,b,c}`;
38* a type description, currently one of:
39
40 * `label`, `label-bin`, `label-test`, `label-package` for
41 a Bazel label for, respectively, a target, a runnable target,
42 a test, and a package,
43 * `path` for a filesystem path,
44 * `info-key` for one of the information keys as listed by `bazel info`;
45
46* a combination of possible values using `|` as a separator, e.g,
47 `path|{or,an,enum}'`.
48
49Let us know if you have any questions or issues on the
50[mailing list](https://groups.google.com/forum/#!forum/bazel-discuss) or
Kristina Chodorow2b1763a2015-09-01 09:15:54 +000051[GitHub](https://github.com/bazelbuild/bazel).