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

Zsh completion never suggests files but only options #886

Closed
corneliusweig opened this issue Jun 12, 2019 · 7 comments
Closed

Zsh completion never suggests files but only options #886

corneliusweig opened this issue Jun 12, 2019 · 7 comments

Comments

@corneliusweig
Copy link

An overhauled zsh completion was merged with #646. One drawback of that script is that it only ever suggests options. Say for example, I have a command cmd with option --foo. When I type

cmd <Tab><Tab>

I would expect to see a suggestion list of all files in the working dir. However, it actually adds a - and shows the --foo suggestion.

It would be much better to trigger option completion only when typing

cmd -<Tab><Tab>  # <-- note the dash

and otherwise show the standard list of files in the cwd.

/cc @rsteube @babysnakes

@rsteube
Copy link
Contributor

rsteube commented Jun 12, 2019

Since you added a specific completion for cmd you have overriden the default _files function.
Now unless you tell it that your command accept files it won't complete it for you.

command.MarkZshCompPositionalArgumentFile(1) might be the solution (complete files for first argument).

There's also the possibilty filtering by patterns:
https://github.com/spf13/cobra/blob/master/zsh_completions.go#L125

@corneliusweig
Copy link
Author

Thanks @rsteube, I was not aware that this had to be enabled manually. 👍

@blacktop
Copy link

@rsteube can you show a small example on how to add them? I am trying and it doesn't seem to work for sub commands?

@rsteube
Copy link
Contributor

rsteube commented Dec 16, 2019

There is a test using it:

r.MarkZshCompPositionalArgumentFile(1, "*.log")

You probably know, but if it's a sub command it needs to be called on the sub command and not on the root command. Can't think of any other reason right now why it's not working.

@blacktop
Copy link

blacktop commented Dec 16, 2019

I added it here:

https://github.com/blacktop/ipsw/blob/9b307d745c4a7b27f8567d281c0fa7ce0169c600/cmd/ipsw/cmd/device.go#L49

It doesn't seem to have any impact on what is output by running:

ipsw completion zsh

I would have expected to see "DeviceTree*" show up somewhere or _file

😕

@rsteube
Copy link
Contributor

rsteube commented Dec 16, 2019

I think it's because of the sub sub command "list": https://github.com/blacktop/ipsw/blob/9b307d745c4a7b27f8567d281c0fa7ce0169c600/cmd/ipsw/cmd/device_list.go#L15

That should set the list commond as positional argument 1 and thus override your file argument (both is probably not possible). When that is commented the Devicetree argument is rendered in the output.

@blacktop
Copy link

Ah thank you! I should simplify my sub sub subs into a more typical cli. I also confirmed if I remove the sub subs it does in fact work 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants