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

[Feature] Add option to print Bash completion script #558

Open
hdwalters opened this issue Oct 31, 2024 · 3 comments
Open

[Feature] Add option to print Bash completion script #558

hdwalters opened this issue Oct 31, 2024 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@hdwalters
Copy link
Contributor

Is your feature request related to a problem? Please describe.
A lot of Bash CLI tools provide a command line option to output a completion script. For example, ripgrep provides an option:

$ rg --generate=complete-bash | head -5
_rg() {
  local i cur prev opts cmds
  COMPREPLY=()
  cur="${COMP_WORDS[COMP_CWORD]}"
  prev="${COMP_WORDS[COMP_CWORD-1]}"

This can be called in a .bashrc file, to enable command line completion:

source <(rg --generate=complete-bash)

It would be nice if Amber supported this.

Describe the solution you'd like
Since we already use the clap library, we can use the complementary clap_complete library to do this.

Describe alternatives you've considered
N/A

Additional context
See https://docs.rs/clap_complete/latest/clap_complete/ for more details.

@hdwalters hdwalters added the enhancement New feature or request label Oct 31, 2024
@github-project-automation github-project-automation bot moved this to 🆕 New in Amber Project Oct 31, 2024
@b1ek
Copy link
Member

b1ek commented Nov 1, 2024

what kind of completition scripts are you talking about? im pretty sure that @KrosFire is working on an LSP server, so they might not be necessary

@hdwalters
Copy link
Contributor Author

hdwalters commented Nov 1, 2024

No, I'm talking about tab completion on the command line, not keyword completion in an IDE. Suppose I want to type git commit. If I type this:

$ git co<Tab><Tab>

I get this, where | represents the cursor:

$ git co
co       commit   config   
$ git co|

If I then type this:

$ git com<Tab>

I get this:

$ git commit |

Whenever the user presses the Tab key, Bash parses the command line so far, and calls the relevant completion script. It then offers completion options according to the output of that script. The clap library has a feature where you can generate completion scripts automatically.

@hdwalters hdwalters self-assigned this Nov 1, 2024
@hdwalters
Copy link
Contributor Author

I've assigned this and #411 to myself; might as well do both at the same time.

@hdwalters hdwalters changed the title [Feature] Add command line option to print Bash completion script [Feature] Add option to print Bash completion script Nov 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants