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.

Only cd if external command returns something

0 votes
asked Dec 6, 2018 in vifm by mwgkgk

Using an fzf command like

command! FzfHere :execute 'cd' "'".term('fd -t d "" .  | fzf 2> /dev/tty')."'"
nmap รท :FzfHere<CR>

There's a drawback that a cancelled fzf select will run the cd with no arguments, moving us back to home folder. What is a good way to approach this?

Can it be done with :if somehow? Or does it require functions?

If all else fails, here's a workaround I came up with:

command! FzfHere :execute 'cd' "'".term('fd -t d "" .  | fzf 2> /dev/tty | xargs dot-if-empty')."'"

dot-if-empty:

#!/bin/dash

if [ $# -eq 0 ]; then
  echo "."
else
  echo $@
fi

1 Answer

0 votes
answered Dec 6, 2018 by xaizek
selected Dec 7, 2018 by mwgkgk
 
Best answer

I see you have found issue #309 on GitHub with the following command:

command! fzf : let $FZF_RES = term('fzf 2>&0')
            \| if $FZF_RES != ''
            \|     goto $FZF_RES
            \| endif

It doesn't work as expected or you asked the question before seeing it?

commented Dec 7, 2018 by mwgkgk

That exact one didn't work for me, as it turns out because of 2>&0 bit, so I've abandoned that answer somewhere along the road and forgot it exists. Changing it to 2>/dev/tty works! Thank you.

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