Skip to content

Commit

Permalink
add contextual preview to kks-grep
Browse files Browse the repository at this point in the history
  • Loading branch information
kkga committed Sep 18, 2021
1 parent 8e27167 commit fa03f24
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion scripts/kks-grep
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
# requires:
# - ripgrep (https://github.com/BurntSushi/ripgrep)
# - fzf (https://github.com/junegunn/fzf)
# - bat (change to your liking) (https://github.com/sharkdp/bat)

history_file="$HOME/.cache/kks-grep-history"

[ -f "$history_file" ] || touch "$history_file"

rg --vimgrep '.+' "$@" |
fzf --height 100% --prompt 'grep> ' --history="$history_file" |
fzf -d ':' --height 100% --prompt 'grep> ' --history="$history_file" \
--preview='range="$(echo {2}-5 | bc | sed "s/^-.*/0/"):$(echo {2}+20 | bc)"; bat -r "$range" -n --color always -H {2} {1}' |
awk -F':' '{print $1 " " "+" $2 ":" $3 }' |
xargs -r kks edit

0 comments on commit fa03f24

Please sign in to comment.