Skip to content
Myr

Update ADVANCED example using 'search' action

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Junegunn Choi · committed by Junegunn Choi · parent 51c2074 · Browse files · 2 files+12 added−14 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+12 added−14 removed

  • other:+12 added−14 removed

2 files+12 added−14 removed

modified:ADVANCED.md+6 added-7 removed
513 unmodified lines
514515```sh516#!/usr/bin/env bash517518export TEMP=$(mktemp -u)519trap 'rm -f "$TEMP"' EXIT520521INITIAL_QUERY="${*:-}"522TRANSFORMER='523 rg_pat={q:1} # The first word is passed to ripgrep524 fzf_pat={q:2..} # The rest are passed to fzf522 rg_pat_org={q:s1} # The first word with trailing whitespaces preserved.523 # We use this to avoid unnecessary reloading of ripgrep.525525 if [[ -n $fzf_pat ]]; then526 echo "search:$fzf_pat"527 elif ! [[ $rg_pat_org =~ \ $ ]]; then526 if ! [[ -r "$TEMP" ]] || [[ $rg_pat != $(cat "$TEMP") ]]; then527 echo "$rg_pat" > "$TEMP"528 printf "reload:sleep 0.1; rg --column --line-number --no-heading --color=always --smart-case %q || true" "$rg_pat"529 else530 echo search:529 fi530 echo "+search:$fzf_pat"531'532fzf --ansi --disabled --query "$INITIAL_QUERY" \533 --with-shell 'bash -c' \534 --bind "start,change:transform:$TRANSFORMER" \
180 unmodified lines
modified:CHANGELOG.md+6 added-7 removed
29 unmodified lines
30 - `kill` completion for bash and zsh were updated to use this feature31- Extended `{q}` placeholder to support ranges. e.g. `{q:1}`, `{q:2..}`, etc.32- 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.33 ```sh34 export TEMP=$(mktemp -u)35 trap 'rm -f "$TEMP"' EXIT3637 TRANSFORMER='38 rg_pat={q:1} # The first word is passed to ripgrep39 fzf_pat={q:2..} # The rest are passed to fzf37 rg_pat_org={q:s1} # The first word with trailing whitespaces preserved.38 # We use this to avoid unnecessary reloading of ripgrep.4040 if [[ -n $fzf_pat ]]; then41 echo "search:$fzf_pat"42 elif ! [[ $rg_pat_org =~ \ $ ]]; then41 if ! [[ -r "$TEMP" ]] || [[ $rg_pat != $(cat "$TEMP") ]]; then42 echo "$rg_pat" > "$TEMP"43 printf "reload:sleep 0.1; rg --column --line-number --no-heading --color=always --smart-case %q || true" "$rg_pat"44 else45 echo search:44 fi45 echo "+search:$fzf_pat"46 '47 fzf --ansi --disabled \48 --with-shell 'bash -c' \49 --bind "start,change:transform:$TRANSFORMER"
2445 unmodified lines