Skip to content

Commit 282884a

Browse files
authored
[fish] Unescape query from commandline (junegunn#4236)
More natural processing of the query taken from command line, by unquoting/unescaping the token. Unescaped open quotes are removed. Because of how `string unescape` works, if both single and double quotes are present, with the outer quotes open, only the outer quotes are removed. Examples: `'foo bar'`, `"foo bar"`, `foo\ bar` becomes `foo bar` `"foobar`, `'foobar`, `foo"bar`, `foo'bar` becomes `foobar` `'"foo"'`, `'"foo"` becomes `"foo"` `"'foo'"`, `"'foo'` becomes `'foo'` `"'foo` becomes `'foo` `'"foo` becomes `"foo`
1 parent 7877ac4 commit 282884a

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

shell/key-bindings.fish

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ function fzf_key_bindings
154154
# eval is used to do shell expansion on paths
155155
eval set commandline $commandline
156156

157-
# Combine multiple consecutive slashes into one
158-
set commandline (string replace -r -a -- '/+' '/' $commandline)
157+
# Combine multiple consecutive slashes into one, and unescape.
158+
set commandline (string replace -r -a -- '/+' '/' $commandline | string unescape -n)
159159

160160
if test -z "$commandline"
161161
# Default to current directory with no --query
@@ -171,10 +171,8 @@ function fzf_key_bindings
171171
# if $dir is "." but commandline is not a relative path, this means no file path found
172172
set fzf_query $commandline
173173
else
174-
# Special characters must be double escaped.
175-
set -l re_dir (string escape -n -- $dir)
176174
# Also remove trailing slash after dir, to "split" input properly
177-
set fzf_query (string replace -r -- "^$re_dir/?" '' $commandline)
175+
set fzf_query (string replace -r -- "^$dir/?" '' $commandline)
178176
end
179177
end
180178

@@ -184,7 +182,7 @@ function fzf_key_bindings
184182
end
185183

186184
function __fzf_get_dir -d 'Find the longest existing filepath from input string'
187-
set dir (string unescape -n -- $argv)
185+
set dir $argv
188186

189187
# Strip trailing slash, unless $dir is root dir (/)
190188
set dir (string replace -r -- '(?<!^)/$' '' $dir)

0 commit comments

Comments
 (0)