From 10bfac15d7cf8d79092af31122ca2f22eac82cec Mon Sep 17 00:00:00 2001 From: Kid Date: Sat, 30 Jan 2021 16:08:59 +0800 Subject: [PATCH] Expand tilde while searching files --- functions/__fzf_search_current_dir.fish | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/functions/__fzf_search_current_dir.fish b/functions/__fzf_search_current_dir.fish index ae323e82..5612ba59 100644 --- a/functions/__fzf_search_current_dir.fish +++ b/functions/__fzf_search_current_dir.fish @@ -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) # 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)