mac终端打开报complete 13 command not found compdef异常处理以及命令补全功能实现
mac终端报complete未找到异常
mac打开终端报如下错误
"complete:13: command not found: compdef" message when launching Terminal
问题处理,参考https://apple.stackexchange.com/questions/296477/my-command-line-says-complete13-command-not-found-compdef
1. 在~/.zshrc文件中追加如下内容
if [[ -n ${ZSH_VERSION-} ]]; then
autoload -U +X bashcompinit && bashcompinit
fi
2. 然后执行
source ~/.zshrc
3. 此时打开新的终端正常可以看到异常消失,但是若此时故障依旧,则检查.zshrc文件中是否有complete命令开头的语句,若有则去掉该语句,然后重新执行source ~/.zshrc即可
complete -o nospace -C /opt/homebrew/bin/terraform terraform
问题解析:
核查是否安装了zsh-completions,若没有则执行如下命令进行安装
brew install zsh-completions
安装完成之后根据如下提示
To activate these completions, add the following to your .zshrc:
if type brew &>/dev/null; then
FPATH=$(brew --prefix)/share/zsh-completions:$FPATH
autoload -Uz compinit
compinit
fi
You may also need to force rebuild `zcompdump`:
rm -f ~/.zcompdump; compinit
Additionally, if you receive "zsh compinit: insecure directories" warnings when attempting
to load these completions, you may need to run these commands:
chmod go-w '/opt/homebrew/share'
chmod -R go-w '/opt/homebrew/share/zsh'
执行相应操作,即在.zshrc文件中追加
if type brew &>/dev/null; then
FPATH=$(brew --prefix)/share/zsh-completions:$FPATH
autoload -Uz compinit
compinit
fi
然后再次执行source ~/.zshrc,完成该操作之后再次执行提示中的其他操作,如下所示
命令补全
terraform命令补全实现
在.zshrc文件中追加如下内容即可实现terraform命令的补全操作
complete -o nospace -C /opt/homebrew/bin/terraform terraform
kubectl命令补全
参考在 macOS 系统上安装和设置 kubectl | Kubernetes
在.zshrc文件中追加如下命令即可实现kubectl的命令补全功能
source <(kubectl completion zsh)