Skip to content

Instantly share code, notes, and snippets.

@Delapouite
Created July 25, 2018 06:34
Show Gist options
  • Save Delapouite/26723b2ed4d5d9fd4f97e9cac248db34 to your computer and use it in GitHub Desktop.
Save Delapouite/26723b2ed4d5d9fd4f97e9cac248db34 to your computer and use it in GitHub Desktop.
fk
#!/bin/sh
# used by kakoune to use fzf+rg
# sleep needed to get real dimensions
sleep 0.1
COLUMNS=$(tput cols)
LINES=$(tput lines)
# multiply by 2 to roughly approximate the size of a cell
LINES=$(expr $LINES \* 2)
[ $COLUMNS -gt $LINES ] && pos=right:50% || pos=top:60%
# fzf quick reminder:
# --select-1: auto-select the only match
# --multi: use <tab> to select multiple files
# --delimiter: to separate the filename from the match
if [ $# -eq 0 ]; then
# no node_modules nor .git
export FZF_DEFAULT_COMMAND='rg --files'
fzf \
--select-1 \
--multi \
--preview="~/bin/preview.rb {} | head -n 100" \
--preview-window=$pos \
--bind 'ctrl-t:toggle-preview' \
--bind 'ctrl-x:execute($EDITOR {})' \
| xargs $EDITOR
else
rg "$1" \
--column \
--line-number \
--color=always \
| fzf \
--ansi \
--select-1 \
--multi \
--delimiter : \
--preview="~/bin/preview.rb {1}:{2}" \
--preview-window=$pos \
--bind 'ctrl-t:toggle-preview' \
--bind 'ctrl-x:execute($EDITOR {})' \
| cut -d : -f 1,2,3 \
| awk -F : '{ print $1 " +"$2":"$3 }' \
| xargs $EDITOR
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment