zsh-users/zsh-completions

oh-my-zsh installation instructions are sub-optimal

segevfiner opened this issue · 2 comments

The current instructions: README.md#oh-my-zsh, suggest to add zsh-completions to plugins and rerun compinit.

But that's sub-optimal. This will cause Zsh to rebuild the completion cache twice on each Zsh invocation: The first when you source oh-my-zsh, and the second time when you rerun compinit. This defeats the whole point of the completions cache, and will negatively impact the startup time of Zsh.

Sadly, oh-my-zsh doesn't seem to have a way for a plugin to add more fpath entries, besides the root folder of the plugin, before it invokes compinit. I think it's best to just suggest adding the zsh-completions src dir to fpath before the source $ZSH/oh-my-zsh.sh line, in order to avoid this issue. Something like this:

fpath=($ZSH/custom/plugins/zsh-completions/src $fpath)

Just to clarify, the suggestion is to replace:

plugins=(… zsh-completions)

source "$ZSH/oh-my-zsh.sh"

autoload -U compinit && compinit

With:

fpath+="${ZSH_CUSTOM:-"$ZSH/custom"}/plugins/zsh-completions/src"

source "$ZSH/oh-my-zsh.sh"

The above is just an optimized version of the previously suggested, which takes the ZSH_CUSTOM into account if set.

References ohmyzsh/ohmyzsh#10412

It's important to remove zsh-completions from the OMZ plugins because otherwise fpath would be filled with the same contents twice.