Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request] Native zsh completion #294

Open
gyscos opened this issue Mar 5, 2018 · 11 comments
Open

[Feature request] Native zsh completion #294

gyscos opened this issue Mar 5, 2018 · 11 comments
Labels
status: help-wanted 🆘 theme: auto-completion An issue or change related to auto-completion theme: codegen An issue or change related to the picocli-codegen module theme: integration An issue or change related to integration with other frameworks, shells or operating systems type: enhancement ✨
Milestone

Comments

@gyscos
Copy link

gyscos commented Mar 5, 2018

Picocli currently can create bash completion files, and zsh has a compatibility tool to read bash completion files.

However, this only exposes basic autocompletion features (what bash itself support), and does not take advantage of the features zsh offer.

For instance, zsh can show a description for each command/option, as well as option aliases (short vs long options). There's a thousands pictures on the internet; here's one example for the git command:

screenshot from 2018-03-05 10-48-22

This behavior cannot be obtained from a bash completion file.

Therefore, I propose that a new Autocomplete.zsh static method be added, to output a zsh-native completion script that includes more details, like command and option description and aliases.

@remkop
Copy link
Owner

remkop commented Mar 5, 2018

I think that's great idea and that would be a very cool feature!
Will you be able to provide a pull request?

@hristo-vrigazov
Copy link

+1, this would be awesome

@remkop remkop added theme: auto-completion An issue or change related to auto-completion theme: codegen An issue or change related to the picocli-codegen module labels Sep 30, 2018
@yschimke
Copy link

The other relevant thing is that the file should be in FPATH and start with the #compdef line so shell login doesn't involve running all the scripts

https://github.com/zsh-users/zsh-completions/blob/master/zsh-completions-howto.org

@remkop
Copy link
Owner

remkop commented Jun 16, 2019

@yschimke thanks for the tip!

@yschimke
Copy link

The testing and debugging section of that doc is good also e.g.

| _complete_help | Ctrl+x h | displays information about context names, tags, and completion functions used when completing at the current cursor position |

@byteit101
Copy link

It's super hacky, and only supports the bare minimum needed for one-level descriptions on my specific app, but I made a first attempt at this on byteit101@7f9d1cf

I do plan on eventually getting around to cleaning it up to make it into an integrateable PR, but unfortunately I'm rather busy with other things for the next month or so, if anyone else wants to run with it.

@remkop
Copy link
Owner

remkop commented Jun 22, 2019

@byteit101 Thank you! I need a bit more time to look in detail, but this seems like a good start!

@yschimke
Copy link

yschimke commented May 16, 2020

Going to play around with my specific script for now, but this would be high impact given it's the default shell in OSX now.

@remkop
Copy link
Owner

remkop commented May 16, 2020

That would be great! PRs are always welcome!

@remkop remkop added the theme: integration An issue or change related to integration with other frameworks, shells or operating systems label May 21, 2020
@remkop remkop added this to the 4.4 milestone May 21, 2020
@remkop
Copy link
Owner

remkop commented Jun 17, 2020

@yschimke I saw your message on #502. Thanks! I am still working on some parser issues, but ZSH completion is high on my list of priorities. Once I make some progress on this your feedback will be very welcome!

UPDATE 2020/11/16

I was thinking about redesigning the logic for generating completion scripts to follow the Visitor pattern; I need to prototype this a bit to see how useful this would be. Something like this:

interface ModelVisitor<R,P> {
  R visit(CommandSpec command, P p);
  R visit(ArgGroupSpec group, P p);
  R visit(OptionSpec option, P p);
  R visit(PositionalParamSpec positional, P p);
}

Current call tree:

bash(String, CommandLine)
  generateEntryPointFunction
    generateFunctionCallsToArrContains
      [generateFunctionCallsToArrContains...] - recursively for nested subcommands
  generateFunctionForCommand - for all subcommands and nested descendant sub-subcmds
    generateCompletionCandidates - options with completion candidates
    generateOptionsSwitch - other options for which completions can be generated
    generatePositionParamCompletionCandidates - positionals with completion candidates
    generatePositionalParamsCases - other positionals for which completions can be generated

@remkop
Copy link
Owner

remkop commented Mar 9, 2022

@remkop remkop modified the milestones: 4.7, 4.8 Jun 28, 2022
@remkop remkop removed this from the 4.8 milestone Aug 9, 2022
@remkop remkop added this to the 4.9 milestone Aug 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: help-wanted 🆘 theme: auto-completion An issue or change related to auto-completion theme: codegen An issue or change related to the picocli-codegen module theme: integration An issue or change related to integration with other frameworks, shells or operating systems type: enhancement ✨
Projects
None yet
Development

No branches or pull requests

5 participants