Welcome to Vifm Q&A, where you can ask questions about using Vifm. Registration is optional, anonymous posts are moderated. E-mail and GitHub logins are enabled.
0 votes
in vifm by
edited by

Hi, again.

I tried using the "template" of the find+fzf command that the vifm wiki provides to navigate directories with ripgrep, but I couldn't manage it. When I select the entry, the output displayed is the entire line ripgrep shows, not the filename.
image
What I try to do:

command! MoveRipGrep : set noquickview
                  \| let $FZF_PICK = term("rg --column --line-number --color=always --smart-case . | fzf --ansi --color 'hl:-1:underline,hl+:-1:underline:reverse' --delimiter : --preview '' --border 'none' --no-bold --color='gutter:-1' --layout=reverse --height 100%% 2>/dev/tty &")
                  \| [ -n "$res" ] && vifm --remote "send $id select \"$res\""
                  \| if $FZF_PICK != ''
                  \|     execute system('[ -f "$FZF_PICK" ] && echo goto || echo cd') fnameescape($FZF_PICK)
                  \| endif

There is a command in lf that does it, I tried to replicate it in vifm:

cmd moveripgrepfzf ${{
    RG_PREFIX="rg --column --line-number --no-heading --color=always --smart-case "
    res="$(
        FZF_DEFAULT_COMMAND="$RG_PREFIX ''" \
    fzf --ansi \
        --color "hl:-1:underline,hl+:-1:underline:reverse" \
        --delimiter : \
        --preview 'bat --color=always {1} --highlight-line {2} --wrap=auto' \
        --preview-window 'sharp' \
        --border=none --no-bold --color='gutter:-1' \
        --layout=reverse --height 100% \
        | cut -d':' -f1 | sed 's/\\/\\\\/g;s/"/\\"/g'
    )"
    [ -n "$res" ] && lf -remote "send $id select \"$res\""
}}

1 Answer

0 votes
by
  1. Drop & at the end, it's at best just ignored.
  2. Either drop --column --line-number or append | cut -f1 -d: like in this question (and in the command for lf). Version below does the latter.
  3. Remove the line with [ -n $res" ] ....

Putting it together:

command! MoveRipGrep : set noquickview
                    \| let $FZF_PICK = term("rg --column --line-number --color=always --smart-case . | fzf --ansi --color 'hl:-1:underline,hl+:-1:underline:reverse' --delimiter : --preview '' --border 'none' --no-bold --color='gutter:-1' --layout=reverse --height 100%% 2>/dev/tty | cut -f1 -d:")
                    \| if $FZF_PICK != ''
                    \|     execute system('[ -f "$FZF_PICK" ] && echo goto || echo cd') fnameescape($FZF_PICK)
                    \| endif

Don't have rg to test it though, but the command should be close to working.

If you would like to make a bug report or feature request consider using GitHub, SourceForge or e-mail. Posting such things here is acceptable, but this is not a perfect place for them.
...