Skip to content
Myr

complete/zsh: improve --hyperlink-format completion

Before adoption: this commit came in with the history the project adopted, so no landing records it.

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

authored by dana · committed by Andrew Gallant · parent 519c1bd · Browse files · 5 files+121 added−16 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+121 added−16 removed

  • other:+121 added−16 removed

5 files+121 added−16 removed

modified:crates/core/flags/complete/rg.zsh+46 added-1 removed
317 unmodified lines
318 '--debug[show debug messages]'319 '--field-context-separator[set string to delimit fields in context lines]'320 '--field-match-separator[set string to delimit fields in matching lines]'321 '--hostname-bin=[executable for getting system hostname]:hostname executable:_command_names -e'322 '--hyperlink-format=[specify pattern for hyperlinks]:pattern'322 '--hyperlink-format=[specify pattern for hyperlinks]: :_rg_hyperlink_formats'323 '--trace[show more verbose debug messages]'324 '--dfa-size-limit=[specify upper size limit of generated DFA]:DFA size (bytes)'325 "(1 stats)--files[show each file that would be searched (but don't search)]"326 '*--ignore-file=[specify additional ignore file]:ignore file:_files'
82 unmodified lines
409 return ret410}411412# Complete encodings413(( $+functions[_rg_encodings] )) ||414_rg_encodings() {415 local -a expl416 local -aU _encodings417
4 unmodified lines
422 _wanted encodings expl encoding compadd -a "$@" - _encodings423}424425# Complete file types426(( $+functions[_rg_types] )) ||427_rg_types() {428 local -a expl429 local -aU _types430
5 unmodified lines
436 _wanted types expl 'file type' compadd "$@" - ${(@)_types%%:*}437 fi438}439440# Complete hyperlink format-string aliases441(( $+functions[_rg_hyperlink_format_aliases] )) ||442_rg_hyperlink_format_aliases() {443 _describe -t format-aliases 'hyperlink format alias' '(444!HYPERLINK_ALIASES!445 )'446}447448# Complete custom hyperlink format strings449(( $+functions[_rg_hyperlink_format_strings] )) ||450_rg_hyperlink_format_strings() {451 local op='{' ed='}'452 local -a pfx sfx rmv453454 compquote op ed455456 sfx=( -S $ed )457 rmv=( -r ${(q)ed[1]} )458459 compset -S "$op*"460 compset -S "$ed*" && sfx=( -S '' )461 compset -P "*$ed"462 compset -p ${#PREFIX%$op*}463 compset -P $op || pfx=( -P $op )464465 WSL_DISTRO_NAME=${WSL_DISTRO_NAME:-\$WSL_DISTRO_NAME} \466 _describe -t format-variables 'hyperlink format variable' '(467 path:"absolute path to file containing match (required)"468 host:"system host name or output of --hostname-bin executable"469 line:"line number of match"470 column:"column of match (requires {line})"471 wslprefix:"\"wsl$/$WSL_DISTRO_NAME\" (for WSL share)"472 )' "${(@)pfx}" "${(@)sfx}" "${(@)rmv}"473}474475# Complete hyperlink formats476(( $+functions[_rg_hyperlink_formats] )) ||477_rg_hyperlink_formats() {478 _alternative \479 'format-string-aliases: :_rg_hyperlink_format_aliases' \480 'format-strings: :_rg_hyperlink_format_strings'481}482483# Don't run the completion function when being sourced by itself.484#485# See https://github.com/BurntSushi/ripgrep/issues/2956486# See https://github.com/BurntSushi/ripgrep/pull/2957
205 unmodified lines
modified:crates/core/flags/complete/zsh.rs+10 added-1 removed
17 unmodified lines
18*/1920/// Generate completions for zsh.21pub(crate) fn generate() -> String {22 let hyperlink_alias_descriptions = grep::printer::hyperlink_aliases()23 .iter()24 .map(|alias| {25 format!(r#" {}:"{}""#, alias.name(), alias.description())26 })27 .collect::<Vec<String>>()28 .join("\n");29 include_str!("rg.zsh")22 include_str!("rg.zsh").replace("!ENCODINGS!", super::ENCODINGS.trim_end())30 .replace("!ENCODINGS!", super::ENCODINGS.trim_end())31 .replace("!HYPERLINK_ALIASES!", &hyperlink_alias_descriptions)32}
modified:crates/printer/src/hyperlink/aliases.rs+57 added-14 removed
2 unmodified lines
3/// Aliases to well-known hyperlink schemes.4///5/// These need to be sorted by name.6pub(super) const HYPERLINK_PATTERN_ALIASES: &[HyperlinkAlias] = &[7 #[cfg(not(windows))]8 prioritized_alias(0, "default", "file://{host}{path}"),9 #[cfg(windows)]10 prioritized_alias(0, "default", "file://{path}"),11 alias("file", "file://{host}{path}"),7 prioritized_alias(8 0,9 "default",10 "RFC 8089 scheme (file://) (platform-aware)",11 {12 #[cfg(not(windows))]13 {14 "file://{host}{path}"15 }16 #[cfg(windows)]17 {18 "file://{path}"19 }20 },21 ),22 alias(23 "file",24 "RFC 8089 scheme (file://) with host",25 "file://{host}{path}",26 ),27 // https://github.com/misaki-web/grepp13 alias("grep+", "grep+://{path}:{line}"),14 alias("kitty", "file://{host}{path}#{line}"),28 alias("grep+", "grep+ scheme (grep+://)", "grep+://{path}:{line}"),29 alias(30 "kitty",31 "kitty-style RFC 8089 scheme (file://) with line number",32 "file://{host}{path}#{line}",33 ),34 // https://macvim.org/docs/gui_mac.txt.html#mvim%3A%2F%2F35 alias(36 "macvim",37 "MacVim scheme (mvim://)",38 "mvim://open?url=file://{path}&line={line}&column={column}",39 ),20 prioritized_alias(1, "none", ""),40 prioritized_alias(1, "none", "disable hyperlinks", ""),41 // https://macromates.com/blog/2007/the-textmate-url-scheme/42 alias(43 "textmate",44 "TextMate scheme (txmt://)",45 "txmt://open?url=file://{path}&line={line}&column={column}",46 ),47 // https://code.visualstudio.com/docs/editor/command-line#_opening-vs-code-with-urls27 alias("vscode", "vscode://file{path}:{line}:{column}"),28 alias("vscode-insiders", "vscode-insiders://file{path}:{line}:{column}"),29 alias("vscodium", "vscodium://file{path}:{line}:{column}"),48 alias(49 "vscode",50 "VS Code scheme (vscode://)",51 "vscode://file{path}:{line}:{column}",52 ),53 alias(54 "vscode-insiders",55 "VS Code Insiders scheme (vscode-insiders://)",56 "vscode-insiders://file{path}:{line}:{column}",57 ),58 alias(59 "vscodium",60 "VSCodium scheme (vscodium://)",61 "vscodium://file{path}:{line}:{column}",62 ),63];6465/// Creates a [`HyperlinkAlias`].33const fn alias(name: &'static str, format: &'static str) -> HyperlinkAlias {34 HyperlinkAlias { name, format, display_priority: None }66const fn alias(67 name: &'static str,68 description: &'static str,69 format: &'static str,70) -> HyperlinkAlias {71 HyperlinkAlias { name, description, format, display_priority: None }72}7374/// Creates a [`HyperlinkAlias`] with a display priority.75const fn prioritized_alias(76 priority: i16,77 name: &'static str,78 description: &'static str,79 format: &'static str,80) -> HyperlinkAlias {43 HyperlinkAlias { name, format, display_priority: Some(priority) }81 HyperlinkAlias {82 name,83 description,84 format,85 display_priority: Some(priority),86 }87}
modified:crates/printer/src/hyperlink/mod.rs+6 added
188 unmodified lines
189/// Some of their features are usable in const blocks.190#[derive(Clone, Debug)]191pub struct HyperlinkAlias {192 name: &'static str,193 description: &'static str,194 format: &'static str,195 display_priority: Option<i16>,196}197
2 unmodified lines
200 pub const fn name(&self) -> &str {201 self.name202 }203204 /// Returns a very short description of this hyperlink alias.205 pub const fn description(&self) -> &str {206 self.description207 }208209 /// Returns the display priority of this alias.210 ///211 /// If no priority is set, then `None` is returned.212 ///
953 unmodified lines
modified:CHANGELOG.md+2 added
47 unmodified lines
48* [FEATURE #3048](https://github.com/BurntSushi/ripgrep/pull/3048):49 Globs in ripgrep (and the `globset` crate) now support nested alternates.50* [FEATURE #3096](https://github.com/BurntSushi/ripgrep/pull/3096):51 Improve completions for `--hyperlink-format` in bash and fish.52* [FEATURE #3102](https://github.com/BurntSushi/ripgrep/pull/3102):53 Improve completions for `--hyperlink-format` in zsh.54555614.1.1 (2024-09-08)57===================
1709 unmodified lines