dotfiles/.local/bin/fzf-grep

42 lines
1.7 KiB
Plaintext
Raw Normal View History

2024-05-18 13:41:08 +05:00
#!/usr/bin/env bash
2024-04-23 07:34:15 +05:00
2024-05-25 20:48:42 +05:00
dwmc setlayoutex 2
2024-05-18 13:41:08 +05:00
rm -f /tmp/rg-fzf-{r,f}
2024-04-23 07:34:15 +05:00
2024-05-18 13:41:08 +05:00
[ -d "$1" ] && SEARCH_DIR="$1" && shift || SEARCH_DIR="."
2024-04-23 07:34:15 +05:00
RG_PREFIX="rg --hidden --column --line-number --no-heading --follow --color=always --smart-case \
--glob '!/.ssh' --glob '!/.android' --glob '!/.gnupg' --glob '!node_modules'"
2024-05-18 13:41:08 +05:00
INITIAL_QUERY="${*:-}"
2024-04-23 07:34:15 +05:00
h_padding=$(printf '%*s' 7 ' ')
h_gap=$(printf '%*s' 2 ' ')
HEADER="${h_padding}\
 Prefix:Alt${h_gap}\
 Space:fzf/ripgrep${h_gap}\
 A:Select All${h_gap}\
 D:Deselect All${h_gap}\
 /:Toggle Preview${h_gap}\
 Q:Quickfix List"
: | fzf --ansi --multi --disabled --query "$INITIAL_QUERY" \
2024-05-18 13:41:08 +05:00
--bind "start:reload:$RG_PREFIX {q} $SEARCH_DIR" \
--bind "change:reload:sleep 0.1; $RG_PREFIX {q} $SEARCH_DIR || true" \
--bind "alt-space:transform:[[ ! \$FZF_PROMPT =~ ripgrep ]] &&
2024-05-18 13:41:08 +05:00
echo \"rebind(change)+change-prompt(ripgrep  )+disable-search+transform-query:echo {q} > /tmp/rg-fzf-f; cat /tmp/rg-fzf-r\" ||
echo \"unbind(change)+change-prompt(fzf  )+enable-search+transform-query:echo {q} > /tmp/rg-fzf-r; cat /tmp/rg-fzf-f\"" \
--bind 'alt-a:select-all,alt-d:deselect-all,alt-/:toggle-preview' \
2024-05-25 20:48:42 +05:00
--margin=5%,10%,5%,10% --height=100% --reverse --color=16 --info=inline-right \
--scrollbar=▐ --keep-right --border=none --ellipsis= \
2024-05-18 13:41:08 +05:00
--prompt 'ripgrep  ' \
--delimiter : \
--header "$HEADER" --header-first \
2024-05-18 13:41:08 +05:00
--preview 'bat --style=header,numbers --color=always {1} --highlight-line {2}' \
--preview-window 'bottom,60%,border-top,+{2}+3/3,~1' \
--bind "alt-q:execute:nvim +cw -q {+f}" \
--bind "enter:execute:nvim {1} +{2}"
2024-05-18 13:41:08 +05:00
2024-05-25 20:48:42 +05:00
dwmc setlayoutex 0