Useful recipes of various fzf+rga+bat integrations
This will repo will help you to search for code faster than ever.
Basic version of qse:
qse() {
RG_PREFIX="rg --files-with-matches"
local file
file="$(
FZF_DEFAULT_COMMAND="$RG_PREFIX '$1'" \
fzf \
--preview="[[ ! -z {} ]] && rg --pretty --context 5 {q} {}" \
--disabled --query "$1" \
--bind "change:reload:sleep 0.1; $RG_PREFIX {q}" \
--bind "f3:execute(bat --paging=always --pager=less --color=always {} < /dev/tty > /dev/tty)" \
--bind "f4:execute(code {})" \
--preview-window="70%:wrap"
)" &&
echo "$file"
}Advanced version with bat-preview (and awesome batgrep from bat-extras)
export BAT_THEME="Monokai Extended"
qsb() {
RG_PREFIX="rg --files-with-matches"
local file
file="$(
FZF_DEFAULT_COMMAND="$RG_PREFIX '$1'" \
fzf \
--preview="if [[ -n {} ]]; then if [[ -n {q} ]]; then batgrep --color=always --terminal-width=\$FZF_PREVIEW_COLUMNS --context=3 {q} {}; else bat --color=always {}; fi; fi" \
--disabled --query "$1" \
--bind "change:reload:sleep 0.1; $RG_PREFIX {q}" \
--bind "f3:execute(bat --paging=always --pager=\"less -j4 -R +/{q}\" --color=always {} < /dev/tty > /dev/tty)" \
--bind "f4:execute(code {})" \
--preview-window="70%:wrap"
)" &&
echo "$file"
}And one more version with hidden files included by default is also helpful:
qsh() {
RG_PREFIX="rg --files-with-matches --hidden --glob '!.git'"
local file
file="$(
FZF_DEFAULT_COMMAND="$RG_PREFIX '$1'" \
fzf \
--preview="if [[ -n {} ]]; then if [[ -n {q} ]]; then batgrep --color=always --terminal-width=\$FZF_PREVIEW_COLUMNS --context=3 {q} {}; else bat --color=always --terminal-width=\$FZF_PREVIEW_COLUMNS {}; fi; fi" \
--disabled --query "$1" \
--bind "change:reload:sleep 0.1; $RG_PREFIX {q}" \
--bind "f3:execute(bat --paging=always --pager=\"less -j4 -R +/{q}\" --color=always {} < /dev/tty > /dev/tty)" \
--bind "f4:execute(code {})" \
--preview-window="70%:wrap"
)" &&
echo "$file"
}Install bat, fzf, ripgrep and batgrep/bat-extras, for example:
brew install ripgrep fzf bat bat-extrasThen simply add recipe to your ~/.shrc or ~/.zshrc and restart the shell