ftop() { FZF_DEFAULT_COMMAND='ps -ef' \ fzf --bind 'ctrl-r:reload(ps -ef)' \ --header 'Press CTRL-R to reload' \ --header-lines=1 \ --height=50% --layout=reverse } __fzf-jump-widget() { LBUFFER="${LBUFFER}$(fasd -ld | tac | fzf)" local ret=$? zle redisplay if [[ $ret == 0 ]]; then zle accept-line fi return $ret } zle -N __fzf-jump-widget __fzf-open-widget() { FILE=$(fasd -lf | tac | fzf) local ret=$? if [[ $ret != 0 ]]; then return $ret fi if [[ "${LBUFFER}" != "" ]]; then LBUFFER="${LBUFFER}${FILE}" elif [[ $(file --mime ${FILE}) =~ "binary" ]]; then LBUFFER="xdg-open ${FILE}" else LBUFFER="${EDITOR} ${FILE}" fi zle redisplay if [[ $ret == 0 ]]; then zle accept-line fi return $ret } zle -N __fzf-open-widget # Search files with preview __fzf-preview-widget() { LBUFFER="${LBUFFER}$(ls | fzf -e --preview=${FZF_BAT_PREVIEW})" } zle -N __fzf-preview-widget # rg on Asteroids rf() { RG_PREFIX="rga --files-with-matches" local file file="$( FZF_DEFAULT_COMMAND="$RG_PREFIX '$1'" \ fzf --sort --preview="[[ ! -z {} ]] && echo {} && rga --pretty --context 5 {q} {}" \ --phony -q "$1" \ --bind "change:reload:$RG_PREFIX {q}" \ --preview-window="70%:wrap" )" && echo $file # echo "opening $file" && # xdg-open "$file" } # Fancy git diff using fzf if which git &>/dev/null; then alias gdf=' git status -s \ | fzf --no-sort --reverse \ --preview "git diff --color=always {+2} | delta" \ --bind=ctrl-j:preview-down --bind=ctrl-k:preview-up \ --preview-window=right:70%:wrap' fi # figure out some useful things to do... # https://junegunn.kr/2016/07/fzf-git/ _FZF_BAT_PREVIEW='[[ $(file --mime {}) =~ "binary" ]] && echo "" || bat --style=numbers --color=always {} --line-range :500' alias fzfp="fzf --preview='${_FZF_BAT_PREVIEW}'" alias fzfd="fzf --preview='${_FZF_BAT_PREVIEW}' --bind='enter:execute(bat --style=numbers --color=always --paging=always {}),ctrl-e:execute(micro {}),tab:toggle-preview'" export FZF_DEFAULT_OPTS="-1 --height 50% --layout=reverse --border --multi --info=inline" # Use fd/rg/ag if possible to follow any ignores / sensible configs if which fd &>/dev/null; then export FZF_DEFAULT_COMMAND='fd --type f' elif which rg &>/dev/null; then export FZF_DEFAULT_COMMAND='rg --files' elif which ag &>/dev/null; then export FZF_DEFAULT_COMMAND='ag --files-with-matches' fi