Skip to content

QtRoS/qse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

22 Commits
ย 
ย 

Repository files navigation

๐Ÿ” qse

Useful recipes of various fzf+rga+bat integrations

Summary

About

This will repo will help you to search for code faster than ever.

Recipes

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"
}

asciicast

Advanced

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 --terminal-width=\$FZF_PREVIEW_COLUMNS {}; fi; fi" \
			--disabled --query "$1" \
			--bind "change:reload:sleep 0.15; $RG_PREFIX {q}" \
			--bind "f3:execute(bat --paging=always --pager=\"less -j4 -R +/{q}\" --color=always {} < /dev/tty > /dev/tty)" \
			--bind "f4:execute(code {})" \
			--bind "f6:change-preview-window(hidden|up:50%|hidden|)" \
			--preview-window="70%:wrap"
	)" &&
	echo "$file"
}

asciicast

Version below goes further and allows you to search via ripgrep and then filter with fzf, and also hidden files included by default:

qsf() {
    rm -f /tmp/rg-fzf-{r,f}
	RG_PREFIX="rg --files-with-matches --hidden --glob '!.git'"
    INITIAL_QUERY="${*:-}"
    echo $INITIAL_QUERY > /tmp/rg-fzf-r
	local file
	file="$(
        fzf --disabled --query "$INITIAL_QUERY" \
        --preview="if [[ -n {} ]]; then if [[ -n \$(<'/tmp/rg-fzf-r') ]]; then batgrep --color=always --terminal-width=\$FZF_PREVIEW_COLUMNS --context=3 \$(<'/tmp/rg-fzf-r') {}; else bat --color=always {}; fi; fi" \
        --bind "start:reload($RG_PREFIX {q})" \
        --bind "change:reload:sleep 0.15; echo {q} > /tmp/rg-fzf-r; $RG_PREFIX {q}" \
        --bind "f3:execute(bat --paging=always --pager=\"less -j4 -R +/\$(<'/tmp/rg-fzf-r')\" --color=always {} < /dev/tty > /dev/tty)" \
        --bind "f4:execute(code {})" \
        --bind "f6:change-preview-window(hidden|up:50%|hidden|)" \
        --prompt "ripgrep> " --header "F3:View | F4:Edit | F6:Layout | F8:Mode" \
        --bind 'f8:transform:[[ ! $FZF_PROMPT =~ ripgrep ]] &&
            echo "rebind(change)+change-prompt(ripgrep> )+disable-search+transform-query:echo \{q} > /tmp/rg-fzf-f; cat /tmp/rg-fzf-r" ||
            echo "unbind(change)+change-prompt(fzf> )+enable-search+transform-query:echo \{q} > /tmp/rg-fzf-r; cat /tmp/rg-fzf-f"' \
        --preview-window="70%:wrap"
	)" &&
	echo "$file"
}

Installation

Install bat, fzf, ripgrep and batgrep/bat-extras, for example:

brew install ripgrep fzf bat bat-extras

For debian/ubuntu:

sudo apt install ripgrep fzf bat bat-extras

Then simply add recipe to your ~/.shrc or ~/.zshrc and restart the shell

About

Useful recipes of various fzf+rga+bat integrations

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors