Welcome to Vifm Q&A, where you can ask questions about Vifm usage. Registration is optional, anonymous posts are moderated. GitHub or Google logins are enabled.
0 votes
in vifm by

Hi,

need some help to combine 2 Fzf commands found in the wiki:

command! FZFcd :set noquickview | :execute 'cd ' fnameescape(term('locate $HOME | fzf-tmux --height 10 2>/dev/tty'))

command! FZFlocate :set noquickview | :execute 'goto ' fnameescape(term('locate $HOME | fzf-tmux --height 10 2>/dev/tty'))

I have one for cd, and one for goto. Not sure how to combine the two into one command.

i found a similar command that works in lf:

cmd fzf_jump ${{
  res="$(find . -maxdepth 3 | fzf --reverse --header='Jump to location')"
  if [ -f "$res" ]; then
    cmd="select"
  elif [ -d "$res" ]; then
    cmd="cd"
  fi
  lf -remote "send $id $cmd \"$res\""
}}

just not sure how to get it working in vifm ...

1 Answer

0 votes
by
 
Best answer

Hello,

this is going to be somewhat ugly:

command! FZF : set noquickview
            \| let $FZF_PICK = term('locate $HOME | fzf-tmux --height 10 2>/dev/tty')
            \| execute term('[ -f "$FZF_PICK" ] && echo goto || echo cd') fnameescape($FZF_PICK)
by

Wow, thank you for your answer, it works great !!!

sorry for the bother, but i am actually using an older version of the script, ie:

command! FZFcd :set noquickview | :execute 'cd "'.system('locate $HOME | fzf-tmux --height 10 2>/dev/tty ').'"%IU' | redraw

that uses .system instead of fnameescape, and when run in tmux it doesn't hide vifm when it s run, unlike the command using fnameescape.

would your command also work with the .system command ?

i tried a bit, but didn't get it working,

either way, thanks again

by

It's not fnameescape(), but one of term() that needs to be replaced with system(). Probably like this:

command! FZF : set noquickview
            \| let $FZF_PICK = system('locate $HOME | fzf-tmux --height 10 2>/dev/tty')
            \| execute term('[ -f "$FZF_PICK" ] && echo goto || echo cd') fnameescape($FZF_PICK)
            \| redraw
by

Thanks again !!!

i changed your above command a bit with your answer from below post, so there is no cd if nothing is chosen with fzf:
vifm github issue link
vifm Q&A link

to this:

command! FZF : set noquickview
            \| let $FZF_PICK = system('locate $HOME | fzf-tmux --height 10 2>/dev/tty')
            \| if $FZF_PICK != ''
            \|     execute term('[ -f "$FZF_PICK" ] && echo goto || echo cd') fnameescape($FZF_PICK)
            \| endif
            \| redraw

i don't know if this is the correct way to do this, but it works great for me.

Maybe something like this could be added to the wiki, for others?

thank you again xaizek for all your help :-)

by

Right, updated https://wiki.vifm.info/index.php/How_to_integrate_fzf_for_fuzzy_finding#Commands

By the way, replace second term() use as well. system() is all that's needed there and term() will only cause unnecessary flicker.

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.
...