@@ -51,20 +51,30 @@ 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
+ set -l -- match_regex ' (?<fzf_query>[\ s\ S]*?(?=\ n?$)$)'
55
+ set -l -- prefix_regex ' ^-[^\ s=]+=|^-[^\ s]'
56
+
57
+ # fish v3.3.0 and newer: Don't use option prefix if " -- " is preceded.
58
+ if test \ ( " $fish_major " -ge 4 \ ) -o \ ( " $fish_major " -eq 3 -a " $fish_minor " -ge 3 \ )
59
+ if string match -q -v -- ' * -- *' (string sub -l (commandline -Cp ) -- (commandline -p ))
60
+ set -- match_regex " (?<prefix>$prefix_regex )?$match_regex "
61
+ end
62
+ else
63
+ set -- match_regex " (?<prefix>$prefix_regex )?$match_regex "
64
+ end
65
+
54
66
# Set $prefix and expanded $fzf_query with preserved trailing newlines.
55
67
if test " $fish_major " -ge 4
56
68
# 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 )
69
+ string match -q -r -- $match_regex (commandline --current-token --tokens-expanded | string collect -N )
59
70
else if test " $fish_major " -eq 3 -a " $fish_minor " -ge 2
60
71
# 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 )
72
+ string match -q -r -- $match_regex (commandline --current-token --tokenize | string collect -N )
63
73
eval set -- fzf_query (string escape -n -- $fzf_query | string replace -r -a ' ^\\\ (?=~)|\\\ (?=\ $\ w)' ' ' )
64
74
else
65
75
# fish older than v3.2.0 (v3.1b1 - v3.1.2)
66
76
set -l -- cl_token (commandline --current-token --tokenize | string collect -N )
67
- set -- prefix (string match -r -- ' ^-[^ \ s=]+= ' $cl_token )
77
+ set -- prefix (string match -r -- $prefix_regex $cl_token )
68
78
set -- fzf_query (string replace -- " $prefix " ' ' $cl_token | string collect -N )
69
79
eval set -- fzf_query (string escape -n -- $fzf_query | string replace -r -a ' ^\\\ (?=~)|\\\ (?=\ $\ w)|\\\ n\\\ n$' ' ' )
70
80
end
0 commit comments