phiresky / ripgrep-all

rga: ripgrep, but also search in PDFs, E-Books, Office documents, zip, tar.gz, etc.
Other
8.21k stars 177 forks source link

rga-fzf() for fish-shell users #128

Closed ayoubelmhamdi closed 2 years ago

ayoubelmhamdi commented 2 years ago

export SHELL=bash

rga-fzf() { .... }

rga-fzf

bobblkabb commented 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
ayoubelmhamdi commented 2 years ago

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
mathieupost commented 2 years ago

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"