How to using rga (ripgrep-all) with fzf for searching the pdf file and then using sioyek to open that file with its page number?
Like this nvim script with rg : #!/usr/bin/env bash
1. Search for text in files using Ripgrep
2. Interactively narrow down the list using fzf
3. Open the file in Vim
rg --color=always --line-number --no-heading --smart-case "${*:-}" |
fzf --ansi \
--color "hl:-1:underline,hl+:-1:underline:reverse" \
--delimiter : \
--preview 'bat --color=always {1} --highlight-line {2}' \
--preview-window 'up,60%,border-bottom,+{2}+3/3,~3' \
--bind 'enter:become(nvim {1} +{2})'
I have found a similar fzf for rga from their official websites:
rga-fzf() {
RG_PREFIX="rga --files-with-matches"
local file
file="$(
FZF_DEFAULT_COMMAND="$RG_PREFIX '$1'" \
fzf -m --sort --preview="[[ ! -z {} ]] && rga --pretty --context 3 {q} {}" \
--phony -q "$1" \
--bind "change:reload:$RG_PREFIX {q}" \
--preview-window="80%:wrap"
)" &&
echo "opening $file" &&
open "$file"
}
I want make it become sioyek "$file" --pages "page_number " etc
Thanks !!
I tried to using awk to grep the first part of the fzf result:
rga -t f ( rga type : pdf)
result : some file name.pdf:Page 42:sentense that contains my searching words
But I don't know how to awk the page, or using built in function from rg to achieve this
One more similar example :
skrga() {
local file
file="$(sk-tmux --bind "ctrl-p:toggle-preview" --ansi -i --cmd-query "$*" -c 'rga --ignore-case --color=always --line-number --column {}' --preview 'bat --color=always --style=header,numbers --highlight-line "$(echo {1}|cut -d: -f2)" --line-range "$(($(echo {1}|cut -d: -f2))):$(($(echo {1}|cut -d: -f2)+50))" "$(echo {1}|cut -d: -f1)"')"; [[ $? -eq 0 ]] && echo "opening $file" && subl "$(echo "$file"|cut -d: -f1):$(echo "$file"|cut -d: -f2):$(echo "$file"|cut -d: -f3)" || return 1;
}
Thanks!