shell - zsh-completions error when loading `zsh: compinit: function definition file not found` - TagMerge
4zsh-completions error when loading `zsh: compinit: function definition file not found`zsh-completions error when loading `zsh: compinit: function definition file not found`

zsh-completions error when loading `zsh: compinit: function definition file not found`

Asked 5 months ago
1
4 answers

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.

Source: link

0

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.

Source: link

0

oh-my-zshからより軽いzsh構成に戻ろうとした後、zsh-completionsプラグインをインストールしました。これは、homebrewを介してインストールするときに次のものが必要です。
if type brew &>/dev/null; then
    fpath=${HOMEBREW_PREFIX}/share/zsh-completions:$fpath

    autoload -Uz compinit
    compinit
fi
問題は、それが見つからないために正しく機能せずcompinit、次のエラーが発生したことです。
zsh: compinit: function definition file not found
修正は簡単に行うことができ、次のものを置き換えます。
fpath=${HOMEBREW_PREFIX}/share/zsh-completions:$fpath
export fpath=(${HOMEBREW_PREFIX}/share/zsh-completions $fpath)

Source: link

0

You could set the ZSH_DISABLE_COMPFIX flag in your ~/.zshrc config:
ZSH_DISABLE_COMPFIX="true"
compaudit | xargs chmod g-w
The solution is to ignore the insecure directories for the non-admin account, as described in the zsh docs and zsh-users/antigen@4c4f805:
# ~/.zshrc
autoload -Uz compinit
if [ "$(whoami)" = "YOUR_NON_ADMIN_USER" ]; then
  compinit -i # Ignore insecure directories
else
  compinit
fi
Ignore insecure directories on non-admin Zsh user … 8d6d3a0
Commit c496edb updated the Zsh completion initialization script. This
resulted in an error for non-admin users:

```
zsh compinit: insecure directories and files, run compaudit for list.
```

I have admin and non-admin user accounts on my macOS work machine. For
security purposes (supposedly), I have to do my day-to-day-work with the
non-admin account, and only use the admin account for tasks requiring
those perms, like software upgrades. This means my Zsh installation, and
all related directories, are owned by the admin account, and I can't
simply `chmod` and `chown` to the non-admin account.

The solution is to ignore insecure directories on the non-admin account.

~/.zshrc:

```zsh
autoload -Uz compinit
if [ "$(whoami)" = "brendon.smith" ]; then
  compinit -i # Ignore insecure directories
else
  compinit
fi
```

The non-admin account doesn't have permissions to perform any actions on
the pertinent directories, so ignoring them doesn't pose a security risk
that I'm aware of.

Also see zsh-users/zsh-completions#680.
don't use homebrew because it breaks permissions and installs files in /usr/local (but i can't do that because i need a package not available in macports) undo the damage homebrew did to /usr/local/share/zsh (btw, i didn't want homebrew for anything to do with my zsh and it never asked permission)
sudo rm -rf /usr/local/share/zsh/site-functions
sudo chown root:admin rm -rf /usr/local/share/zsh
sudo chmod g-w /usr/local/share/zsh

Source: link

Recent Questions on shell

    Programming Languages