mirror of
https://github.com/junegunn/fzf.git
synced 2025-07-31 04:02:01 -07:00
[fish] Fix for directories with special characters (#4230)
Using CTRL-T or ALT-C when the current command line token contained a directory with special characters, the script would fail to detect it. For exampe, an existing directory named `it\'s\ a\ test`, instead of using it as walker-root, it would use it as the query.
This commit is contained in:
@@ -171,18 +171,20 @@ function fzf_key_bindings
|
|||||||
# if $dir is "." but commandline is not a relative path, this means no file path found
|
# if $dir is "." but commandline is not a relative path, this means no file path found
|
||||||
set fzf_query $commandline
|
set fzf_query $commandline
|
||||||
else
|
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
|
# Also remove trailing slash after dir, to "split" input properly
|
||||||
set fzf_query (string replace -r -- "^$dir/?" '' $commandline)
|
set fzf_query (string replace -r -- "^$re_dir/?" '' $commandline)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
echo (string escape -- $dir)
|
echo -- $dir
|
||||||
echo (string escape -- $fzf_query)
|
string escape -- $fzf_query
|
||||||
echo $prefix
|
echo -- $prefix
|
||||||
end
|
end
|
||||||
|
|
||||||
function __fzf_get_dir -d 'Find the longest existing filepath from input string'
|
function __fzf_get_dir -d 'Find the longest existing filepath from input string'
|
||||||
set dir $argv
|
set dir (string unescape -n -- $argv)
|
||||||
|
|
||||||
# Strip trailing slash, unless $dir is root dir (/)
|
# Strip trailing slash, unless $dir is root dir (/)
|
||||||
set dir (string replace -r -- '(?<!^)/$' '' $dir)
|
set dir (string replace -r -- '(?<!^)/$' '' $dir)
|
||||||
@@ -194,7 +196,7 @@ function fzf_key_bindings
|
|||||||
set dir (dirname -- "$dir")
|
set dir (dirname -- "$dir")
|
||||||
end
|
end
|
||||||
|
|
||||||
echo $dir
|
string escape -n -- $dir
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user