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

Enhanced shell completion #493

Closed
MichaelMure opened this issue Nov 1, 2020 · 4 comments
Closed

Enhanced shell completion #493

MichaelMure opened this issue Nov 1, 2020 · 4 comments
Labels
area/cli Relates to the CLI enhancement New feature or request

Comments

@MichaelMure
Copy link
Collaborator

Cobra, the library used to implement the CLI commands also generate the shell completion scripts, for bash, zsh, fish and powershell. This completion scripts are based on the description of each commands (living in https://github.com/MichaelMure/git-bug/tree/master/commands).

At the moment, those completion works decently, completing command names and flags. However it would be possible to do better. By teaching cobra (see https://github.com/spf13/cobra/blob/master/shell_completions.md#customizing-completions) about what is expected, it should be possible to:

  • disable the default completion showing files when it's not appropriate
  • complete based on git-bug specific terms (git bug ls [tab][tab] would also complete with query qualifiers)
  • complete based on git-bug specific data (git bug show [tab][tab] would complete with bug Ids, possibly with the bug title)
@MichaelMure MichaelMure added enhancement New feature or request help wanted area/cli Relates to the CLI labels Nov 1, 2020
@Ogguz
Copy link

Ogguz commented Jan 19, 2021

I want to work on this

@MichaelMure
Copy link
Collaborator Author

Yes please!

krobelus added a commit to krobelus/git-bug that referenced this issue Jan 24, 2021
This completes bug IDs in bash and fish.  I haven't gotten this to work in zsh.
In fish, the bug titles are shown as completion label, and can be searched for.
I don't know if/how other shells can show the completion label.
Maybe they don't use "\t" as separator but it seems to do no harm.

The interface does not yet seem ideal because sometimes subcommands and
bug IDs are both valid. Since there can be lots of bug IDs, they overshadow
the subcommands.
I wonder if instead of

	git bug status open 0123acd

we should use

	git bug status --open 0123acd

or if there's some other way to avoid ambiguity.

If that doesn't work out, fish has a -k/--keep-order flag, so subcommand
completions can be listed before bug IDs, but that's neither portable nor
a pretty solution.

Part of git-bug#493
@krobelus
Copy link
Contributor

As a first step, I have added bug ID completions. They work well in fish, I'm not sure how to make completions work in zsh.

krobelus added a commit to krobelus/git-bug that referenced this issue Jan 24, 2021
This completes bug IDs in bash and fish.  I haven't gotten this to work in zsh.
In fish, the bug titles are shown as completion label, and can be searched for.
I don't know if/how other shells can show the completion label.
Maybe they don't use "\t" as separator but it seems to do no harm.

The interface does not yet seem ideal because sometimes subcommands and
bug IDs are both valid. Since there can be lots of bug IDs, they overshadow
the subcommands.
I wonder if instead of

	git bug status open 0123acd

we should use

	git bug status --open 0123acd

or if there's some other way to avoid ambiguity.

If that doesn't work out, fish has a -k/--keep-order flag, so subcommand
completions can be listed before bug IDs, but that's neither portable nor
a pretty solution.

Part of git-bug#493
krobelus added a commit to krobelus/git-bug that referenced this issue Jan 24, 2021
This completes bug IDs in bash and fish.  I haven't gotten this to work in zsh.
In fish, the bug titles are shown as completion label, and can be searched for.
I don't know if/how other shells can show the completion label.
Anyway, everything after the "\t" separator seems to be ignored.

Part of git-bug#493
krobelus added a commit to krobelus/git-bug that referenced this issue Jan 25, 2021
Complete bug IDs, bridges, users, labels where appropriate.

This works in bash and fish. ZSH is not yet supported by Cobra.
In fish, descriptions (the part of a completion after the "\t") are shown
as completion label, and can be searched.

Closes git-bug#493
krobelus added a commit to krobelus/git-bug that referenced this issue Feb 10, 2021
Complete bug IDs, bridges, users, labels where appropriate.

This works in bash and fish. ZSH is not yet supported by Cobra.
In fish, descriptions (the part of a completion after the "\t") are shown
as completion label, and can be searched.

Closes git-bug#493
@TheNerdyHamster
Copy link

What is the status on this issue?
I would be interested to continue on it, if its not completed

krobelus added a commit to krobelus/git-bug that referenced this issue Aug 1, 2021
Complete bug IDs, bridges, users, labels where appropriate.

This works in bash and fish. ZSH is not yet supported by Cobra.
In fish, descriptions (the part of a completion after the "\t") are shown
as completion label, and can be searched.

Closes git-bug#493
krobelus added a commit to krobelus/git-bug that referenced this issue Mar 2, 2022
Complete bug IDs, bridges, users, labels where appropriate.

This works in bash and fish. ZSH is not yet supported by Cobra.
In fish, descriptions (the part of a completion after the "\t") are shown
as completion label, and can be searched with Ctrl+S.

Reproduce with

	fish -C 'source misc/fish_completion/git-bug'
	git bug select ^I

(tested with fish version 3.3.1)

Also works with bash, but only for "git-bug" (with the dash)

	bash --rcfile <(echo source misc/bash_completion/git-bug)
	git-bug select ^I

Closes git-bug#493
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/cli Relates to the CLI enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants