
When I try to run the proposed script in my `~/.bashrc` file I get this output: ``` -bash: have: command not found -bash: have: command not found -bash: have: command not found -bash: have: command not found -bash: have: command not found -bash: have: command not found -bash: have: command not found -bash: have: command not found -bash: have: command not found -bash: have: command not found -bash: [: =: unary operator expected # ... ``` It goes on for quite some time and does not give me bash completion. When I execute `source "$(brew --prefix)/etc/bash_completion"` it works and I get bash completion. This script also emits a helpful error message letting people know if bash completion was not installed already. I'll also add that the bash completion script takes a fairly long amount of time. I've seen between one quarter and a half of a second to execute it: ``` $ time source "$(brew --prefix)/etc/bash_completion" real 0m0.254s ``` Though that's unrelated to this PR, making a note of it.
1.9 KiB
Homebrew Shell Completion
Homebrew comes with completion definitions for the brew
command. Some packages also provide completion definitions for their own programs.
zsh
, bash
and fish
are currently supported. (Homebrew provides brew
completions for zsh
and bash
; fish
provides its own brew
completions.)
You must configure your shell to enable the completion support. This is because the Homebrew-managed completions are stored under HOMEBREW_PREFIX
, which your system shell may not be aware of, and because it is difficult to automatically configure bash
and zsh
completions in a robust manner, so the Homebrew installer cannot do it for you.
Configuring Completions in bash
To make Homebrew's completions available in bash
, you must source the definitions as part of your shell startup. Add the following to your ~/.bashrc
file:
if type brew 2&>/dev/null; then
source "$(brew --prefix)/etc/bash_completion"
else
echo "run: brew install git bash-completion"
fi
Configuring Completions in zsh
To make Homebrew's completions available in zsh
, you must get the Homebrew-managed zsh site-functions on your FPATH
before initialising zsh
's completion facility. Add the following to your ~/.zshrc
file:
if type brew &>/dev/null; then
FPATH=$(brew --prefix)/share/zsh/site-functions:$FPATH
fi
This must be done before compinit
is called. Note that if you are using Oh My Zsh, it will call compinit
for you, so this must be done before you call oh-my-zsh.sh
.
You may also need to forcibly rebuild zcompdump
:
rm -f ~/.zcompdump; compinit
Additionally, if you receive "zsh compinit: insecure directories" warnings when attempting to load these completions, you may need to run this:
chmod go-w "$(brew --prefix)/share"
Configuring Completions in fish
No configuration is needed in fish
. Friendly!