How to make fzf send text that has no match to standard output?

Viewed 341

I'm writing a script that opens a terminal and prompts the user to rename a file in fzf. Obviously, there is no match in fzf, so fzf sends an empty string, but I want it to send the string that I wrote. dmenu does this.

Example:

echo "yes\nno" | fzf would only allow either yes or no to be entered, otherwise it prints an empty string

echo "yes\nno" | dmenu Would allow anything to be be entered including yes or no

1 Answers

fzf can print query as the first line: --print-query. To achieve your need, you could try to fetch the last line for both match and no match case: echo "yes\nno" | fzf --print-query | tail -1

Related