From 519c1bd5cfd569bed29f1b3114a872329883983a Mon Sep 17 00:00:00 2001 From: Ilya Grigoriev Date: Sun, 6 Jul 2025 16:05:15 -0700 Subject: [PATCH] complete: improvements for the `--hyperlink-format` flag The goal is to make the completion for `rg --hyperlink-format v` work in the fish shell. These are not exhaustive (the user can also specify custom formats). This is somewhat unfortunate, but is probably better than not doing anything at all. The `grep+` value necessitated a change to a test. Closes #3096 --- CHANGELOG.md | 2 ++ crates/core/flags/defs.rs | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ed953ac..65ed698b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,8 @@ Feature enhancements: Add `highlight` color type, for styling non-matching text in a matching line. * [FEATURE #3048](https://github.com/BurntSushi/ripgrep/pull/3048): Globs in ripgrep (and the `globset` crate) now support nested alternates. +* [FEATURE #3096](https://github.com/BurntSushi/ripgrep/pull/3096): + Improve completions for `--hyperlink-format` in bash and fish. 14.1.1 (2024-09-08) diff --git a/crates/core/flags/defs.rs b/crates/core/flags/defs.rs index 7b9af14f..30f5cdc8 100644 --- a/crates/core/flags/defs.rs +++ b/crates/core/flags/defs.rs @@ -3008,6 +3008,19 @@ https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda &DOC } + fn doc_choices(&self) -> &'static [&'static str] { + static CHOICES: LazyLock> = LazyLock::new(|| { + let mut aliases = grep::printer::hyperlink_aliases(); + aliases.sort_by_key(|alias| { + alias.display_priority().unwrap_or(i16::MAX) + }); + aliases.iter().map(|alias| alias.name().to_string()).collect() + }); + static BORROWED: LazyLock> = + LazyLock::new(|| CHOICES.iter().map(|name| &**name).collect()); + &*BORROWED + } + fn update(&self, v: FlagValue, args: &mut LowArgs) -> anyhow::Result<()> { let v = v.unwrap_value(); let string = convert::str(&v)?; @@ -7724,9 +7737,10 @@ mod tests { assert!( choice.chars().all(|c| c.is_ascii_alphanumeric() || c == '-' - || c == ':'), + || c == ':' + || c == '+'), "choice '{choice}' for flag '{long}' does not match \ - ^[-:0-9A-Za-z]+$", + ^[-+:0-9A-Za-z]+$", ) } }