1
0
Fork 0

lf: fix ripgrep search

This commit is contained in:
Luca Bilke 2024-08-15 09:33:04 +02:00
parent a89636e24d
commit 5d119ff52a
Signed by: luca
GPG Key ID: F6E11C9BAA7C82F5
1 changed files with 5 additions and 19 deletions

View File

@ -144,27 +144,13 @@ cmd fzf ${{
cmd find_word ${{
set +ue
RG_PREFIX="rg --hidden --column --line-number --no-heading --color=always --smart-case --follow --no-ignore"
for cmd in bat batcat head; do
command -v $cmd >/dev/null 2>&1 && break
done
rg_cmd="rg -uu --column --line-number --no-heading --color=always --smart-case --follow"
res="$(
FZF_DEFAULT_COMMAND="$RG_PREFIX ." SEDPATTERN='s/\\/\\\\/g;s/"/\\"/g' SHELL="sh" \
fzf \
--ansi \
--exact \
--bind "change:reload:${RG_PREFIX} {q} || true" \
fzf --disabled --ansi --exact --layout=reverse --header 'Searching file contents' --delimiter=: \
--bind="start:reload([ -n {q} ] && $rg_cmd -- {q} || true)" \
--bind="change:reload([ -n {q} ] && $rg_cmd -- {q} || true)" \
--preview-window="right,50%" \
--preview="
file=\$(realpath \"\$(echo {} | cut -d: -f1 | sed \"\${SEDPATTERN}\")\" 2>/dev/null)
case '$cmd' in
head) head -n 300 \"\$file\" ;;
bat*) '$cmd' --color=always --italic-text=always --style=plain --pager=never \
--tabs=4 --theme=base16 --line-range :300 \"\$file\" ;;
esac
" \
--layout=reverse \
--header 'Searching file contents'
--preview='~/.config/lf/preview/clean; ~/.config/lf/preview/preview {1} "$FZF_PREVIEW_COLUMNS" "$FZF_PREVIEW_LINES" "$FZF_PREVIEW_LEFT" "$FZF_PREVIEW_TOP"'
)"
file="$(realpath "$(echo "$res" | cut -d':' -f1 | sed 's/\\/\\\\/g;s/"/\\"/g')" 2>/dev/null)"
row="$(echo "$res" | cut -d':' -f2)"