12

In OS X, is there any way to have Zsh (I'm using Oh-my-zsh) tab-complete formulas?

E.g.

$ brew install em<TAB>

could expand to:

$ brew install emacs
slm
  • 363,520
  • 117
  • 767
  • 871
Josh
  • 1,694
  • 3
  • 16
  • 32

2 Answers2

12

Try installing the zsh-completions formula.

$ brew info zsh-completions
zsh-completions: stable 0.10.0, HEAD
https://github.com/zsh-users/zsh-completions
Not installed
From: https://github.com/Homebrew/homebrew/commits/master/Library/Formula/zsh-completions.rb
==> Caveats
To activate these completions, add the following to your .zshrc:

  fpath=(/usr/local/share/zsh-completions $fpath)

You may also need to force 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 /usr/local/share

It also looks like zsh may have some compatibility with bash completions. You could try that in conjunction with the bash-completions formula.

cpugeniusmv
  • 2,627
  • 17
  • 25
6

Homebrew provides it's own completion. You just need to link the file $(brew --prefix)/Library/Contributions/brew_zsh_completion.zsh to _brew somewhere in your $fpath.(See comment at the start of https://github.com/Homebrew/homebrew/blob/master/Library/Contributions/brew_zsh_completion.zsh)

zsh-completions recently removed its _brew completion in favour of that file, see https://github.com/zsh-users/zsh-completions/issues/305.


Update 2016-04-19: At some point(1) Homebrew updated its handling of zsh completion again. Now if you install zsh via Homebrew it should "just work". The file is installed to /usr/local/share/zsh/site-functions/_brew.

Orangenhain
  • 291
  • 3
  • 4
  • For anyone interested in `$fpath` and `$FPATH` to accommodate these new completion functions in `Zsh`, [this Q&A](http://unix.stackexchange.com/questions/26555/fpath-in-zsh-functions-and-site-functions) may be informative. – Amelio Vazquez-Reina Feb 08 '16 at 16:48
  • As of my writing, brew didn't install the _brew file under the mentioned directory. However I do see it here: `/home/linuxbrew/.linuxbrew/share/zsh/site-functions` And since I am using ohmyzsh that path doesn't seem to be included in `$FPATH`. – Arne Mar 23 '22 at 10:50
  • Also it seems `brew completions link` will add brew's shell completions to the shell. Not sure what it does in detail, though. – Arne Mar 23 '22 at 10:58