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 all 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
2 changes: 2 additions & 0 deletions .github/workflows/continuous_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ jobs:
- name: Run full test suite
run: fishtape tests/*/*.fish
shell: fish {0}
# timeout in case tests get stuck on fzf
timeout-minutes: 3

syntax-check:
runs-on: ubuntu-latest
Expand Down
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
10 changes: 10 additions & 0 deletions tests/search_current_dir/expands_var_in_query.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
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 \* ""
# string unescape because the args passed into commandline --current-token --replace are escaped
set actual (string unescape (__fzf_search_current_dir))

@test "expands variables in current token" (basename $actual) = $target