Fzf: Print Query if there is no match

Created on 22 Sep 2019  路  3Comments  路  Source: junegunn/fzf

  • Category

    • [x] fzf binary

    • [ ] fzf-tmux script

    • [ ] Key bindings

    • [ ] Completion

    • [ ] Vim

    • [ ] Neovim

    • [ ] Etc.

  • OS

    • [x] Linux

    • [ ] Mac OS X

    • [ ] Windows

    • [ ] Windows Subsystem for Linux

    • [ ] Etc.

  • Shell

    • [x] bash

    • [x] zsh

    • [ ] fish

Is it possible to make fzf automatically print the query, only if there is no match found. This is the behaviour of other fuzzy finders such as dmenu and rofi.

Thanks for creating this tool!

question

Most helpful comment

--bind=enter:replace-query+print-query makes fzf behave like dmenu. You may find it useful as an alternative to --print-query + tail -1 compatible with --print0. You probably don't want it as the default though since it breaks multi-select and the Vim function.

All 3 comments

automatically print the query, only if there is no match found

Then it's not clear if the printed line is the query or the selection, and we would need to define an arbitrary exit status for that specific case. A simpler way would be to use --print-query option and use shell script to check the number of output lines.

$ echo 1 | fzf --print-query -0 -1 | wc -l
       2
$ : | fzf --print-query -0 -1 | wc -l
       1

@junegunn
when you don't care about if the selection came from a list or was typed manually (for example a launcher that most of the time selects from a list but sometimes you want to type the whole command with env variables and arguments) you can use

[list] | fzf --print-query | tail -1 | xargs -r ...

there doesn't appear to be such a simple solution to the problem if you use --print0 however, have to resort to actual scripts.

is there a way to make fzf abstain from printing an empty line?

--bind=enter:replace-query+print-query makes fzf behave like dmenu. You may find it useful as an alternative to --print-query + tail -1 compatible with --print0. You probably don't want it as the default though since it breaks multi-select and the Vim function.

Was this page helpful?
0 / 5 - 0 ratings