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

Complete default recognized type names in Bash #1549

Open
commonquail opened this issue Apr 11, 2020 · 2 comments
Open

Complete default recognized type names in Bash #1549

commonquail opened this issue Apr 11, 2020 · 2 comments
Labels
enhancement An enhancement to the functionality of the software.

Comments

@commonquail
Copy link

commonquail commented Apr 11, 2020

What version of ripgrep are you using?

ripgrep 12.0.1 (rev 1143888259)
+SIMD -AVX (compiled)
+SIMD +AVX (runtime)

How did you install ripgrep?

Compile from source.

What operating system are you using ripgrep on?

Ubuntu 19.10

Describe your question, feature request, or bug.

I would like to be able to complete default recognized type names in Bash.

I compile ripgrep from source; mostly as a historical curiosity. Because I already compile from source I patch ripgrep's generated Bash completion to support type names: commonquail/ripgrep@1ce1701:

$ rg -t j
java     jinja    jl       js       json     jsonl    julia    jupyter

That has been fairly useful to me, if technically not quite worth it.

Since the completion file is generated, it's not really feasible to propose that version for upstreaming. Fortunately, clap has built-in support for enumerating valid values and it's already being used a few places in ripgrep. Unfortunately, the type names seem very difficult to access at that point in time:
commonquail/ripgrep@36447f5:

I appreciate that the generated completion scripts are at best a secondary concern, included purely "because we can", so I understand not wanting to spend any time on this.

See also

@BurntSushi BurntSushi added the enhancement An enhancement to the functionality of the software. label Nov 21, 2023
@BurntSushi
Copy link
Owner

I don't have any plans of working on this, but once #2626 is merged, ripgrep will own the generation process for bash shell completions. Previously, it asked a dependency (the Clap crate) to do it. This should make it much easier to augment the generation code to include all of the file types.

With that said, the ideal here would be for the completion script to use rg --type-list to determine the complete list of types. Since they can be added to (or removed) by the end user.

@commonquail
Copy link
Author

For Bash

impl Flag for Type {
    fn doc_choices(&self) -> &'static [&'static str] {
        &["$(rg --type-list | cut -d: -f1)"]
    }
}

is functionally equivalent to the modification I made. Nakedly shelling out this way would not work for Fish and PowerShell, of course, so some means of signalling dynamic generation would be necessary -- a richer return type or a new function definition, essentially.

--type-list could be taught a flag to omit the prefix and obviate cut, or an alternative argument (hidden?) could do the same to leave --type-list alone. This could allow an alternative design more specialized than arbitrarily shelling out, which may or may not be preferable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement to the functionality of the software.
Projects
None yet
Development

No branches or pull requests

2 participants