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

feat: Better ZSH shell completion #38

Closed
Irubataru opened this issue Sep 4, 2018 · 9 comments
Closed

feat: Better ZSH shell completion #38

Irubataru opened this issue Sep 4, 2018 · 9 comments

Comments

@Irubataru
Copy link

To make browsing issues easier it would be really great if we could have shell completion on par with git completion in zsh (not sure how well it works in bash). Ideally typing git bug show <TAB> would show a list of bugs similar to how git checkout <TAB> shows a list of branches and commits (see picture).

git_tab_complete

@MichaelMure
Copy link
Collaborator

It will depend on better support in cobra.

There is a PR open for that but the author is on hold for personal reason.

@Irubataru
Copy link
Author

I see, interesting. I sort of assumed that shell completion was handled by separate completion scripts, but I guess it makes sense that you use the git-bug executable to handle lookup of the information that zsh etc would need.

@MichaelMure MichaelMure changed the title feat: Better shell completion feat: Better ZSH shell completion Sep 4, 2018
@MichaelMure
Copy link
Collaborator

Better ZSH completion landed: https://github.com/MichaelMure/git-bug/tree/master/misc/zsh_completion

@Irubataru could you give it a try ?

@Irubataru
Copy link
Author

Sorry for the late reply, but I finally got around to trying it out and when I try to autocomplete git bug show I get the following message:

_arguments:comparguments:325: invalid option definition: (-f --field)-f[Select field to display. Valid values are [author,authorEmail,createTime,humanId,id,labels,shortId,status,title,actors,participants]]:
_arguments:comparguments:325: invalid option definition: (-f --field)-f[Select field to display. Valid values are [author,authorEmail,createTime,humanId,id,labels,shortId,status,title,actors,participants]]:
_arguments:comparguments:325: invalid option definition: (-f --field)-f[Select field to display. Valid values are [author,authorEmail,createTime,humanId,id,labels,shortId,status,title,actors,participants]]:

and if I try to tab complete git bug ls then I get

_arguments:comparguments:325: invalid option definition: (*-s *--status)*-s[Filter by status. Valid values are [open,closed]]:
_arguments:comparguments:325: invalid option definition: (*-s *--status)*-s[Filter by status. Valid values are [open,closed]]:
_arguments:comparguments:325: invalid option definition: (*-s *--status)*-s[Filter by status. Valid values are [open,closed]]:

I installed it wit the go get method, and placed the git-bug file in the folder you linked somewhere my zsh instance could find it.

@MichaelMure
Copy link
Collaborator

Ha, interesting. It's possibly because the completion is generated for git-bug and not git bug.

The bash completion require a very minimal adaptor function: https://github.com/MichaelMure/git-bug/blob/master/commands/root.go#L44-L49

Unfortunately, I have zero knowledge about ZSH completion. Would you be able to fix that ?

@Irubataru
Copy link
Author

Irubataru commented Jun 30, 2019

I tried with both git-bug and git bug, and it makes no difference, so I don't think that is the issue. I think I found it though, it appears to be due to the brackets in the explanation strings, e.g. as you can see in line 141.

https://github.com/MichaelMure/git-bug/blob/aa4464dbba0b1e0ce39ae53e35971e6924d404d3/misc/zsh_completion/git-bug#L138-L146

I use zsh, but I have never tried to write completion for it. However, if you escape the inner brackets as \[ and \] then I do not get those error messages anymore. I thought about making a quick PR for it, but it appears that you generate the completion scripts from go, so maybe you have to fix it at a different level.

Also, there is no completion for completing issue numbers. If you look at the zsh file and the bash file, you can see that the bash file has a lot more logic in it. The zsh file only completes command names and optional argument strings. I played around with it for a bit and got something basic working, so maybe I could help out with that if I ever find the time, or is that something your framework should support by itself?

@MichaelMure
Copy link
Collaborator

The situation is that git-bug use Cobra as the command line parser, and this library can generate the ZSH completion. They just landed a complete rewrite of this, so it's possible there is a bug lurking somewhere. The code generating the file is there: https://github.com/spf13/cobra/blob/master/zsh_completions.go

As for the custom completion of bug ID, it seems that Cobra doesn't support that at the moment for ZSH: https://github.com/spf13/cobra/blob/master/zsh_completions.md

That said, it's very much in line with what they want to support (it's possible for bash). git-bug has the ls-id command so it would be pretty easy to plug there. Note though that all te git-bug commands support giving a simple prefix, so you don't need that much the completion.

@MichaelMure
Copy link
Collaborator

The bracket problem is fixed with this PR upstream: spf13/cobra#899

@MichaelMure
Copy link
Collaborator

This has been working for long.

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

2 participants