Shell completions for the swift command

Hello All,

I was searching for the ability to install shell completions for the entire swift command tree into my current favourite shell, fish. Today I learned how to do this and I thought I would share it with you in case you couldn't find it, like me.

The completion generator can be found in swift package completion-tool. It supports completions for bash, zsh, and fish, like the swift-argument-parser. Here's how I added completions for fish:

swift package completion-tool generate-fish-script > ~/.config/fish/completions/swift.fish

You can also generate the completions for bash/zsh in a similar way. This guide from the argument parser library has some notes about those shells that might be helpful.

https://swiftpackageindex.com/apple/swift-argument-parser/1.5.0/documentation/argumentparser/installingcompletionscripts

Cheers,
Chris

4 Likes