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
Add flag to select single result immediately #27
Comments
I see. It could be useful. One fact that we have to consider is that fzf doesn't block user input while it's receiving lines from stdin. So for example, (echo hello; sleep 1; echo world) | fzf --query o fzf will first match Hmm, I might make fzf block only when the option is given. What do you think? |
That sounds very reasonable. I'm not sure if this makes matters worse, but you could stop blocking when you find the second match. Because at that point it's clear that it won't be the only match. Also typing more characters in between could just reset that option. But all of this is highly optional. In the use case I had in mind there aren't too many files, so blocking would be no issue there. |
Those are indeed good ideas. By the way, I have given some thought, and it seems like we can implement the feature with some shell scripting using fq1() {
local lines
lines=$(fzf --filter="$1" --no-sort)
if [ -n "$lines" -a $(wc -l <<< "$lines") -eq 1 ]; then
echo "$lines"
else
echo "$lines" | fzf --query="$1"
fi
} This is not as compact or easy as the suggested option, however I usually try to take the minimalist approach and tend to not add features that can be accomplished otherwise. So do you still feel this option should be implemented? I'm open to your opinion. |
Oh that's amazing! This is what I am using now: function fq1() {
local lines
lines=$(fzf --filter="$1" --no-sort)
if [ -n "$lines" -a $(wc -l <<< "$lines") -eq 1 ]; then
echo "$lines"
else
echo "$lines" | fzf --query="$1"
fi
}
function ze() {
FILE=$(fq1 $1) && vim "$FILE"
} I am pleased with this and agree that there is no need to bake it into fzf. You might want to mention that function in the Readme as I believe it's very useful. Thank you! |
Okay, I'm glad you like it, thanks! |
A slight improvement to the function: Exit when there's no match function fq1() {
local lines
lines=$(fzf --filter="$1" --no-sort)
if [ -z "$lines" ]; then
return 1
elif [ $(wc -l <<< "$lines") -eq 1 ]; then
echo "$lines"
else
echo "$lines" | fzf --query="$1"
fi
} |
👍 |
If all you need is to get the best match in a non-interactive way:
|
When providing a
--query=foo
parameter it could be useful to select the only match immediately when there is only one. When there are multiple matches the selection happens as usual.Could look like this:
This is related to #26.
The text was updated successfully, but these errors were encountered: