complete/zsh: improve --hyperlink-format completion

Also don't re-define helper functions if they exist.

Closes #3102
This commit is contained in:
dana
2025-07-13 01:50:38 -05:00
committed by Andrew Gallant
parent 519c1bd5cf
commit 78383de9b2
5 changed files with 121 additions and 16 deletions

View File

@@ -19,5 +19,14 @@ 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())
let hyperlink_alias_descriptions = grep::printer::hyperlink_aliases()
.iter()
.map(|alias| {
format!(r#" {}:"{}""#, alias.name(), alias.description())
})
.collect::<Vec<String>>()
.join("\n");
include_str!("rg.zsh")
.replace("!ENCODINGS!", super::ENCODINGS.trim_end())
.replace("!HYPERLINK_ALIASES!", &hyperlink_alias_descriptions)
}