Sdk: Port zsh shell completion to #compdef

Created on 29 Mar 2018  路  3Comments  路  Source: dotnet/sdk

Our current shell completion for zsh uses compctl. This makes it hard for any packages (like .deb, or .rpm) to register these completions as system-wide by default. We can't simply copy the file at /usr/share/zsh/site-functions/ and call it a day. They wont get picked up. As far as I can tell, zsh actually only supports #compdef-style completions for this: http://zsh.sourceforge.net/Doc/Release/Completion-System.html#Autoloaded-files

We should port the completions to the new #compdef format instead of using the older compctl-format which has been obsolete since the 90s.

Most helpful comment

@omajid I have opened a PR

I hope to make it clear that it is 100% @mcornella's code an I simply just formed it into a PR!

All 3 comments

It shouldn't be too hard, just use compadd instead of reply=(). This would be the whole file:

#compdef dotnet

local completions=("$(dotnet complete "$words")")
compadd "${(ps:\n:)completions}"

And the file would be called _dotnet to match the convention.

@mcornella Oh, that's nice! Can you do a PR?

@omajid I have opened a PR

I hope to make it clear that it is 100% @mcornella's code an I simply just formed it into a PR!

Was this page helpful?
0 / 5 - 0 ratings