Skip to content

Instantly share code, notes, and snippets.

@emjayoh
Created November 17, 2020 21:10
Show Gist options
  • Select an option

  • Save emjayoh/c120f68070fb00fa29f7c3ac3961ed60 to your computer and use it in GitHub Desktop.

Select an option

Save emjayoh/c120f68070fb00fa29f7c3ac3961ed60 to your computer and use it in GitHub Desktop.
[FZF stuff] aliases and stuff for fzf/rg #fzf #rg #zsh #bash #terminal #snoop
export FZF_DEFAULT_OPTS="
--layout=reverse
--info=inline
--height=80%
--multi
--preview-window=:hidden
--preview '([[ -f {} ]] && (bat --style=numbers --color=always {} || cat {})) || ([[ -d {} ]] && (tree -C {} | less)) || echo {} 2> /dev/null | head -200'
--color='hl:148,hl+:154,pointer:032,marker:010,bg+:237,gutter:008'
--prompt='∼ ' --pointer='▶' --marker='✓'
--bind '?:toggle-preview'
--bind 'ctrl-a:select-all'
--bind 'ctrl-y:execute-silent(echo {+} | pbcopy)'
--bind 'ctrl-e:execute(echo {+} | xargs -o vim)'
--bind 'ctrl-v:execute(code {+})'
"
fzf --preview '([[ -f {} ]] && (bat --style=numbers --color=always {} || cat {})) || ([[ -d {} ]] && (tree -C {} | less)) || echo {} 2> /dev/null | head -200'
# fzf's command
export FZF_DEFAULT_COMMAND="fd"
# CTRL-T's command
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
# ALT-C's command
export FZF_ALT_C_COMMAND="$FZF_DEFAULT_COMMAND --type d"
# Sensible default command
export FZF_DEFAULT_COMMAND="fd --hidden --follow --exclude '.git' --exclude 'node_modules'"
# RG + FZF
# find-in-file - usage: fif <SEARCH_TERM>
fif() {
if [ ! "$#" -gt 0 ]; then
echo "Need a string to search for!";
return 1;
fi rg --files-with-matches --no-messages "$1" | fzf $FZF_PREVIEW_WINDOW --preview "rg --ignore-case --pretty --context 10 '$1' {}"
}
# usage: add to zshrc and run:
# fif <SEARCH_TERM>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment