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

Add shell completion scripts #40

Closed
zaquestion opened this issue Nov 9, 2017 · 15 comments
Closed

Add shell completion scripts #40

zaquestion opened this issue Nov 9, 2017 · 15 comments

Comments

@zaquestion
Copy link
Owner

Cobra has some docs on generating autocompletion scripts for bash: https://github.com/spf13/cobra/blob/master/bash_completions.md

@zaquestion
Copy link
Owner Author

Using the cobra generated bash completion is ended up being rather difficult to use in conjunction with git's bash completion. Moreover, bash completion is clearly well beyond my meager mind. I did put up some work at making a completion script by hand in e1afa8b which supports completing the commands but not the arguments.

@sumnerevans
Copy link

It would be nice to create zsh completions as well.

@claytonrcarter
Copy link
Collaborator

I'm working on completions for fish, which is actually fairly straightforward, but it's also all manual and ... a little tedious. I see that there is a pending PR to enable fish completions in cobra but I'm still too fresh to go and cobra to understand what the docs are saying. I'll post my completions when I get them settled.

@zaquestion
Copy link
Owner Author

Can't make any promises, but Ill try and run the code in that PR and generate the fish completion for you. Hopefully it'll at least be a good jumping off point, but if it's generating good completions then we might be able to poke some folks for a merge

@zaquestion
Copy link
Owner Author

Something to keep in mind here is that lab will no longer be a git wrapper in 1.0 -- instead we'll aim to use "git extensions" (or w/e their called) with aliases in git to achieve the same result. Hopefully this should simplify the completetion problem dramatically. In any cases it's likely not worth the headache to get completions working in conjunction with gits completions. I'd suggest focusing on just completing labs commands

@zaquestion
Copy link
Owner Author

@claytoncarter an example of using cobras completion generators can be seen in https://github.com/zaquestion/lab/pull/205/files

@zaquestion zaquestion changed the title Add bash completion script Add shell completion scripts Nov 6, 2018
@claytonrcarter
Copy link
Collaborator

Thanks, and that makes sense, especially if completions are a pain to get right in bash. FWIW, fish makes it trivial to "inherit" completions from other commands: complete -f -c lab -w git tells fish to "wrap" git when completing the lab command.

@zaquestion
Copy link
Owner Author

zaquestion commented Nov 6, 2018

👀 !!

@rsteube
Copy link
Collaborator

rsteube commented Nov 27, 2018

Got some basic zsh completion working: https://github.com/rsteube/lab-completion

@zaquestion
Copy link
Owner Author

@rsteube Thats exciting, if the completions work I'm open to merging the changes into lab (even if that means using a fork of cobra). I'm sure the community would really appreciate completion scripts.

P.S. If you can do the same thing for bash I'd deeply appreciate it ❤️

@MartinDelille
Copy link
Contributor

I would be very happy to use this in zsh!

@rsteube
Copy link
Collaborator

rsteube commented Nov 27, 2018

I don't know much yet about how to do the argument completion in bash, but the command completion can be generated with cobra pretty easy. I just need to do some cleanup, since i abused some stuff meant for bash in cobra for the zsh generation. Will have a look at it.

@claytonrcarter
Copy link
Collaborator

Excellent work, @rsteube! Now that you've given an inch, may I ask for a mile? 😄

Any chance you would take a look at merging spf13/cobra#754 into your fork of cobra so that we can try adding fish completions, too? It looks like that PR only adds new files, doesn't change any code, and adds the Command.GenFishCompletion() function.

@rsteube
Copy link
Collaborator

rsteube commented Nov 29, 2018

@zaquestion
Copy link
Owner Author

I think we pretty much have this at this point, always room to improve, but I've been enjoying autocomplete on commands for some time now.

1.0 automation moved this from To Do to Done Aug 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
1.0
  
Done
Development

No branches or pull requests

5 participants