brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: compinit in ~/.zshrc turns on Tab completion for brew commands

Terminal
~/tips/tip-macos-zsh-compinit-brew-completion

autoload -Uz compinit

Makes Tab complete Homebrew commands and installed tools in zsh.

Press Tab after brew ins in a fresh zsh setup on a Mac and you may get nothing useful. Homebrew ships completion files for zsh, but they sit in Homebrew’s own folder, and zsh only uses them once its completion system is running.

According to the Homebrew docs, brew shellenv adds Homebrew’s zsh completion folder to FPATH. The docs ask you to make sure that line runs before zsh initialises completion. Then add this to ~/.zshrc:

autoload -Uz compinit
compinit

Open a new tab, type brew up and press Tab: zsh now offers the matching brew commands. Formulae that ship their own zsh completions, like many command-line tools, get Tab completion through the same folder.

Skip this if you use Oh My Zsh: it calls compinit when it loads, and a second call only slows your startup. External Homebrew commands are the exception: their completions are not linked automatically, and brew completions link turns them on.

The caveat is the warning about insecure directories that zsh sometimes prints. Run compaudit to list the folders it means, and remove group or world write access only from those. The Homebrew docs say plainly not to change permissions recursively across the whole Homebrew prefix, and I’d follow that. A blanket chmod there causes more trouble than the warning.

Further reading: Homebrew: brew Shell Completion

More Terminal tips ioreg -rn AppleSmartBattery | grep CycleCount Terminal can save your windows and tabs as a window group Export a Terminal profile to a .terminal file and import it on another Mac mc hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000039,"HIDKeyboardModifierMappingDst":0x700000029}]}' All Terminal tips (116) All topics

Link