Reputation: 16116
After trying to move back from oh-my-zsh to a lighter zsh configuration I've installed the zsh-completions
plugin which requires to have the following when installed via homebrew:
if type brew &>/dev/null; then
fpath=${HOMEBREW_PREFIX}/share/zsh-completions:$fpath
autoload -Uz compinit
compinit
fi
Problem is that it does not work properly as it can't find compinit
and I got the next error:
zsh: compinit: function definition file not found
Upvotes: 2
Views: 14252
Reputation: 1296
I installed the zsh from source with prefix to my home. I got this same error, and found out that the new zsh does not have its functions folder on its fpath by default.
fpath=($fpath [prefix]/share/zsh/[version]/functions)
in the beginning of my ~/.zshrc solved the problem. Where
Upvotes: 0
Reputation: 589
In my case, after update macOS to:
ProductName: macOS
ProductVersion: 13.3
BuildVersion: 22E252
I had problem with zsh
:
/Users/myuser/.zshrc:13: compinit: function definition file not found
Wrong .zshrc
:
fpath=(~/.zsh/completion /usr/local/share/zsh/site-functions /usr/share/zsh/site-functions /usr/share/zsh/5.8.1/functions)
Because directory with name 5.8.1
didn't exist and completes didn't load.
compinit
Correct .zshrs
:
fpath=(~/.zsh/completion /usr/local/share/zsh/site-functions /usr/share/zsh/site-functions /usr/share/zsh/5.9/functions)
autoload -Uz compinit && compinit
Upvotes: 2
Reputation: 101
for me, It's the privilege, after fix them, it works well.
sudo chmod a+x /usr/local/lib/zsh
sudo chmod a+r /usr/local/lib/zsh
sudo chmod a+r /usr/local/lib/zsh/5.9
sudo chmod a+r /usr/local/lib/zsh/5.9/zsh
sudo chmod a+x /usr/local/lib/zsh/5.9
sudo chmod a+x /usr/local/share/zsh
sudo chmod a+r /usr/local/share/zsh
sudo chmod a+xr /usr/local/share/zsh/5.9
Upvotes: -3
Reputation: 41
maybe it's Lmod that cause the problem. See this article: Lmod FAQ
If my startup shell is bash or tcsh and I start zsh, why do I get a message that is like: “/etc/zsh/zshrc:48: compinit: function definition file not found” Lmod supports both zsh and ksh. Both these shell use shell var. FPATH but in very different ways. The issue is that some bash or tcsh users run ksh scripts and need access to the module command. In the K-shell, the env. var. FPATH is exported and is the path to where the module shell function is found. Z-shell also uses FPATH to point to tool like compinit and others. By exporting FPATH, Z-shell does not change the value of FPATH which means that the zsh user can not find all the functions that make it work. The solution is to add “unset FPATH” in your startup files before “exec zsh”.
In my case I have to uninstall the Lmod to ensure that both direct ssh and VSCode terminal run zsh completion correctly.
Upvotes: 4
Reputation: 16116
After seeing the value set using echo $fpath
I realised that homebrew caveat suggestion had the wrong code and it didn't include the folder where compinit function is.
The fix is can be done easily, replacing:
fpath=${HOMEBREW_PREFIX}/share/zsh-completions:$fpath
with
export fpath=(${HOMEBREW_PREFIX}/share/zsh-completions $fpath)
fixed the problem.
Upvotes: 3