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

Expand tilde while searching files #109

Merged
merged 1 commit into from
Jan 30, 2021
Merged
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
5 changes: 3 additions & 2 deletions functions/__fzf_search_current_dir.fish
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ function __fzf_search_current_dir --description "Search the current directory. R
set fd_arguments --hidden --color=always --exclude=.git
set fzf_arguments --multi --ansi
set token (commandline --current-token | string unescape)
set expanded_token (string replace --regex -- "^~/" $HOME/ $token)
Copy link
Contributor Author

@kidonng kidonng Jan 30, 2021

Choose a reason for hiding this comment

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

In fact we can use an unquoted ~ instead of $HOME here, but that would be too confusing 😄

Copy link
Contributor

Choose a reason for hiding this comment

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

I personally find string replace --regex -- "^~/" ~/ $token more aesthetically pleasing, but this works too.


# If the current token is a directory and has a trailing slash,
# then use it as fd's base directory.
if string match --quiet -- "*/" $token && test -d $token
set --append fd_arguments --base-directory=$token
if string match --quiet -- "*/" $token && test -d $expanded_token
set --append fd_arguments --base-directory=$expanded_token
# use the directory name as fzf's prompt to indicate the search is limited to that directory
set --append fzf_arguments --prompt=$token --preview="__fzf_preview_file $token{}"
set file_paths_selected $token(fd $fd_arguments 2>/dev/null | fzf $fzf_arguments)
Expand Down