From a2aa1a156c29658b62a691f8aa343985043b8c9c Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Mon, 27 Jan 2025 15:40:21 +0900 Subject: Allow {q} placeholders with range expressions e.g. {q:1}, {q:2..} --- ADVANCED.md | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'ADVANCED.md') diff --git a/ADVANCED.md b/ADVANCED.md index a045140c..71ee15ae 100644 --- a/ADVANCED.md +++ b/ADVANCED.md @@ -517,18 +517,15 @@ remainder of the query is passed to fzf for secondary filtering. INITIAL_QUERY="${*:-}" TRANSFORMER=' - words=($FZF_QUERY) - - # If $FZF_QUERY contains multiple words, drop the first word, - # and trigger fzf search with the rest - if [[ ${#words[@]} -gt 1 ]]; then - echo "search:${FZF_QUERY#* }" - - # Otherwise, if the query does not end with a space, - # restart ripgrep and reload the list - elif ! [[ $FZF_QUERY =~ \ $ ]]; then - pat=${words[0]} - echo "reload:sleep 0.1; rg --column --line-number --no-heading --color=always --smart-case \"$pat\" || true" + rg_pat={q:1} # The first word is passed to ripgrep + fzf_pat={q:2..} # The rest are passed to fzf + rg_pat_org={q:s1} # The first word with trailing whitespaces preserved. + # We use this to avoid unnecessary reloading of ripgrep. + + if [[ -n $fzf_pat ]]; then + echo "search:$fzf_pat" + elif ! [[ $rg_pat_org =~ \ $ ]]; then + printf "reload:sleep 0.1; rg --column --line-number --no-heading --color=always --smart-case %q || true" "$rg_pat" else echo search: fi -- cgit v1.2.3