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: fish completion #725

Open
yschimke opened this issue Jun 15, 2019 · 8 comments
Open

Feature Request: fish completion #725

yschimke opened this issue Jun 15, 2019 · 8 comments
Labels
status: help-wanted 🆘 theme: auto-completion An issue or change related to auto-completion theme: integration An issue or change related to integration with other frameworks, shells or operating systems
Milestone

Comments

@yschimke
Copy link

I think fish completion is generally much simpler than bash e.g. see examples below with baked in completions "atlassian github" etc. But the functions at the top actually use the command itself to generate context sensitive completions by calling the code inside the app. Good for URLs etc.

https://github.com/yschimke/cooee-cli/blob/master/src/dist/fish/cooee.fish

function __fish_complete_cooee_command
	cooee --fish-complete (commandline -ct)
end

function __fish_complete_add_command
	cooee --option-complete (commandline -ct)
end

function __fish_complete_remove_command
	cooee --option-complete (commandline -ct)
end

complete -c cooee -x -d 'Cooee CLI' -a '(__fish_complete_cooee_command)'
complete -c cooee -l debug -d 'Show debug output'
complete -c cooee -s h -l help -d 'Help options'
complete -c cooee -l login -d 'Login and link account'
complete -c cooee -l logout -d 'Unlink account'
complete -c cooee -s V -l version -d 'Output version and exit'
complete -c cooee -l repl -d 'REPL'

complete -c cooee -l list -d 'List apps'
complete -c cooee -l add -x -d 'Add app' -a '(cooee --option-complete add)'
complete -c cooee -l remove -x -d 'Remove app' -a '(cooee --option-complete remove)'

complete -c cooee -l token -x -d 'Provide specific authorization token'
#complete -c cooee -l tokenSet -x -d 'Set a named authorization token'

complete -c cooee -l authorize -x -d 'Authorize a provider' -a "atlassian github google trello strava"
complete -c cooee -l option-complete -x -a "option-complete command-complete authorize" -d 'Complete possible options'

complete -c cooee -l command-complete -d 'Complete possible command'
@remkop
Copy link
Owner

remkop commented Jun 16, 2019

Thanks for the suggestion!
Fish looks very interesting.

Do you think you’ll be able to provide a pull request?

@yschimke
Copy link
Author

yschimke commented Jun 16, 2019

@remkop Fair question, It's unlikely I will in next 6 months due to

  1. I have working code that is app specific
  2. I have other project commitments, work+personal projects+OkHttp
  3. I'm hesitent to build something like this and not support it. It would be a gamble that utility proved itself enough to gain support within existing users.

So feel free to close this and #726 but it's so palpably close to what I need to delete a tone of code in my own apps.

Feel free to close, this is a suggestion, I don't have plans to actively work on this.

@remkop
Copy link
Owner

remkop commented Jun 16, 2019

No worries!

It is great if people can contribute a PR, so I always ask :-)

I wasn’t aware of fish shell. I had a quick look and it may be quite straightforward to generate a completion script from the picocli model.
It’s still a good suggestion and I don’t plan to close the ticket.

@yschimke
Copy link
Author

It's a great choice for your interactive (only) shell. And in the examples above you can see how sensible the completion logic is.

complete -c cooee -s V -l version -d 'Output version and exit'

-s is short option, -l is long option with -- prefix, and -d is description.

@remkop
Copy link
Owner

remkop commented Jun 16, 2019

Yes that looks straightforward.

I need to look a bit further to see how subcommands (and nested sub-subcommands) are handled, and whether there's a facility for completing options that don't look like POSIX short options or GNU long options (like java -version), but the above looks promising.

Update:

Useful links:

@remkop remkop added theme: auto-completion An issue or change related to auto-completion status: help-wanted 🆘 theme: integration An issue or change related to integration with other frameworks, shells or operating systems labels May 18, 2020
@remkop remkop added this to the 4.4 milestone May 21, 2020
@remkop remkop modified the milestones: 4.4, 4.5 Jun 28, 2020
@remkop remkop modified the milestones: 4.5.2, 4.6 Oct 14, 2020
remkop added a commit that referenced this issue Nov 18, 2020
@remkop remkop modified the milestones: 4.6, 4.7 Dec 26, 2020
@benkeil
Copy link

benkeil commented Jan 7, 2022

Are there any news?

@remkop
Copy link
Owner

remkop commented Jan 7, 2022

@benkeil I haven’t looked at this. My time available to spend on picocli is unfortunately extremely limited.

Pull requests are very welcome. 😅

@remkop remkop modified the milestones: 4.7, 4.8 Jun 28, 2022
@remkop remkop modified the milestones: 4.8, 4.9 Aug 9, 2022
@volkov
Copy link

volkov commented Jan 15, 2023

I've made some very dirty proof of concept realization for fish completion in #1925

It successfully generated completion for my simple app, but it's definitely not universal at the moment.
I think now it works only for apps with sub-commands.

If anybody interested, they can try to generate completion for their app from #1925

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: integration An issue or change related to integration with other frameworks, shells or operating systems
Projects
None yet
Development

No branches or pull requests

4 participants