adaszko / complgen

Declarative bash/fish/zsh completions without writing shell scripts
Apache License 2.0
221 stars 7 forks source link

[FR] Add support of 'Descriptions (a.k.a. completion hints) to 'External commands' #16

Closed Drugoy closed 1 year ago

Drugoy commented 1 year ago

AFAIU complgen currently doesn't support descriptions (aka completion hints) with External commands: it looks like external commands are currently meant to be used only for getting a list of possible values and those values will be suggested to the user as autocompletion variants.

But in some cases it would be nice to have descriptions for those variants. Here's a minimal synthetic illustration of the feature request:

fake [--type <TYPE>];
<TYPE> ::= { echo 'bool "a boolean (true/false)"\nstr "a string"\nint "an integer"' };

I would like this .usage rule to produce an autocompletion that would suggest bool/str/int with a description next to them. Instead, currently it produces bool\ \"a\ boolean\ \(true/false\)\"/int\ \"an\ integer\"/str\ \"a\ string\" as values (so the supposed description is currently treated as a part of the value).

adaszko commented 1 year ago

Hi and thanks for a clear report. I happen to be working on this already and just pushed it, with the difference in that and external command should produce output in the form “completion\tdescription”. The reason is fish already uses that kind of syntax, so we reuse that for zsh too. For bash, that means filtering out the descriptions (anything that comes after a tab character will be ignored)

Drugoy commented 1 year ago

Awesome, thank you! I merely suggest to mention this detail (and better also illustrate it with an example) in the README.