Skip to content

Commit

Permalink
[Search directory] expand variables in current token (#133)
Browse files Browse the repository at this point in the history
Evolved from #109. Now not only does tilde (~) in the current token get expanded, variables do as well. This is useful for quickly accessing known directory variables, e.g. $XDG_CONFIG_HOME, $TMPDIR, $JAVA_HOME, $fisher_path, $__fish_user_data_dir.
  • Loading branch information
kidonng authored Mar 23, 2021
1 parent b8a99b2 commit 2c0fb53
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
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\")
# 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

0 comments on commit 2c0fb53

Please sign in to comment.