Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Search directory] expand variables in current token #133

Merged
merged 23 commits into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions functions/__fzf_search_current_dir.fish
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ function __fzf_search_current_dir --description "Search the current directory. R
set fd_opts --color=always $fzf_fd_opts
set fzf_arguments --multi --ansi $fzf_dir_opts
set token (commandline --current-token)
# expand ~ in the directory name since fd can't expand it
set expanded_token (string replace --regex -- "^~/" $HOME/ $token)
# expand the token (which may include tilde, variables, etc.) into full path
set expanded_token (eval echo -- \"$token\")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's an example where removing the quotes would break this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just quoting it like in __fzf_preview_file.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just can't think of when token when ever be separated by an unescaped space. Whatever, I suppose it's safer this way.

Copy link
Contributor Author

@kidonng kidonng Mar 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

users should know better than to quote ~

You are totally right... I was too careful to do it right.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh shoot, this is actually a bug. Quoting it broke this for tilde. Just tested.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 83cb78f

# unescape token because it's already quoted so backslashes will mess up the path
set unescaped_exp_token (string unescape -- $expanded_token)

Expand Down
9 changes: 9 additions & 0 deletions tests/search_current_dir/expands_vars.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
set target "file 1.txt"

set --global fzf_dir_opts --select-1
mock commandline --current-token "echo \$target"
mock commandline "--current-token --replace --" "echo \$argv"
mock commandline \* ""

set actual (__fzf_search_current_dir)
@test "expands variables in current token" (basename "$actual") = "file 1.txt"