Zsh completions using generate-zsh-script output not working

With the advent of macOS Catalina and Xcode 11/Swift 5.1, I'm migrating from bash to zsh. This seems reasonable since zsh is now the default shell for Catalina.

The file genereated by swift package completion-tool generate-zsh-script is giving the following error when the shell starts: _swift:1: command not found: _arguments

Based on Moving to zsh, part 5: Completions – Scripting OS X, autoload -Uz compinit && compinit was added to the .zshrc file. Then the error changed to "_arguments:comparguments:325: can only be called from completion function".

Is the swift package completion-tool generate-zsh-script generated script expected to work for Catalina/Swift 5.1? Any information on how to get Swift completions to work in zsh?

2 Likes

Not sure if this is optimal, I ended up doing the following for now:

cd ~
mkdir ~/.zsh
swift package completion-tool generate-zsh-script > ~/.zsh/_swift
echo -e "fpath=(~/.zsh \$fpath)\n" >> ~/.zshrc
echo -e "autoload -Uz compinit && compinit" >> ~/.zshrc
1 Like