diff options
| author | bitraid <bitraid@protonmail.ch> | 2025-04-16 10:43:45 +0300 |
|---|---|---|
| committer | Junegunn Choi <junegunn.c@gmail.com> | 2025-04-18 21:06:25 +0900 |
| commit | e491770f1c5f50cc969ff58228cd29a7cfa76663 (patch) | |
| tree | e396c28478fb47f1286fc4437f49ad7bc41d6558 /shell | |
| parent | a41be61506541fd583e56d8b16f5b65af1517a32 (diff) | |
| download | fzf-e491770f1c5f50cc969ff58228cd29a7cfa76663.tar.gz | |
[fish] Improve option prefix processing
- Support single-letter options without = such as -fFILEPATH
- fish v3.3.0 and newer: Disable option prefix if -- is preceded
Diffstat (limited to 'shell')
| -rw-r--r-- | shell/key-bindings.fish | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/shell/key-bindings.fish b/shell/key-bindings.fish index 72b42079..0004c380 100644 --- a/shell/key-bindings.fish +++ b/shell/key-bindings.fish @@ -51,20 +51,26 @@ function fzf_key_bindings set -l -- fish_major (string match -r -- '^\d+' $version) set -l -- fish_minor (string match -r -- '^\d+\.(\d+)' $version)[2] + # fish v3.3.0 and newer: Don't use option prefix if " -- " is preceded. + set -l -- match_regex '(?<fzf_query>[\s\S]*?(?=\n?$)$)' + set -l -- prefix_regex '^-[^\s=]+=|^-(?!-)\S' + if test "$fish_major" -eq 3 -a "$fish_minor" -lt 3 + or string match -q -v -- '* -- *' (string sub -l (commandline -Cp) -- (commandline -p)) + set -- match_regex "(?<prefix>$prefix_regex)?$match_regex" + end + # Set $prefix and expanded $fzf_query with preserved trailing newlines. if test "$fish_major" -ge 4 # fish v4.0.0 and newer - string match -q -r -- '(?<prefix>^-[^\s=]+=)?(?<fzf_query>[\s\S]*?(?=\n?$)$)' \ - (commandline --current-token --tokens-expanded | string collect -N) + string match -q -r -- $match_regex (commandline --current-token --tokens-expanded | string collect -N) else if test "$fish_major" -eq 3 -a "$fish_minor" -ge 2 # fish v3.2.0 - v3.7.1 (last v3) - string match -q -r -- '(?<prefix>^-[^\s=]+=)?(?<fzf_query>[\s\S]*?(?=\n?$)$)' \ - (commandline --current-token --tokenize | string collect -N) + string match -q -r -- $match_regex (commandline --current-token --tokenize | string collect -N) eval set -- fzf_query (string escape -n -- $fzf_query | string replace -r -a '^\\\(?=~)|\\\(?=\$\w)' '') else # fish older than v3.2.0 (v3.1b1 - v3.1.2) set -l -- cl_token (commandline --current-token --tokenize | string collect -N) - set -- prefix (string match -r -- '^-[^\s=]+=' $cl_token) + set -- prefix (string match -r -- $prefix_regex $cl_token) set -- fzf_query (string replace -- "$prefix" '' $cl_token | string collect -N) eval set -- fzf_query (string escape -n -- $fzf_query | string replace -r -a '^\\\(?=~)|\\\(?=\$\w)|\\\n\\\n$' '') end |
