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

Feature request: limit the number of find result #476

Closed
netjune opened this issue Sep 13, 2019 · 12 comments · Fixed by #555
Closed

Feature request: limit the number of find result #476

netjune opened this issue Sep 13, 2019 · 12 comments · Fixed by #555
Labels

Comments

@netjune
Copy link

netjune commented Sep 13, 2019

When used with emacs helm, fd process is created after every char inputting. I want to limit the number of the find result, because the extra results have no use and just cost power.

If there are too many results (more than 100 for me), I will find again until the results are less than 30. This is my common use(99%).

@sharkdp
Copy link
Owner

sharkdp commented Sep 13, 2019

Would

fd … | head -n 30

work for you?

If you want colorized output, you can use

fd --color=always … | head -n 30

@sharkdp
Copy link
Owner

sharkdp commented Sep 13, 2019

see also my answer in #472.

@netjune
Copy link
Author

netjune commented Sep 14, 2019

Good idea. It works on macOS. But on windows, there is no 'head' command. I would have to install msys2 to use it.

@sharkdp
Copy link
Owner

sharkdp commented Sep 15, 2019

I'd like to close this in favor of #472 (even if this is slightly more general).

It's not very likely that we will implement a separate command-line option for this, given that there are reasonable alternatives.

@sharkdp sharkdp closed this as completed Sep 15, 2019
sharkdp added a commit that referenced this issue Apr 2, 2020
This new option can be used instead of piping to `head -n <count>` for
improved performance:

| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|:---|---:|---:|---:|---:|
| `fd --max-buffer-time=0 flow.yaml` | 153.9 ± 2.5 | 151.3 | 170.3 | 4.21 ± 5.86 |
| `fd --max-buffer-time=0 flow.yaml \| head -n 1` | 145.3 ± 17.4 | 111.0 | 180.2 | 3.98 ± 5.55 |
| `fd --max-results=1 flow.yaml` | 36.5 ± 50.8 | 7.2 | 145.7 | 1.00 |

Note: there is a large standard deviation on the last result due to the
non-deterministic file system traversal. With `--max-results`, we don't
have to traverse the whole filesystem tree, so it's all about luck.

closes #472
closes #476
sharkdp added a commit that referenced this issue Apr 2, 2020
This new option can be used instead of piping to `head -n <count>` for
improved performance:

| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|:---|---:|---:|---:|---:|
| `fd --max-buffer-time=0 flow.yaml` | 153.9 ± 2.5 | 151.3 | 170.3 | 4.21 ± 5.86 |
| `fd --max-buffer-time=0 flow.yaml \| head -n 1` | 145.3 ± 17.4 | 111.0 | 180.2 | 3.98 ± 5.55 |
| `fd --max-results=1 flow.yaml` | 36.5 ± 50.8 | 7.2 | 145.7 | 1.00 |

Note: there is a large standard deviation on the last result due to the
non-deterministic file system traversal. With `--max-results`, we don't
have to traverse the whole filesystem tree, so it's all about luck.

closes #472
closes #476
@sharkdp sharkdp reopened this Apr 2, 2020
@sharkdp
Copy link
Owner

sharkdp commented Apr 2, 2020

This has actually been implemented as --max-results=<count> in #555

@sharkdp sharkdp closed this as completed Apr 2, 2020
@netjune
Copy link
Author

netjune commented Apr 5, 2020

Thanks.

@murlakatamenka
Copy link

@sharkdp great news, thanks for implementing this feature! 👍

What do you think about making it a one-line option -n <count> with obvious references to head / tail commands? It's associated with lines and numbers quite commonly, including bat, hexyl, ripgrep, cat etc.

@sharkdp
Copy link
Owner

sharkdp commented Apr 6, 2020

@sharkdp great news, thanks for implementing this feature! +1

thank you for the feedback.

What do you think about making it a one-line option -n <count> with obvious references to head / tail commands? It's associated with lines and numbers quite commonly, including bat, hexyl, ripgrep, cat etc.

I'd rather not, at least not right away. Let's see how this feature develops for some time. What is your most common use case of --max-results? Limiting to just one result? In this case we could also think about adding -1 as an alias for --max-results=1.

@murlakatamenka
Copy link

What is your most common use case of --max-results? Limiting to just one result?

Indeed it's quite often just a single file. I use such fd command to pick a random file of specific extension from a root media directory (wallpapers or audio library) with subdirectories. In zsh corresponding glob is **.png(.Y1), where ** allows recursing, Y1 means yield 1, . means it must be a file.

In this case we could also think about adding -1 as an alias for --max-results=1.

That's a really good idea!

@sharkdp
Copy link
Owner

sharkdp commented Apr 8, 2020

see #561

@sharkdp
Copy link
Owner

sharkdp commented Apr 16, 2020

This has now been released in fd v8.0.

@murlakatamenka
Copy link

Thanks! It's already in Arch repos and of course works:

image

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

Successfully merging a pull request may close this issue.

3 participants