blob: b9c0566c5813c6fe65238e72fed8273067a7117f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
#!/bin/sh
# fzf-grep: browse through grepped lines using fzf
if [ "$OPENFLAG" = 0 ]; then
location="$(echo "$*" | sed 's/^\(.*\):\([0-9]\+\):.*$/\1|\2/')"
file="${location%|*}"; line="${location##*|}"
case "${OPENWITH:=$EDITOR}" in
''|vi|*vim*) $OPENWITH +"$line" "$file" ;;
*) $OPENWITH "$file" ;;
esac; exit
fi
[ -z "$FZF_HISTDIR" ] &&
export FZF_HISTDIR="${XDG_STATE_HOME:-$HOME/.local/state}/fzf"
mkdir -pv "$FZF_HISTDIR"
export FZF_HIST="$FZF_HISTDIR/grep_history"
grep -Rnsi --exclude-dir=.git --exclude-dir=node_modules --color=always "$@" |
fzf --ansi \
--history="$FZF_HIST" \
--prompt="grep > " \
--preview='preview "$(echo {1} | cut -d: -f1)"' \
--preview-window="hidden" \
--bind 'ctrl-v:toggle-preview,ctrl-space:toggle-preview' \
--bind "ctrl-r:reload(grep -Rns --color=always $*)" \
--bind 'enter:execute(append-to-history {} "$FZF_HIST"; OPENFLAG=0 fgrp {})' \
--bind 'alt-e:execute(append-to-history {} "$FZF_HIST"; OPENFLAG=0 OPENWITH=${EDITOR:-vi} fgrp {})' \
--bind 'alt-o:execute(append-to-history {} "$FZF_HIST"; OPENFLAG=0 OPENWITH=${OPENER:-xdg-open} fgrp {})' \
--bind 'alt-O:execute(append-to-history {} "$FZF_HIST"; OPENFLAG=0 OPENWITH=${FILES:-lf} fgrp {})'
|