Skip to content

Commit

Permalink
[Search directory] fix tilde in current token not expanding
Browse files Browse the repository at this point in the history
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 #133 (comment).
  • Loading branch information
PatrickF1 committed Mar 25, 2021
1 parent 3a46f14 commit 83cb78f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion functions/__fzf_search_current_dir.fish
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 2 additions & 1 deletion tests/search_current_dir/expands_~_base_dir.fish
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/search_current_dir/no_base_dir_if_no_slash.fish
Original file line number Diff line number Diff line change
@@ -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" ""

This comment has been minimized.

Copy link
@PatrickF1

PatrickF1 Mar 25, 2021

Author Owner

This change is out of scope: merely meant to prevent echo conf.d from polluting the output of the tests.

mock commandline \* ""

set --export searched_functions_dir false
Expand Down

0 comments on commit 83cb78f

Please sign in to comment.