Skip to content

Commit 19fe205

Browse files
committed
[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
1 parent 84aff1b commit 19fe205

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

shell/key-bindings.fish

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,26 @@ function fzf_key_bindings
5151
set -l -- fish_major (string match -r -- '^\d+' $version)
5252
set -l -- fish_minor (string match -r -- '^\d+\.(\d+)' $version)[2]
5353

54+
# 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 3
58+
or string match -q -v -- '* -- *' (string sub -l (commandline -Cp) -- (commandline -p))
59+
set -- match_regex "(?<prefix>$prefix_regex)?$match_regex"
60+
end
61+
5462
# Set $prefix and expanded $fzf_query with preserved trailing newlines.
5563
if test "$fish_major" -ge 4
5664
# fish v4.0.0 and newer
57-
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)
5966
else if test "$fish_major" -eq 3 -a "$fish_minor" -ge 2
6067
# 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)
6369
eval set -- fzf_query (string escape -n -- $fzf_query | string replace -r -a '^\\\(?=~)|\\\(?=\$\w)' '')
6470
else
6571
# fish older than v3.2.0 (v3.1b1 - v3.1.2)
6672
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)
6874
set -- fzf_query (string replace -- "$prefix" '' $cl_token | string collect -N)
6975
eval set -- fzf_query (string escape -n -- $fzf_query | string replace -r -a '^\\\(?=~)|\\\(?=\$\w)|\\\n\\\n$' '')
7076
end

0 commit comments

Comments
 (0)