gpt4 book ai didi

zsh - 为什么zsh不能执行命令compdef?

转载 作者:行者123 更新时间:2023-12-03 14:51:40 30 4
gpt4 key购买 nike

我已经在 Ubuntu 18.04 上安装了 zsh 和 oh my zsh。我想对 kubectl 使用自动完成功能。因此我添加了 source <(kubectl completion zsh)到我的 ~/.zshrc 文件。

执行此脚本时,zsh 收到以下错误:

complete:13: command not found: compdef

kubectl 文档指出,当出现上述错误时,您应该将以下内容放在 .zshrc 文件的顶部:
autoload -Uz compinit
compinit

执行此操作并重新启动终端后,我收到相同的错误。

在 git-issue 中,我发现以下内容对遇到常见问题的人有所帮助:
#This will perform chmod g-w for each file returned by compaudit to remove write access for group
compaudit | xargs -I % chmod g-w "%"
#This will perform chown to current user (Windows and Linux) for each file returned by compaudit
compaudit | xargs -I % chown $USER "%"
#Remove all dump files (which normally speed up initialization)
rm ~/.zcompdump*
#Regenerate completions file
compinit

zsh 在运行脚本时记录以下内容:
kubescript:12457: command not found: _bash_comp

不幸的是,这并没有解决我的问题。我还能做些什么来解决我的问题?甚至仍然:我该怎么做才能找出导致它的原因?

最佳答案

我通过在 .zshrc 中使用以下代码修复了错误:

# K8s auto-complete
autoload -U +X compinit && compinit
source <(kubectl completion zsh)

你也可以使用 oh-my-zsh plugin如果您使用 oh-my-zsh。

关于zsh - 为什么zsh不能执行命令compdef?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58283701/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com