summaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorbitraid <bitraid@protonmail.ch>2025-02-11 16:19:40 +0200
committerGitHub <noreply@github.com>2025-02-11 23:19:40 +0900
commit282884ad83c9aae32519d9bb3b7d685319c26639 (patch)
tree06c062152de196b63dc41f34c04c1eccc223cae5 /shell
parent7877ac42f034bc6ef1ad7fa2cfeae367aa0762fb (diff)
downloadfzf-282884ad83c9aae32519d9bb3b7d685319c26639.tar.gz
[fish] Unescape query from commandline (#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`
Diffstat (limited to 'shell')
-rw-r--r--shell/key-bindings.fish10
1 files changed, 4 insertions, 6 deletions
diff --git a/shell/key-bindings.fish b/shell/key-bindings.fish
index 9d173d48..8e316518 100644
--- a/shell/key-bindings.fish
+++ b/shell/key-bindings.fish
@@ -154,8 +154,8 @@ function fzf_key_bindings
# eval is used to do shell expansion on paths
eval set commandline $commandline
- # Combine multiple consecutive slashes into one
- set commandline (string replace -r -a -- '/+' '/' $commandline)
+ # Combine multiple consecutive slashes into one, and unescape.
+ set commandline (string replace -r -a -- '/+' '/' $commandline | string unescape -n)
if test -z "$commandline"
# Default to current directory with no --query
@@ -171,10 +171,8 @@ function fzf_key_bindings
# if $dir is "." but commandline is not a relative path, this means no file path found
set fzf_query $commandline
else
- # Special characters must be double escaped.
- set -l re_dir (string escape -n -- $dir)
# Also remove trailing slash after dir, to "split" input properly
- set fzf_query (string replace -r -- "^$re_dir/?" '' $commandline)
+ set fzf_query (string replace -r -- "^$dir/?" '' $commandline)
end
end
@@ -184,7 +182,7 @@ function fzf_key_bindings
end
function __fzf_get_dir -d 'Find the longest existing filepath from input string'
- set dir (string unescape -n -- $argv)
+ set dir $argv
# Strip trailing slash, unless $dir is root dir (/)
set dir (string replace -r -- '(?<!^)/$' '' $dir)