Zsh’s command completion for some commands is unacceptably slow. After a bit of digging, I discovered using an atypically large hosts file causes problems. A one-line customisation to Zsh solved the issue.
Whenever I’d use tab completion on commands such as
ssh, my system would completely freeze. Zsh’s advanced command completion is
one of it’s killer features, so rather than switching back to Bash, this had
to be fixed.
As mentioned in a previous post, I use a custom hosts file as a lightweight alternative to browser ad-blocking. Unfortunately, this file is necessarily huge (~12,000 lines!), so it made sense for Zsh to die a slow death when trying to match a hostname.
The idea was to disable hostname completion. With a bit of perseverance with the zshcompsys(1) manual, I came up with:
:completion:* matches any context where tab completion can be used (any
command, path, glob etc).
hosts — the “tag” (or type of completion) —
accepts one parameter; either a path to a hosts file (defaulting to
/etc/hosts) or a boolean.
[^1]: DuckDuckGo is a nice alternative to Google. I particularly like the zero-click information, https url rewrites and the !bang syntax. Check it out!