ohmyzsh: command not found after starting zsh in AWS machines
$ zsh
complete:13: command not found: compdef
UPDATE: see solution at https://github.com/robbyrussell/oh-my-zsh/issues/4771#issuecomment-181122099
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 36 (18 by maintainers)
TL;DR aws-cli will get updated someday, until then:
sudo chmod a-r /etc/profile.d/aws-cli.shOh crap! You beat me to it. That’s exactly the problem. I’m reproducing the log at the end for future reference.
Explanation:
The
aws_zsh_completer.shfile is a part of aws/aws-cli. Funnily enough, @blueyed (who has made significant contributions to Oh My Zsh, hence the fun part) contributed the commit that dropped the call tocompinitbecause it broke completion: https://github.com/aws/aws-cli/commit/a2498c41b5bb7bbc189d3251081df1971597a510.Now, the really offending file is
/etc/profile.d/aws-cli.sh, because of sourcing the completion file without runningcompinit—or, at least, sourcing it in a point in time wherecompinitshould’ve already been called./etc/profile.dis soon enough in the initialization process thatcompinithasn’t been run yet. See all the startup files for reference. Also, theaws_zsh_completer.shfile says explicitly enough that the file should be sourced in the zshrc file:I don’t know which package the
aws-cli.shfile comes from, so I cannot submit a bug report; a quick google search only returns this file part of a Chef cookbook, which is correct because it runscompinitbefore, as well as a post in Japanese about this problem which suggests runningcompinitin a~/.zshenvfile to fix this problem.Solutions:
The latter solution will not work in your case though,
compinitwill be running twice and, while you won’t see the error again, the aws cli completion won’t work. You could then source theaws_zsh_completerfrom within your zshrc file but that’s a horrible contraption that I particularly hate.I think you can disable the loading of
/etc/profile.d/aws-cli.shby toggling off itsreadableattribute. Here’s the relevant part of the code that loads profile.d files:The
[ -r $file ]code checks the readable attribute of$file. So with a simplechmod a-r /etc/profile.d/aws-cli.shyou should be all set.Actionable items:
For everybody that posted here with this problem, you should make sure that you have the file
/etc/profile.d/aws-cli.sh, or that at least you are usingaws-cliin some way. If the former, you can already apply thechmodsolution above.If that’s not the case, post your diagnostic dump and we’ll figure it out.
Relevant part of the debug log. Notice the comment that says “make sure to run
compinitbefore” 😂👍 on the
chmod a-r /etc/profile.d/aws-cli.shtrick. Every time I logged into my AWS box I got that error and I died a little inside. Now it’s gone and I want to give everyone a hug.This is fixed as of aws-cli-1.11.83-1.46, pushed today.
I never considered that the printed error message was coming from my AWS box rather than from my local.
chmoding theaws-cli.shfile did the trick. Thanks for the sleuthing!Might be a corrupted compdump file. Try doing
rm ~/*zcompdump*and restarting zsh.This section (REDACTED) looks like it might be the problem, or at least part of it. It’s from
/etc/profile.d/aws-cli.shand/usr/share/zsh/site-functions/aws_zsh_completer.sh, which looks like a custom AWS client completion forzshbuilt onzsh’sbashcompinitportability layer, and redefining_bash_completeusing its own logic. It callsbashcompinit, but does not callcompinit. It is typicallycompinitwhich makescompdefand related functions available.This could be that the AWS client stuff assumes that it will be called after something else has called
compinit. When you’re running OMZ, it’s usuallyoh-my-zsh.shwhich callscompinit. (In your case that’s being done [down here on line 567 of that log.) But since this AWS stuff is being sourced from/etc/profile.d, it’s run before your~/.zshrc.Looks like that AWS client stuff may need to be revised if it’s being run from
/etc/profile.dahead of the user’s initialization files. Specifically, it (or something preceding it in the load order) would need to callcompinit. That may cause a problem with OMZ or normal~/.zshrcfiles which also callcompinit, because I think that resets the defined completions.