Skip to content
Myr

[fish] Improve option prefix processing

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

- Support single-letter options without = such as -fFILEPATH - fish v3.3.0 and newer: Disable option prefix if -- is preceded

authored by bitraid · committed by Junegunn Choi · parent a41be61 · Browse files · 1 file+11 added−5 removed
This commit

State

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

Diff stats

1 file+11 added−5 removed

  • other:+11 added−5 removed

1 file+11 added−5 removed

modified:shell/key-bindings.fish+11 added-5 removed
49 unmodified lines
50 # a method compatible with all supported fish versions.51 set -l -- fish_major (string match -r -- '^\d+' $version)52 set -l -- fish_minor (string match -r -- '^\d+\.(\d+)' $version)[2]5354 # fish v3.3.0 and newer: Don't use option prefix if " -- " is preceded.55 set -l -- match_regex '(?<fzf_query>[\s\S]*?(?=\n?$)$)'56 set -l -- prefix_regex '^-[^\s=]+=|^-(?!-)\S'57 if test "$fish_major" -eq 3 -a "$fish_minor" -lt 358 or string match -q -v -- '* -- *' (string sub -l (commandline -Cp) -- (commandline -p))59 set -- match_regex "(?<prefix>$prefix_regex)?$match_regex"60 end6162 # Set $prefix and expanded $fzf_query with preserved trailing newlines.63 if test "$fish_major" -ge 464 # fish v4.0.0 and newer57 string match -q -r -- '(?<prefix>^-[^\s=]+=)?(?<fzf_query>[\s\S]*?(?=\n?$)$)' \58 (commandline --current-token --tokens-expanded | string collect -N)65 string match -q -r -- $match_regex (commandline --current-token --tokens-expanded | string collect -N)66 else if test "$fish_major" -eq 3 -a "$fish_minor" -ge 267 # fish v3.2.0 - v3.7.1 (last v3)61 string match -q -r -- '(?<prefix>^-[^\s=]+=)?(?<fzf_query>[\s\S]*?(?=\n?$)$)' \62 (commandline --current-token --tokenize | string collect -N)68 string match -q -r -- $match_regex (commandline --current-token --tokenize | string collect -N)69 eval set -- fzf_query (string escape -n -- $fzf_query | string replace -r -a '^\\\(?=~)|\\\(?=\$\w)' '')70 else71 # fish older than v3.2.0 (v3.1b1 - v3.1.2)72 set -l -- cl_token (commandline --current-token --tokenize | string collect -N)67 set -- prefix (string match -r -- '^-[^\s=]+=' $cl_token)73 set -- prefix (string match -r -- $prefix_regex $cl_token)74 set -- fzf_query (string replace -- "$prefix" '' $cl_token | string collect -N)75 eval set -- fzf_query (string escape -n -- $fzf_query | string replace -r -a '^\\\(?=~)|\\\(?=\$\w)|\\\n\\\n$' '')76 end77
141 unmodified lines