From 160e8620c0dfeea7b84dc7d3b836c6fc248b6e2a Mon Sep 17 00:00:00 2001 From: Patrick Fong Date: Sat, 6 Feb 2021 12:51:10 -0800 Subject: [PATCH] save progress --- functions/__fzf_preview_file.fish | 2 +- functions/__fzf_search_current_dir.fish | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/functions/__fzf_preview_file.fish b/functions/__fzf_preview_file.fish index 8f7247ea..275cb0b3 100644 --- a/functions/__fzf_preview_file.fish +++ b/functions/__fzf_preview_file.fish @@ -23,6 +23,6 @@ function __fzf_preview_file --argument-names file_path --description "Print a pr else if test -p "$file_path" __fzf_report_file_type "$file_path" "named pipe" else - echo "File doesn't exist." >&2 + echo "File doesn't exist or is empty." >&2 end end diff --git a/functions/__fzf_search_current_dir.fish b/functions/__fzf_search_current_dir.fish index 38f0306e..467c21d5 100644 --- a/functions/__fzf_search_current_dir.fish +++ b/functions/__fzf_search_current_dir.fish @@ -5,7 +5,8 @@ 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 current_token (commandline --current-token) + set token (string unescape $current_token) # need to expand ~ in the directory name since fd can't expand it set expanded_token (string replace --regex -- "^~/" $HOME/ $token) @@ -23,14 +24,16 @@ function __fzf_search_current_dir --description "Search the current directory. R if test $status -eq 0 - # If the user was in the middle of inputting the first token and only one path is selected, - # then prepend ./ to the selected path so that - # - if the path is an executable, the user can hit Enter one more time to immediately execute it - # - if the path is a directory, the user can hit Enter one more time to immediately cd into it (fish will - # attempt to cd implicitly if a directory name starts with a dot) - if test (count $file_paths_selected) = 1 + # Fish will implicitly take action on a path when a path is provided as the first token and it + # begins with a dot, slash, or tilde. If the path is a directory, Fish will cd into it. + # If the path is an executable, Fish will execute it. To help users harness + # this convenient behavior, we automatically prepend ./ to the selected path if + # - only one path was selected, + # - the user was in the middle of inputting the first token, + # - and the path doesn't already begin with a dot, slash, or tilde + # Then, the user only needs to hit Enter once more to potentially cd into or execute that path. + if test (count $file_paths_selected) = 1 && not string match --regex "^[.|/|~]" $file_paths_selected set commandline_tokens (commandline --tokenize) - set current_token (commandline --current-token) if test "$commandline_tokens" = "$current_token" set file_paths_selected ./$file_paths_selected end