-
Notifications
You must be signed in to change notification settings - Fork 0
/
rf
executable file
·30 lines (27 loc) · 1.44 KB
/
rf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env bash
# https://github.com/junegunn/fzf/blob/master/ADVANCED.md#switching-between-ripgrep-mode-and-fzf-mode
if is-dark-mode; then
BAT_THEME="Monokai Extended Origin"
else
BAT_THEME="Monokai Extended Light"
fi
export BAT_THEME
SWITCH_CACHE_DIR=$(mktemp -d)
trap 'rm -rf "$SWITCH_CACHE_DIR"' EXIT
# Switch between Ripgrep launcher mode (CTRL-R) and fzf filtering mode (CTRL-F)
RG_PREFIX="rg --column --line-number --no-heading --color=always --smart-case "
INITIAL_QUERY="${*:-}"
FZF_DEFAULT_COMMAND="$RG_PREFIX $(printf %q "$INITIAL_QUERY")" \
fzf --ansi \
--color "hl:-1:underline,hl+:-1:underline:reverse" \
--disabled --query "$INITIAL_QUERY" \
--bind "change:reload:sleep 0.1; $RG_PREFIX {q} || true" \
--bind "ctrl-f:unbind(change,ctrl-f)+change-prompt(2. fzf> )+enable-search+rebind(ctrl-r)+transform-query(echo {q} > '$SWITCH_CACHE_DIR/rg-fzf-r'; cat '$SWITCH_CACHE_DIR/rg-fzf-f')" \
--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} > '$SWITCH_CACHE_DIR/rg-fzf-f'; cat '$SWITCH_CACHE_DIR/rg-fzf-r')" \
--bind "start:unbind(ctrl-r)" \
--prompt '1. ripgrep> ' \
--delimiter : \
--header '╱ CTRL-R (ripgrep mode) ╱ CTRL-F (fzf mode) ╱' \
--preview "bat --color=always {1} --highlight-line {2}" \
--preview-window 'up,60%,border-bottom,+{2}+3/3,~3' \
--bind "enter:become($EDITOR {1} +{2})"