mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2025-02-02 03:58:30 +00:00
Update ADVANCED example using 'search' action
This commit is contained in:
parent
51c207448d
commit
b83dd6c6b4
13
ADVANCED.md
13
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' \
|
||||
|
13
CHANGELOG.md
13
CHANGELOG.md
@ -31,19 +31,18 @@ CHANGELOG
|
||||
- Extended `{q}` placeholder to support ranges. e.g. `{q:1}`, `{q:2..}`, etc.
|
||||
- Added `search(...)` and `transform-search(...)` action to trigger an fzf search with an arbitrary query string. This can be used to extend the search syntax of fzf. In the following example, fzf will use the first word of the query to trigger ripgrep search, and use the rest of the query to perform fzf search within the result.
|
||||
```sh
|
||||
export TEMP=$(mktemp -u)
|
||||
trap 'rm -f "$TEMP"' EXIT
|
||||
|
||||
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 \
|
||||
--with-shell 'bash -c' \
|
||||
|
Loading…
x
Reference in New Issue
Block a user