Bazel: Can someone elaborate on the instructions to install zsh completion?

Created on 7 Dec 2017  路  8Comments  路  Source: bazelbuild/bazel

I'm looking at the instructions for how to install zsh completion here and am left a little confused about what to do. I'm only a casual user of ZSH, so I think I'm missing something fundamental.

Getting zsh completion

Bazel also comes with a zsh completion script. To install it:

Add this script to a directory on your $fpath:

fpath[1,0]=~/.zsh/completion/
mkdir -p ~/.zsh/completion/
cp scripts/zsh_completion/_bazel ~/.zsh/completion

You may have to call rm -f ~/.zcompdump; compinit the first time to make it work.

Optionally, add the following to your .zshrc.

# This way the completion script does not have to parse Bazel's options
# repeatedly.  The directory in cache-path must be created manually.
zstyle ':completion:*' use-cache on
zstyle ':completion:*' cache-path ~/.zsh/cache

The second step is very clear, but the first is confusing to me.

My $fpath includes a whole list of directories. So should I just pick a directory and write a file with the contents of that first script? Does it matter what I name it? Is there an existing convention I should be following? I'm reviewing the docs for zsh functions at http://zsh.sourceforge.net/Doc/Release/Functions.html, but I'm still unsure of how to proceed.

P3 team-Bazel documentation (cleanup)

Most helpful comment

The _bazel file just needs to be in one of the directories listed in your fpath. The installation example shows how add a directory to your fpath and move the _bazel file into it, but if you already have a directory in your fpath that you prefer, you can move _bazel there instead.

It doesn't matter what the name of the directory is at all ($HOME/.zsh/completion/ is just commonly used). The _bazel filename only matters because that is what the completion function is named (i.e. https://github.com/bazelbuild/bazel/blob/64d9a4d6dcd720a3b7a60ff550a17a7707dd41d0/scripts/zsh_completion/_bazel#L247). Otherwise, it's only a convention to name the completion file/function after the command it completes with a leading underscore. When compinit is run, zsh will look through all files in all of the fpath directories and look for #compdef lines at the start of each to register completion functions.

All 8 comments

I know nothing about zsh.

@schroederc : I believe you added the zsh completion script to Bazel in commit https://github.com/bazelbuild/bazel/commit/6b2766dd0, so I'm hoping you can help.
@damienmg : you approved Cody's change, you may know about zsh.

also confused by this sentence

The _bazel file just needs to be in one of the directories listed in your fpath. The installation example shows how add a directory to your fpath and move the _bazel file into it, but if you already have a directory in your fpath that you prefer, you can move _bazel there instead.

It doesn't matter what the name of the directory is at all ($HOME/.zsh/completion/ is just commonly used). The _bazel filename only matters because that is what the completion function is named (i.e. https://github.com/bazelbuild/bazel/blob/64d9a4d6dcd720a3b7a60ff550a17a7707dd41d0/scripts/zsh_completion/_bazel#L247). Otherwise, it's only a convention to name the completion file/function after the command it completes with a leading underscore. When compinit is run, zsh will look through all files in all of the fpath directories and look for #compdef lines at the start of each to register completion functions.

Oh, I see. So the documentation was written from the perspective of that file and was copy/pasted/generated into documentation here: https://docs.bazel.build/versions/master/install.html#zsh

It looks like there may be a need to reword it.

The document disappeared. Is zsh auto completion not supported anymore?

Looking at the history of install.md, the instructions were there at 3e0c545404be6bce908d035044a5ff0ee41cc472, but not anymore at 70e84f8926bd2cc38fea9e74af292d19038607b8.

Let me see if they are still up-to-date and put them back.

FYI: alternatively, you guys may try this https://github.com/jackwish/bazel which is to make the process easier.

on macOS the zsh completions are installed automatically if you install via homebrew

Was this page helpful?
0 / 5 - 0 ratings

Related issues

laurentlb picture laurentlb  路  101Comments

philwo picture philwo  路  88Comments

dslomov picture dslomov  路  106Comments

meisterT picture meisterT  路  98Comments

davido picture davido  路  61Comments