summaryrefslogtreecommitdiff
path: root/ADVANCED.md
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2025-01-26 01:50:08 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2025-01-26 01:50:08 +0900
commit7220d8233e81291db8bda3d4eb5286ca45f07be0 (patch)
tree0bbb9c4593e50c0a06408982c0b907c30db8661b /ADVANCED.md
parent0237bf09bf1fe70d94727b040ac39110f56b497f (diff)
downloadfzf-7220d8233e81291db8bda3d4eb5286ca45f07be0.tar.gz
Add 'search' and 'transform-search'
Close #4202
Diffstat (limited to 'ADVANCED.md')
-rw-r--r--ADVANCED.md47
1 files changed, 45 insertions, 2 deletions
diff --git a/ADVANCED.md b/ADVANCED.md
index bafe9708..2636b15f 100644
--- a/ADVANCED.md
+++ b/ADVANCED.md
@@ -1,8 +1,8 @@
Advanced fzf examples
======================
-* *Last update: 2024/06/24*
-* *Requires fzf 0.54.0 or later*
+* *Last update: 2025/01/26*
+* *Requires fzf 0.59.0 or later*
---
@@ -22,6 +22,7 @@ Advanced fzf examples
* [Switching to fzf-only search mode](#switching-to-fzf-only-search-mode)
* [Switching between Ripgrep mode and fzf mode](#switching-between-ripgrep-mode-and-fzf-mode)
* [Switching between Ripgrep mode and fzf mode using a single key binding](#switching-between-ripgrep-mode-and-fzf-mode-using-a-single-key-binding)
+ * [Controlling Ripgrap search and fzf search simultaneously](#controlling-ripgrap-search-and-fzf-search-simultaneously)
* [Log tailing](#log-tailing)
* [Key bindings for git objects](#key-bindings-for-git-objects)
* [Files listed in `git status`](#files-listed-in-git-status)
@@ -500,6 +501,48 @@ fzf --ansi --disabled --query "$INITIAL_QUERY" \
--bind 'enter:become(vim {1} +{2})'
```
+### Controlling Ripgrap search and fzf search simultaneously
+
+fzf 0.59.0 added `search` action that allows you to trigger an fzf search
+with an arbitrary query string. This means fzf is no longer restricted to the
+exact query entered in the prompt.
+
+In the example below, `transform` action is used to conditionally trigger
+either `reload` for ripgrep or `search` for fzf. The first word of the query
+initiates the Ripgrep process to generate the initial results, while the
+remainder of the query is passed to fzf for secondary filtering.
+
+```sh
+#!/usr/bin/env bash
+
+# Switch between Ripgrep mode and fzf filtering mode (CTRL-T)
+RG_PREFIX="rg --column --line-number --no-heading --color=always --smart-case "
+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
+ echo "reload:sleep 0.1; $RG_PREFIX \"${words[0]}\" || true"
+ fi
+'
+fzf --ansi --disabled --query "$INITIAL_QUERY" \
+ --with-shell 'bash -c' \
+ --bind "start:transform:$TRANSFORMER" \
+ --bind "change:transform:$TRANSFORMER" \
+ --color "hl:-1:underline,hl+:-1:underline:reverse" \
+ --delimiter : \
+ --preview 'bat --color=always {1} --highlight-line {2}' \
+ --preview-window 'up,60%,border-bottom,+{2}+3/3,~3' \
+ --bind 'enter:become(vim {1} +{2})'
+```
+
Log tailing
-----------