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

Print Query if there is no match #1693

Closed
4 of 15 tasks
Jab2870 opened this issue Sep 22, 2019 · 4 comments
Closed
4 of 15 tasks

Print Query if there is no match #1693

Jab2870 opened this issue Sep 22, 2019 · 4 comments
Labels

Comments

@Jab2870
Copy link

Jab2870 commented Sep 22, 2019

  • Category
    • fzf binary
    • fzf-tmux script
    • Key bindings
    • Completion
    • Vim
    • Neovim
    • Etc.
  • OS
    • Linux
    • Mac OS X
    • Windows
    • Windows Subsystem for Linux
    • Etc.
  • Shell
    • bash
    • 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!

@junegunn
Copy link
Owner

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

@ghost
Copy link

ghost commented Apr 6, 2020

@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?

@guidocella
Copy link

guidocella commented Sep 27, 2020

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

@Superty
Copy link

Superty commented Aug 11, 2023

Note that replace-query+print-query will truncate the selection if it is too long since there seems to be a limit on the size of the query.

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

No branches or pull requests

4 participants