Skip to content
Myr

ADVANCED.md: Remove unnecessary `: | fzf`

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

See 5b52833

authored by Junegunn Choi · committed by Junegunn Choi · parent 8689f5f · Browse files · 1 file+10 added−12 removed
This commit

State

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

Diff stats

1 file+10 added−12 removed

  • other:+10 added−12 removed

1 file+10 added−12 removed

modified:ADVANCED.md+10 added-12 removed
1Advanced fzf examples2======================34* *Last update: 2024/06/06*5* *Requires fzf 0.53.0 or later*4* *Last update: 2024/06/24*5* *Requires fzf 0.54.0 or later*67---89<!-- vim-markdown-toc GFM -->
350 unmodified lines
360# 2. Interactively restart Ripgrep with reload action361# 3. Open the file in Vim362RG_PREFIX="rg --column --line-number --no-heading --color=always --smart-case "363INITIAL_QUERY="${*:-}"364: | fzf --ansi --disabled --query "$INITIAL_QUERY" \364fzf --ansi --disabled --query "$INITIAL_QUERY" \365 --bind "start:reload:$RG_PREFIX {q}" \366 --bind "change:reload:sleep 0.1; $RG_PREFIX {q} || true" \367 --delimiter : \368 --preview 'bat --color=always {1} --highlight-line {2}' \
2 unmodified lines
371```372373![image](https://user-images.githubusercontent.com/700826/113684212-f9ff0a00-96ff-11eb-8737-7bb571d320cc.png)374375- Instead of starting fzf in the usual `rg ... | fzf` form, we start fzf with376 an empty input (`: | fzf`), then we make it start the initial Ripgrep377 process immediately via `start:reload` binding. This way, fzf owns the378 initial Ripgrep process so it can kill it on the next `reload`. Otherwise,379 the process will keep running in the background.375- Instead of starting fzf in the usual `rg ... | fzf` form, we make it start376 the initial Ripgrep process immediately via `start:reload` binding for the377 consistency of the code.378- Filtering is no longer a responsibility of fzf; hence `--disabled`379- `{q}` in the reload command evaluates to the query string on fzf prompt.380- `sleep 0.1` in the reload command is for "debouncing". This small delay will381 reduce the number of intermediate Ripgrep processes while we're typing in
15 unmodified lines
397# * Press alt-enter to switch to fzf-only filtering398# 3. Open the file in Vim399RG_PREFIX="rg --column --line-number --no-heading --color=always --smart-case "400INITIAL_QUERY="${*:-}"403: | fzf --ansi --disabled --query "$INITIAL_QUERY" \401fzf --ansi --disabled --query "$INITIAL_QUERY" \402 --bind "start:reload:$RG_PREFIX {q}" \403 --bind "change:reload:sleep 0.1; $RG_PREFIX {q} || true" \404 --bind "alt-enter:unbind(change,alt-enter)+change-prompt(2. fzf> )+enable-search+clear-query" \405 --color "hl:-1:underline,hl+:-1:underline:reverse" \
35 unmodified lines
441# Switch between Ripgrep launcher mode (CTRL-R) and fzf filtering mode (CTRL-F)442rm -f /tmp/rg-fzf-{r,f}443RG_PREFIX="rg --column --line-number --no-heading --color=always --smart-case "444INITIAL_QUERY="${*:-}"447: | fzf --ansi --disabled --query "$INITIAL_QUERY" \445fzf --ansi --disabled --query "$INITIAL_QUERY" \446 --bind "start:reload($RG_PREFIX {q})+unbind(ctrl-r)" \447 --bind "change:reload:sleep 0.1; $RG_PREFIX {q} || true" \448 --bind "ctrl-f:unbind(change,ctrl-f)+change-prompt(2. fzf> )+enable-search+rebind(ctrl-r)+transform-query(echo {q} > /tmp/rg-fzf-r; cat /tmp/rg-fzf-f)" \449 --bind "ctrl-r:unbind(ctrl-r)+change-prompt(1. ripgrep> )+disable-search+reload($RG_PREFIX {q} || true)+rebind(change,ctrl-f)+transform-query(echo {q} > /tmp/rg-fzf-f; cat /tmp/rg-fzf-r)" \
34 unmodified lines
484# Switch between Ripgrep mode and fzf filtering mode (CTRL-T)485rm -f /tmp/rg-fzf-{r,f}486RG_PREFIX="rg --column --line-number --no-heading --color=always --smart-case "487INITIAL_QUERY="${*:-}"490: | fzf --ansi --disabled --query "$INITIAL_QUERY" \488fzf --ansi --disabled --query "$INITIAL_QUERY" \489 --bind "start:reload:$RG_PREFIX {q}" \490 --bind "change:reload:sleep 0.1; $RG_PREFIX {q} || true" \491 --bind 'ctrl-t:transform:[[ ! $FZF_PROMPT =~ ripgrep ]] &&492 echo "rebind(change)+change-prompt(1. ripgrep> )+disable-search+transform-query:echo \{q} > /tmp/rg-fzf-f; cat /tmp/rg-fzf-r" ||
31 unmodified lines
524Kubernetes pods.525526```bash527pods() {530 : | command='kubectl get pods --all-namespaces' fzf \528 command='kubectl get pods --all-namespaces' fzf \529 --info=inline --layout=reverse --header-lines=1 \530 --prompt "$(kubectl config current-context | sed 's/-context$//')> " \531 --header $'╱ Enter (kubectl exec) ╱ CTRL-O (open log in editor) ╱ CTRL-R (reload) ╱\n\n' \532 --bind 'start:reload:$command' \
144 unmodified lines