mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-11-23 21:54:45 +02:00
- Stop using `-n __fish_use_subcommand`. This had the effect of
ignoring options if a positional argument has already been given, but
that's not how ripgrep works.
- Only suggest negation options if the option they're negating is
passed (e.g., only complete `--no-pcre2` if `--pcre2` is present). The
zsh completions already do this.
- Take into account whether an option takes an argument. If an option
is not a switch then it won't suggest further options until the
argument is given, e.g. `-C<tab>` won't suggest options but `-i<tab>`
will.
- Suggest correct arguments for options. We already completed a fixed
set of choices where available, but now we go further:
- Filenames are only suggested for options that take filenames.
- `--pre` and `--hostname-bin` suggest binaries from `$PATH`.
- `-t`/`--type`/&c use `--type-list` for suggestions, like in zsh,
with a preview of the glob patterns.
- `--encoding` uses a hardcoded list extracted from the zsh
completions. This has been refactored into a separate file, and the
range globs (`{1..5}`) replaced by comma globs (`{1,2,3,4,5}`) since
those work in both shells. I verified that this produces the same
list as before in zsh, and the same list in fish (albeit in a
different order).
PR #2684
24 lines
922 B
Rust
24 lines
922 B
Rust
/*!
|
|
Provides completions for ripgrep's CLI for the zsh shell.
|
|
|
|
Unlike completion short for other shells (at time of writing), zsh's
|
|
completions for ripgrep are maintained by hand. This is because:
|
|
|
|
1. They are lovingly written by an expert in such things.
|
|
2. Are much higher in quality than the ones below that are auto-generated.
|
|
Namely, the zsh completions take application level context about flag
|
|
compatibility into account.
|
|
3. There is a CI script that fails if a new flag is added to ripgrep that
|
|
isn't included in the zsh completions.
|
|
4. There is a wealth of documentation in the zsh script explaining how it
|
|
works and how it can be extended.
|
|
|
|
In principle, I'd be open to maintaining any completion script by hand so
|
|
long as it meets criteria 3 and 4 above.
|
|
*/
|
|
|
|
/// Generate completions for zsh.
|
|
pub(crate) fn generate() -> String {
|
|
include_str!("rg.zsh").replace("!ENCODINGS!", super::ENCODINGS.trim_end())
|
|
}
|