summaryrefslogtreecommitdiff
path: root/ADVANCED.md
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2025-01-27 15:40:21 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2025-01-27 18:04:57 +0900
commita2aa1a156c29658b62a691f8aa343985043b8c9c (patch)
tree291473b3e429657d064227b9ee5af991e12102fa /ADVANCED.md
parent2f8a72a42a7503276a99cc0234f98f8c56169320 (diff)
downloadfzf-a2aa1a156c29658b62a691f8aa343985043b8c9c.tar.gz
Allow {q} placeholders with range expressions
e.g. {q:1}, {q:2..}
Diffstat (limited to 'ADVANCED.md')
-rw-r--r--ADVANCED.md21
1 files changed, 9 insertions, 12 deletions
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