JoshMcguigan / shell_completion

Write shell completion scripts in pure Rust
Apache License 2.0
133 stars 5 forks source link

Zsh support #7

Open fenhl opened 5 years ago

fenhl commented 5 years ago

Is Zsh support in the scope of this project?

JoshMcguigan commented 5 years ago

I would like this crate to support shells other than Bash, but I have not yet found the time to experiment with Zsh. A preliminary review of some documentation (linked below) suggests it should be possible.

I think the primary difference as an end user of these completions would be that Zsh users would register a completion with a wrapper script which might look something like this (assuming the completions are for my_cli and the completion binary generated by shell_completion is _my_cli_completions).

#compdef my_cli
# put this in $fpath

compadd $(_my_cli_completions)

I'm not a Zsh user, so I have a couple open questions:

  1. Will this work at all? Can we make even a very basic proof of concept work in the way described above? In this scenario, can _my_cli_completions just return a space separated list of completions?
  2. How do we pass information about the text the user has entered before pressing tab into _my_cli_completions? Will it be passed automatically by the shell in the form of environment variables? Is there something additional we can add to the wrapper script to pull this information out and pass it into _my_cli_completions explicitly as arguments?

Any help here would be appreciated. I'd like to get to it myself in the next few weeks.

http://zsh.sourceforge.net/Doc/Release/Completion-System.html#Completion-System https://github.com/zsh-users/zsh-completions/blob/master/zsh-completions-howto.org https://mads-hartmann.com/2017/08/06/writing-zsh-completion-scripts.html#the-use-of-_arguments