2

How can I load Swift auto completions for my ZSH shell, i.e. when I type swift [TAB] it should show possible sub-commands.

blackjacx
  • 9,011
  • 7
  • 45
  • 56
  • I don't think you can. I believe autocompletion is only for the actual command (swift) and not for the arguments/options – Joakim Danielson Feb 11 '21 at 12:07
  • @JoakimDanielson : zsh is designed to make subcommand completion feasible. It just takes some work. For instance, `git` subcommand completion is implemented in this way. – user1934428 Feb 11 '21 at 14:32
  • @blackjacx : Something like [this](https://stackoverflow.com/questions/9000698/completion-when-program-has-sub-commands)? – user1934428 Feb 11 '21 at 14:33
  • @user1934428 That is very interesting, I didn't know that. Where does it come from so to speak, is it some tool we users need to run or is the creator of the command (like git) that adds the support or...? – Joakim Danielson Feb 11 '21 at 14:34
  • 1
    @JoakimDanielson : The discussion under the link I pointed to in my comment to the OP also contains a link for where to find information to implement your own subcommand completion. – user1934428 Feb 11 '21 at 14:36

1 Answers1

2

You can achieve that by using swiftpm zsh plugin from ohmyzsh repository.

If you are using ohmyzsh, just add swiftpm plugin in your .zshrc file:

plugins=(
  swiftpm
)

and restart terminal.

gcharita
  • 7,729
  • 3
  • 20
  • 37
  • Just being curious: Is there a particular reason, why the ohmyzsh framework is necessary for using that plugin? – user1934428 Feb 11 '21 at 14:35
  • @user1934428 it isn't? Sorry, I never used one without the other. – gcharita Feb 11 '21 at 14:41
  • 1
    uhhhh awesome exactly what I searched for @user1934428 yeah this is necessary since OhMyZSH implements these specific plugins: https://github.com/ohmyzsh/ohmyzsh/wiki/Plugins – blackjacx Feb 12 '21 at 11:08