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 bash completions #13

Open
Gelio opened this issue Apr 2, 2022 · 1 comment
Open

Add bash completions #13

Gelio opened this issue Apr 2, 2022 · 1 comment

Comments

@Gelio
Copy link
Owner

Gelio commented Apr 2, 2022

It would be nice to have bash completions for the supported flags and/or binaries passed as arguments.

Specifically, pressing tab for completions should lead to following output:

$ go-global-update --<tab>
--help -h --debug --dry-run --verbose --version -v
$ go-global-update go<tab>
go-global-update gofumpt gotop
@Gelio
Copy link
Owner Author

Gelio commented Apr 2, 2022

I've done some research and looks like this will be a bit more complex than I originally thought. Things we need to do:

  1. Install (copy) https://github.com/urfave/cli/blob/master/autocomplete/bash_autocomplete as /etc/bash_completion.d/go-global-update

    It would be great to offer a install-bash-autocomplete command/script to make this step easier and not expect users to copy this file manually.

  2. Set EnableBashCompletion to true in main.go, according to https://github.com/urfave/cli/blob/master/docs/v2/manual.md#distribution-and-persistent-autocompletion

  3. For the command arguments (go binary names), we would have to write a custom BashComplete function to get the list of installed binaries

To make sure all of that works, it would be great to add some integration tests that try to invoke the completion with various arguments. This can be done by running go run main.go --generate-bash-completion. We can provide existing arguments there too to simulate various inputs for completion. For example, to get a list of possible flags starting with d:

11:39 $ go run main.go --d --generate-bash-completion
--debug
--dry-run

Other shells

For ZSH, users would need to add a line to their config to enable completion: https://github.com/urfave/cli/blob/master/docs/v2/manual.md#zsh-support

For Powershell, same as for ZSH, they would need to edit the config: https://github.com/urfave/cli/blob/master/docs/v2/manual.md#powershell-support

It looks like they should work along with the custom bash completions

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

1 participant