1
0
Fork 0

enshittify find_word function

This commit is contained in:
Luca Bilke 2024-06-19 17:43:56 +02:00
parent fd672968e7
commit 6446b3bfdd
No known key found for this signature in database
GPG Key ID: C9E851809C1A5BDE
1 changed files with 28 additions and 19 deletions

View File

@ -144,25 +144,34 @@ cmd fzf ${{
}}
cmd find_word ${{
set +ue
RG_PREFIX="rg --hidden --column --line-number --no-heading --color=always --smart-case --follow --no-ignore "
res="$(
FZF_DEFAULT_COMMAND="$RG_PREFIX ''" \
fzf --bind "change:reload:$RG_PREFIX {q} || true" \
--ansi --layout=reverse --header 'Searching file contents' |\
grep -iv -e 'Trash/files' -e 'Trash/info'
)"
file="$(realpath "$(echo "$res" | cut -d':' -f1 | sed 's/\\/\\\\/g;s/"/\\"/g')" 2>/dev/null)"
row="$(echo "$res" | cut -d':' -f2)"
column="$(echo "$res" | cut -d':' -f3)"
if [ -n "$res" ]; then
if [ "$EDITOR" = "nvim" ] || [ "$EDITOR" = "vim" ]; then
lf -remote "send $id \$$EDITOR +'call cursor($row, $column)' -- '$file'"
else
lf -remote "send $id \$$EDITOR '$file'"
fi
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
res="$(
FZF_DEFAULT_COMMAND="$RG_PREFIX ." SEDPATTERN='s/\\/\\\\/g;s/"/\\"/g' SHELL="sh" \
fzf --bind "change:reload:${RG_PREFIX} {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
" --ansi --layout=reverse --header 'Searching file contents'
)"
file="$(realpath "$(echo "$res" | cut -d':' -f1 | sed 's/\\/\\\\/g;s/"/\\"/g')" 2>/dev/null)"
row="$(echo "$res" | cut -d':' -f2)"
column="$(echo "$res" | cut -d':' -f3)"
if [ -n "$res" ]; then
if [ "$EDITOR" = "nvim" ] || [ "$EDITOR" = "vim" ]; then
lf -remote "send $id \$$EDITOR +'call cursor($row, $column)' -- '$file'"
else
lf -remote "send $id \$$EDITOR '$file'"
fi
return 0
fi
return 0
}}
cmd find_project ${{
@ -284,7 +293,7 @@ map P link
map q quit
map <c-r> reload
map r :rename # before extension
map R $lf -remote "send $id :select \"$(readlink $f)\""
map R &lf -remote "send $id :select \"$(readlink $f)\""
map sh :set hidden!
map sn :set sortby natural; set info
map ss :set sortby size; set info size