summaryrefslogtreecommitdiff
path: root/ADVANCED.md
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2025-01-28 17:48:46 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2025-01-28 17:48:46 +0900
commitb83dd6c6b426da99e11a8b3c58c075c70ee2700a (patch)
tree99a628a412d4b5a837d43c714598e8fe570b70ef /ADVANCED.md
parent51c207448da6eb1cea3352d72c2d22682f604b6d (diff)
downloadfzf-b83dd6c6b426da99e11a8b3c58c075c70ee2700a.tar.gz
Update ADVANCED example using 'search' action
Diffstat (limited to 'ADVANCED.md')
-rw-r--r--ADVANCED.md13
1 files changed, 6 insertions, 7 deletions
diff --git a/ADVANCED.md b/ADVANCED.md
index 012fb62b..d9dc72f0 100644
--- a/ADVANCED.md
+++ b/ADVANCED.md
@@ -515,20 +515,19 @@ remainder of the query is passed to fzf for secondary filtering.
```sh
#!/usr/bin/env bash
+export TEMP=$(mktemp -u)
+trap 'rm -f "$TEMP"' EXIT
+
INITIAL_QUERY="${*:-}"
TRANSFORMER='
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
+ if ! [[ -r "$TEMP" ]] || [[ $rg_pat != $(cat "$TEMP") ]]; then
+ echo "$rg_pat" > "$TEMP"
printf "reload:sleep 0.1; rg --column --line-number --no-heading --color=always --smart-case %q || true" "$rg_pat"
- else
- echo search:
fi
+ echo "+search:$fzf_pat"
'
fzf --ansi --disabled --query "$INITIAL_QUERY" \
--with-shell 'bash -c' \