ohmyzsh / ohmyzsh

🙃 A delightful community-driven (with 2,300+ contributors) framework for managing your zsh configuration. Includes 300+ optional plugins (rails, git, macOS, hub, docker, homebrew, node, php, python, etc), 140+ themes to spice up your morning, and an auto-update tool so that makes it easy to keep up with the latest updates from the community.
https://ohmyz.sh
MIT License
172.04k stars 25.78k forks source link

Suddenly OMZ gives compdef: command not found #10702

Closed konsbn closed 2 years ago

konsbn commented 2 years ago

Discussed in https://github.com/ohmyzsh/ohmyzsh/discussions/10701

Originally posted by **konsbn** February 17, 2022 Out of nowhere I am being greeted with this message as I fire up a new terminal. I haven't done anything with my .zshrc or the config files. ```/home/sbn/.oh-my-zsh/oh-my-zsh.sh:126: compinit: function definition file not found /home/sbn/.oh-my-zsh/lib/completion.zsh:78: bashcompinit: function definition file not found zsh: compdef: command not found... /home/sbn/.oh-my-zsh/lib/termsupport.zsh:108: add-zsh-hook: function definition file not found /home/sbn/.oh-my-zsh/lib/termsupport.zsh:109: add-zsh-hook: function definition file not found /home/sbn/.oh-my-zsh/lib/theme-and-appearance.zsh:2: colors: function definition file not found /home/sbn/.oh-my-zsh/lib/vcs_info.zsh:3: is-at-least: function definition file not found /home/sbn/.oh-my-zsh/lib/vcs_info.zsh:3: is-at-least: function definition file not found zsh: compdef: command not found... zsh: compdef: command not found... zsh: compdef: command not found... zsh: compdef: command not found... /home/sbn/.oh-my-zsh/plugins/git/git.plugin.zsh:140: is-at-least: function definition file not found zsh: compdef: command not found... zsh: compdef: command not found... zsh: compdef: command not found... zsh: compdef: command not found... zsh: compdef: command not found... zsh: compdef: command not found... /home/sbn/.oh-my-zsh/plugins/git/git.plugin.zsh:282: is-at-least: function definition file not found /home/sbn/.oh-my-zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh:59: is-at-least: function definition file not found zsh-syntax-highlighting: Failed to load add-zsh-hook. Some speed optimizations will not be used. zsh-syntax-highlighting: failed loading add-zsh-hook. /home/sbn/.oh-my-zsh/custom/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh:742: add-zsh-hook: function definition file not found zsh: compdef: command not found... ``` Please help me resolve this issue
rwmitchell commented 2 years ago

I believe compdef is defined in:

PATH/share/zsh/VERSION/functions/compinit

where PATH and VERSION will depend on your installation.

Are those files still ok?

mcornella commented 2 years ago

Same as https://github.com/ohmyzsh/ohmyzsh/issues/10697. Have you updated from 5.8 to 5.8.1? If so, can you post the output of typeset -p fpath?

zapateo commented 2 years ago

I had the same problem on Fedora 35 Workstation, after updating Zsh from 5.8 to 5.8.1. The FPATH variable was pointing to /usr/share/zsh/5.8/functions instead of /usr/share/zsh/5.8.1/functions.

Rebooting the system solved the problem (a logout wasn't enough, not sure why).

mcornella commented 2 years ago

Check for changes to $fpath or $FPATH in your zshrc or similar. It might be that somewhere something is doing export FPATH, which shouldn't happen ($fpath and $FPATH are tied variables and never should be exported).

konsbn commented 2 years ago

I had the same problem on Fedora 35 Workstation, after updating Zsh from 5.8 to 5.8.1. The FPATH variable was pointing to /usr/share/zsh/5.8/functions instead of /usr/share/zsh/5.8.1/functions.

Rebooting the system solved the problem (a logout wasn't enough, not sure why).

mcornella commented 2 years ago

Rebooting the system solved the problem (a logout wasn't enough, not sure why).

See https://github.com/ohmyzsh/ohmyzsh/issues/10702#issuecomment-1042708514. Can you run typeset -p fpath and post the output so I can see if it is exported?

mcornella commented 2 years ago

If you followed the wrong advice on https://github.com/ohmyzsh/ohmyzsh/issues/4607 or other threads, it's likely you have a line in your .zshrc file saying export FPATH. YOU SHOULD DELETE THAT LINE, otherwise this problem will keep happening every time you update your zsh version.

xapienz commented 2 years ago

@mcornella

Can you run typeset -p fpath and post the output so I can see if it is exported?

Mine is this:

$ typeset -p fpath
typeset -aT FPATH fpath=( /home/xapienz/.oh-my-zsh/plugins/git /home/xapienz/.oh-my-zsh/functions /home/xapienz/.oh-my-zsh/completions /home/xapienz/.oh-my-zsh/cache/completions /usr/share/Modules/init/zsh-functions /usr/local/share/zsh/site-functions /usr/share/zsh/site-functions /usr/share/zsh/5.8/functions )

However, opening a new terminal doesn't solve the issue.

I didn't try to reboot and I believe that ohmyzsh updates shouldn't require reboots, so I made a symlink as a local workaround: sudo ln -s /usr/share/zsh/5.8.1 /usr/share/zsh/5.8

rwmitchell commented 2 years ago

"I didn't try to reboot and I believe that ohmyzsh updates shouldn't require reboots,"

omz doesn't require a reboot, however, your system updated ZSH and apparently did so in a way that breaks current running zsh sessions.

xapienz commented 2 years ago

@rwmitchell You are right, I was confused between zsh and ohmyzsh upgrades, because I saw several reports like this, and thought that it was caused by ohmyzsh update. Looks like zsh itself is the culprit

mcornella commented 2 years ago

The "workaround" is only useful until you reboot, so I don't see why you'd prefer that. If this happened because of Zsh, it'll happen again when you update to the next Zsh version.

mcornella commented 2 years ago

Thank you for the sponsorship by the way!

xapienz commented 2 years ago

The "workaround" is only useful until you reboot

Yes, I did it exactly because I don't want to reboot :) When I reboot, it will get fixed in fpath, according to comments above, and I will be safe until next time.

tik9 commented 2 years ago

I get ln: /usr/share/zsh/5.8: Read-only file system on Mac Monterey when doing sudo ln -s /usr/share/zsh/5.8.1 /usr/share/zsh/5.8. I did csrutil disable because before it, I got permission denied with the ln command. Seems like one has to consider this

rwmitchell commented 2 years ago

Or maybe just don’t install in /usr

Not to be flip, corporate lockdown policies are worse than Apple's. Installing non-apple programs in $HOME/local is a reasonable workaround. It also has the advantage of getting backed up with your HOME and makes it easy to keep OS updates separate from your own.

tik9 commented 2 years ago

You mean copy zsh folder to $home/zsh from usr/share/ and then do the ln in it? Should I leave /usr/local/share/zsh as is? And I have to change the last entry of $fpath - current /usr/share/zsh/5.8.1/functions - to $home/zsh/5.8.1/functions?

rwmitchell commented 2 years ago

No.

I was assuming you were installing zsh by compiling from source and could therefore use:

./configure --prefix=$HOME/local

but now you're talking about copy files from /usr/share into /usr/local/share...how did you get files in /usr/share to begin with if you can't create files there now? If you're using Apple's installation, it should already be using 'its' latest version without needing to create a symlink to it.

tik9 commented 2 years ago

The default shell on Mac Monterey is zsh and the default zsh folder besides /bin/zsh is /usr/share. So I take your point, and try to uninstall zsh or change the system zsh dir. A google search with mac change default system zsh directory to home does not result well .So no idea how to do it. this post about installing with homebrew does not help here.

phdbrianlee commented 1 year ago

sudo ln -s /usr/share/zsh/5.8.1 /usr/share/zsh/5.8 solved my issue on 5.13.6-200.fc34.x86_64.