Closed ayoubelmhamdi closed 2 years ago
Found this somewhere, couldn't test it because I got an old fish version (2.7.1)
function rga-fzf
set -x RG_PREFIX rga --files-with-matches
set -l file
set file (
FZF_DEFAULT_COMMAND="$RG_PREFIX '$argv'" \
fzf --sort --preview="[ ! -z {} ] && rga --pretty --context 5 {q} {}" \
--phony -q "$argv" \ --bind "change:reload:$RG_PREFIX {q}" \
--preview-window="70%:wrap"
) &&
open "$file"
end
thank you, it's work
but must add a new line before --bind
function rga-fzf ... --phony -q "$argv" \ --bind "change:reload:$RG_PREFIX {q}" \ ... end
Created another version with help from babelfish
and edited it so it also accepts more flags if needed.
function rga-fzf
set RG_PREFIX 'rga --files-with-matches --sort=path'
if test (count $argv) -gt 1
set RG_PREFIX "$RG_PREFIX $argv[1..-2]"
end
set -l file $file
set file (
FZF_DEFAULT_COMMAND="$RG_PREFIX '$argv[-1]'" \
fzf --sort --preview='test ! -z {} && \
rga --pretty \
--context 5 {q} {}' \
--phony -q "$argv[-1]" \
--bind "change:reload:$RG_PREFIX {q}" \
--preview-window='50%:wrap'
) && \
echo "opening $file" && \
open "$file"
end
Example to include pdfs only: rga-fzf -tpdf "my search query"
shell
ascli
need forcebash
as default shell forfzf
like that:export SHELL=bash
rga-fzf() { .... }
rga-fzf