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

Shell completion #10058

Merged
merged 2 commits into from
Mar 2, 2018
Merged

Shell completion #10058

merged 2 commits into from
Mar 2, 2018

Conversation

timfallmk
Copy link
Contributor

A simple WIP PR to enable basic shell completion using urfave/cli's built in shell completion function.

The method has two parts:

  • An "autocomplete" script that, when sourced (source is here), adds the completion to the shell
  • A --generate-<shell>-completion function that outputs the inline subcommands for the above script.

I've enabled the second part (it's just one line), but the first would need to be distributed in some way along with the CLI. Since I don't know your install methods, any insight here would be appreciated.

For an example of how this can be done in practice, see here

If approved, zsh completion can easily be added along with bash.

References:

@timfallmk
Copy link
Contributor Author

bump?

@patrickxb
Copy link
Contributor

@timfallmk thanks for this PR.

Shell completion would be nice. Do you know if there's a way to support subcommands?

I see that (if installed) this would complete keybase t + TAB to keybase team but it doesn't look like it will do keybase team add + TAB to keybase team add-member.

@timfallmk
Copy link
Contributor Author

@patrickxb That's a good point.

The default completion command is pretty limited. It should be pretty trivial to write a completion function that descends through any subcommand trees as well. If that's of interest I'd be happy to look into it.

@timfallmk
Copy link
Contributor Author

timfallmk commented Jan 23, 2018

@patrickxb Actually I might be wrong. It's possible that this works as intended already. I'll double check and report back.

Edit: Confirmed subcommands are also added!

@timfallmk
Copy link
Contributor Author

🆙

@patrickxb
Copy link
Contributor

That's cool.

When I tried it, it only generated completions for the root commands. Can you show me the generated file with the subcommands?

@timfallmk
Copy link
Contributor Author

@patrickxb Source pulled directly from here. Added to ~/.bash_profile via

PROG=keybase source /path/to/bash_autocomplete

keybase autocomplete 2

@timfallmk
Copy link
Contributor Author

timfallmk commented Mar 1, 2018

If this isn't of any interest, I'll close out the PR.

@maxtaco maxtaco merged commit fd2443b into keybase:master Mar 2, 2018
@timfallmk timfallmk deleted the shell-completion branch March 3, 2018 02:05
@espoelstra
Copy link

A slightly easier way to get the completion per the CLI library's directions now that the --generate-bash-completion has been merged is below.

wget https://github.com/urfave/cli/raw/master/autocomplete/bash_autocomplete -O keybase.completion
sudo mv keybase.completion /etc/bash_completion.d/keybase
# '. ~/some-file' and 'source ~/some-file' are equivalent, but 'source' only exists in Bash
. /etc/bash_completion.d/keybase
# or source your .bashrc
# . ~/.bashrc

The reason I prefer to use the /etc/bash_completion.d/ directory rather than /usr/share/bash-completion/ is that /etc is for user configurations, while /usr/share is typically for files provided by packages. Just try ls /etc/bash_completion.d/ and ls /usr/share/bash-completion to see the evidence of this.

@jasonkarns
Copy link

jasonkarns commented Feb 7, 2019

Note for homebrew users of bash-completion2: drop the keybase script in /usr/local/etc/bash_completion.d and it'll automatically be sourced without modification to your bashrc.

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

Successfully merging this pull request may close these issues.

5 participants