junegunn / fzf

:cherry_blossom: A command-line fuzzy finder
https://junegunn.github.io/fzf/
MIT License
63.4k stars 2.36k forks source link

[Bug] Can't use `fzf` non-interactively: the option `-f` doesn't work as expected. #3727

Closed anasouardini closed 4 months ago

anasouardini commented 4 months ago

Checklist

Output of fzf --version

0.38.0 (debian)

OS

Shell

Problem / Steps to reproduce

I want to use fzf in a non-interactive mode, and from the man page it seems like the options -f and +s are going to make fzf act like grep which what I want, but when I use those options, fzf just exits.

My goal is to select one option even if the query is still vague (doesn't filter down to only one option). If I'm not mistaken this command should work just find: fzf -1 -0 -f +s --query="r"

I suspect the option -f to be causing the issue:

image

junegunn commented 4 months ago
    -q, --query=STR        Start the finder with the given query
    -f, --filter=STR       Filter mode. Do not start interactive finder.

--filter (or -f) should be followed by a query string. In -f +s case, +s is recognized as the query string. i.e. equivalent to --filter=+s. So you should remove --query and do fzf -1 -0 +s --filter="r" or fzf -1 -0 -f "r" +s fzf +s --filter="r" or fzf -f "r" +s instead.

junegunn commented 4 months ago

I missed to mention that -1 and -0 are not compatible with --filter but with --query.

       -1, --select-1
              If there is only one match for the initial query (--query), do not start interactive finder and automatically select the only match

       -0, --exit-0
              If there is no match for the initial query (--query), do not start interactive finder and exit immediately

So you should try something like fzf -f "r" +s | head -1 instead.

junegunn commented 4 months ago

Hmm, I just realized there is a critical bug in the streaming filter mode (i.e. --no-sort --filter=something) since fzf 0.47.0.

https://github.com/junegunn/fzf/issues/3728

anasouardini commented 4 months ago

Thank you, that satisfies my question.