Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

:FZF ~ empty in (neo)vim #1061

Closed
3 of 15 tasks
refacto opened this issue Sep 26, 2017 · 15 comments
Closed
3 of 15 tasks

:FZF ~ empty in (neo)vim #1061

refacto opened this issue Sep 26, 2017 · 15 comments

Comments

@refacto
Copy link

refacto commented Sep 26, 2017

  • Category
    • fzf binary
    • fzf-tmux script
    • Key bindings
    • Completion
    • Vim
    • Neovim
    • Etc.
  • OS
    • Linux
    • Mac OS X
    • Windows
    • Windows Subsystem for Linux
    • Etc. (Termux)
  • Shell
    • bash
    • zsh
    • fish

Whenever I try to use :FZF ~ from within vim or neovim, it shows:

  0/0
~/

The same goes for :Files from the fzf.vim plugin.
Although, find | fzf works perfectly. Note that I'm using termux, so shell variables might be unusual, but they're correct: $SHELL is /data/data/com.termux/files/usr/bin/zsh, $TERM is xterm.

@junegunn
Copy link
Owner

Although, find | fzf works perfectly

How about plain fzf (without stdin pipe)? Does it work?

@refacto
Copy link
Author

refacto commented Sep 26, 2017

That's empty as well.

@refacto refacto changed the title :FZF ~ empty in (neo)vim :FZF ~ empty in (neo)vim Sep 26, 2017
@junegunn
Copy link
Owner

Do you have $FZF_DEFAULT_COMMAND defined? Is it a valid command? Does it work?

@refacto
Copy link
Author

refacto commented Sep 26, 2017

I've set $FZF_DEFAULT_COMMAND to ls, now it seems to be working. The problem now is that subdirectories don't get shown.

@refacto
Copy link
Author

refacto commented Sep 26, 2017

According to #510 I've now manually set FZF_DEFAULT_COMMAND to

find . -path '*/\.*' -prune -o -type f -print -o -type l -print 2> /dev/null | sed s/^..//

And now it works perfectly. Thanks for the hint!

@refacto refacto closed this as completed Sep 26, 2017
@junegunn
Copy link
Owner

junegunn commented Sep 26, 2017

Setting $FZF_DEFAULT_COMMAND is not required. As noted in #510, fzf launches the default find command when the variable is not defined and it should work just fine. Also, recent versions of fzf print [ERROR] on the screen when the command has failed.

  0/0 [ERROR]
>

Did you notice the message?

@refacto
Copy link
Author

refacto commented Sep 26, 2017

There was no message, just this:

  0/0
>

It still happens when I unset $FZF_DEFAULT_COMMAND
Regarding how new my fzf version is, it's: 0.17.0 (e89eebb)

@junegunn
Copy link
Owner

That's strange, the following is the default command fzf uses, can you check if it works on your machine?

command find -L . -mindepth 1 \( -path '*/\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \) -prune -o -type f -print -o -type l -print 2> /dev/null | cut -b3-

@refacto
Copy link
Author

refacto commented Sep 26, 2017

Nope, doesn't work, I assume. It outputs nothing, but returns 0.

@junegunn
Copy link
Owner

Okay thanks, I see. Looks like | cut -b3- at the end overrides the exit status of the find command (because pipefail is not set by default). I'll see what I can do about it.

Anyway, do you have any idea why that find command doesn't work on your system?

@refacto
Copy link
Author

refacto commented Sep 27, 2017

Yup. When I truncate the command a bit, I get this:

find: unrecognized: -fstype

My find is from BusyBox, might explain the missing options.

@junegunn
Copy link
Owner

I see, thanks for the investigation. Maybe I could change the default command to retry with simpler command on failure. i.e. find -foo -bar -baz || find -foo

@junegunn
Copy link
Owner

I'm thinking about changing the default command as follows

diff --git a/src/constants.go b/src/constants.go
index cfd3a3b..c3a3dd2 100644
--- a/src/constants.go
+++ b/src/constants.go
@@ -55,7 +55,7 @@ var defaultCommand string
 
 func init() {
 	if !util.IsWindows() {
-		defaultCommand = `command find -L . -mindepth 1 \( -path '*/\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \) -prune -o -type f -print -o -type l -print 2> /dev/null | cut -b3-`
+		defaultCommand = `bash -c "set -o pipefail; (command find -L . -mindepth 1 \( -path '*/\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \) -prune -o -type f -print -o -type l -print || command find -L . -mindepth 1 -path '*/\.*' -prune -o -type f -print -o -type l -print) 2> /dev/null | cut -b3-"`
 	} else if os.Getenv("TERM") == "cygwin" {
 		defaultCommand = `sh -c "command find -L . -mindepth 1 -path '*/\.*' -prune -o -type f -print -o -type l -print 2> /dev/null | cut -b3-"`
 	} else {

@refacto
Copy link
Author

refacto commented Sep 28, 2017

This works for me.

junegunn added a commit that referenced this issue Sep 28, 2017
- Use bash for `set -o pipefail`
- Fall back to simpler find command when the original command failed

Related: #1061
junegunn added a commit that referenced this issue Nov 30, 2017
In #1061 we changed the default command to retry with a simpler find
command with fewer arguments if the first find command failed. This was
to support stripped-down verions of find that do not support -fstype
argument.

However, this caused an unwanted side-effect of yielding duplicate
entries when the first command failed after producing some lines.

We revert the change in this commit, so the default command will not
work with find without -fstype support. But we now print better error
message in that case so that the user can set up a working
$FZF_DEFAULT_COMMAND.

Close #1120 #1167
@igbanam
Copy link

igbanam commented Jun 28, 2019

I ran into this error some hours ago.

I'm in Termux also, with oh-my-termux (a ZSH flavour) installed.

I see 8eab611 reverts the change to use a simpler find. Is there a default command we should be using here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants