zsh-users / zsh-completions

Additional completion definitions for Zsh.
Other
7.02k stars 716 forks source link

oh-my-zsh installation instructions are sub-optimal #603

Open segevfiner opened 6 years ago

segevfiner commented 6 years ago

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)
felipecrs commented 3 years ago

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 https://github.com/ohmyzsh/ohmyzsh/issues/10412

felipecrs commented 3 years ago

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