@@ -51,20 +51,26 @@ function fzf_key_bindings
51
51
set -l -- fish_major (string match -r -- ' ^\ d+' $version )
52
52
set -l -- fish_minor (string match -r -- ' ^\ d+\ .(\ d+)' $version )[2]
53
53
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
+
54
62
# Set $prefix and expanded $fzf_query with preserved trailing newlines.
55
63
if test " $fish_major " -ge 4
56
64
# 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 )
59
66
else if test " $fish_major " -eq 3 -a " $fish_minor " -ge 2
60
67
# 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 )
63
69
eval set -- fzf_query (string escape -n -- $fzf_query | string replace -r -a ' ^\\\ (?=~)|\\\ (?=\ $\ w)' ' ' )
64
70
else
65
71
# fish older than v3.2.0 (v3.1b1 - v3.1.2)
66
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 )
68
74
set -- fzf_query (string replace -- " $prefix " ' ' $cl_token | string collect -N )
69
75
eval set -- fzf_query (string escape -n -- $fzf_query | string replace -r -a ' ^\\\ (?=~)|\\\ (?=\ $\ w)|\\\ n\\\ n$' ' ' )
70
76
end
0 commit comments