From 83cb78fbb27dd969d20daace826de9c78216067d Mon Sep 17 00:00:00 2001 From: Patrick Fong Date: Wed, 24 Mar 2021 22:27:39 -0700 Subject: [PATCH] [Search directory] fix tilde in current token not expanding I also realized that the test meant to catch this exact issue was giving false positives because the tilde would automatically expand when echoed, so I fixed it by escaping the tilde. Relates to https://github.com/PatrickF1/fzf.fish/pull/133#discussion_r601049072. --- functions/__fzf_search_current_dir.fish | 2 +- tests/search_current_dir/expands_~_base_dir.fish | 3 ++- tests/search_current_dir/no_base_dir_if_no_slash.fish | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/functions/__fzf_search_current_dir.fish b/functions/__fzf_search_current_dir.fish index 38432a7d..50c05f3e 100644 --- a/functions/__fzf_search_current_dir.fish +++ b/functions/__fzf_search_current_dir.fish @@ -7,7 +7,7 @@ function __fzf_search_current_dir --description "Search the current directory. R set fzf_arguments --multi --ansi $fzf_dir_opts set token (commandline --current-token) # expand any variables or leading tilde (~) in the token - set expanded_token (eval echo -- \"$token\") + set expanded_token (eval echo -- $token) # unescape token because it's already quoted so backslashes will mess up the path set unescaped_exp_token (string unescape -- $expanded_token) diff --git a/tests/search_current_dir/expands_~_base_dir.fish b/tests/search_current_dir/expands_~_base_dir.fish index 48f60a09..61f63905 100644 --- a/tests/search_current_dir/expands_~_base_dir.fish +++ b/tests/search_current_dir/expands_~_base_dir.fish @@ -3,7 +3,8 @@ function fd set fd_captured_opts $argv end mock fzf \* "" -mock commandline --current-token "echo ~/" +# escape tilde so it doesn't get expanded when echoed +mock commandline --current-token "echo \~/" mock commandline "--current-token --replace" "" mock commandline \* "" __fzf_search_current_dir diff --git a/tests/search_current_dir/no_base_dir_if_no_slash.fish b/tests/search_current_dir/no_base_dir_if_no_slash.fish index 709ae11a..4142402d 100644 --- a/tests/search_current_dir/no_base_dir_if_no_slash.fish +++ b/tests/search_current_dir/no_base_dir_if_no_slash.fish @@ -1,6 +1,7 @@ # though the conf.d directory exists, it should not be used as a base directory # because there is no / at the end of the token mock commandline --current-token "echo conf.d" +mock commandline "--current-token --replace" "" mock commandline \* "" set --export searched_functions_dir false