Comments (8)
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.
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.
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.
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.
Okay, I'm glad you like it, thanks!
from fzf.
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.
👍
from fzf.
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)
- eval fzf --bash completion arguments result in "invalid option name" HOT 3
- When sending reload(...) + preview(...) during the same event, the preview is reset HOT 1
- [Bug] Can't use `fzf` non-interactively: the option `-f` doesn't work as expected. HOT 4
- Streaming filter mode crashes
- fzf-tmux fails if fzf is an aliased HOT 6
- v0.50.0 not showing process data correctly HOT 10
- [Feature Request] Customizable shell command flag for command execution HOT 2
- [Feature Request] Integrate fzf into Gnome Search
- FZF to search in winget store and it closes previous fzf window
- Respect $FZF_DEFAULT_OPTS_FILE in key bindings and completion
- How fzf operate with stdin/stdout/stderr/tty/pipe? HOT 1
- Fzf cannot find a function configured as FZF_ALT_C_COMMAND HOT 5
- Incorrect command-line options in shell key-bindings scripts (--scheme=history and --bash) HOT 2
- TestOSExitNotAllowed fails when `go test` is passed `-trimpath` HOT 17
- Bind option doesnt work always HOT 1
- The prompt appears slowly HOT 2
- Not searching recursively HOT 5
- [Feature Request] add `toggle+to+top` and `toggle+to+bottom` actions HOT 2
- [question] Action to toggle multi selection HOT 6
- fish shell: CTRL_T not starting fzf from specified file path HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fzf.