Code Monkey home page Code Monkey logo

Comments (8)

junegunn avatar junegunn commented on May 22, 2024 1

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

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.

from fzf.

wellle avatar wellle commented on May 22, 2024 1

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!

from fzf.

junegunn avatar junegunn commented on May 22, 2024

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 hello, then after 1 second, it will match world as well.
It's possible to defer selecting the only match until fzf completely consumed the source, but during the period the user can type in more characters, which I think can lead to some confusion.

Hmm, I might make fzf block only when the option is given. What do you think?

from fzf.

wellle avatar wellle commented on May 22, 2024

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.

from fzf.

junegunn avatar junegunn commented on May 22, 2024

Okay, I'm glad you like it, thanks!

from fzf.

junegunn avatar junegunn commented on May 22, 2024

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
}

from fzf.

wellle avatar wellle commented on May 22, 2024

👍

from fzf.

mragab avatar mragab commented on May 22, 2024

If all you need is to get the best match in a non-interactive way:

fzf --filter="$1" | head -n 1

from fzf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.