-
-
Notifications
You must be signed in to change notification settings - Fork 825
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
Chained usage fd ... -X fd ... [-X]
-- examples welcome in README? deeper support for chaining?
#1450
Comments
I've rewritten this chained query in an extendable way (thought it suffers in keystroke cost): Would a word-match flag PR be welcome? Something like grep's
$ <<< ~/.local/lib/python3.10/ xargs fd ^brotab$ -td -1
/home/mcint/.local/lib/python3.10/site-packages/brotab/ Where other searches, with early termination, $ <<< ~/.local/lib/python3.10/ xargs fd brotab -td -1
/home/mcint/.local/lib/python3.10/site-packages/brotab-1.4.2.dist-info/ from this small set: $ <<< ~/.local/lib/python3.10/ xargs fd brotab -td
/home/mcint/.local/lib/python3.10/site-packages/brotab/
/home/mcint/.local/lib/python3.10/site-packages/brotab-1.4.2.dist-info/ |
$ fd foo
foo
foo/foo
foo/foo/foo
$ fd foo -X echo fd bar # To see what would be executed
fd bar ./foo ./foo/foo ./foo/foo/foo
$ fd foo -X fd bar # What would actually happen
./foo/bar
./foo/foo/bar
./foo/foo/foo/bar
./foo/foo/bar
./foo/foo/foo/bar
./foo/foo/foo/bar You could pass For your case, it's probably best to do all the filtering in the same $ fd -td --full-path 'brotab.*api.*\.py$' ~/.local/lib/python3.10/
You can write word boundaries in the regex like this: $ fd '\bpattern\b' I don't think we'd add a flag to do this for you, |
Hm, thank you, interesting suggestions. I will consider It looks like, in practice, I can use Sounds like no objections to submitting other use examples for the readme or docs, might PR later. Extraneous thinking aloud, about chaining queriesI've chewed on variations where I can keep appending [pattern] or [depth] [pattern] for a while. To build the motivation a bit more, I query things like this:
Compressed to: Here are some real snippets of recent history, or for tasks I perform commonly: fd -d4 ^php / -td | grep -ve -
fd -d4 ^php / -td | grep -ve - | xargs fd ini
fd -d4 ^php / -td | grep -ve - | xargs fd fpm sudo apt install fzf
fd completion / -d4
fd completion / -d4 -X fd fzf -d4
fd completion / -d4 -td -X fd fzf -d4
fd fzf / -d4 -td -X fd completion -d4
. /usr/share/doc/fzf/examples/completion.bash
less /usr/share/doc/fzf/examples/completion.bash
. /usr/share/doc/fzf/examples/key-bindings.bash Although, these examples each only use 2 steps. Nit about full-path matching
Thank you for a considered response, and I agree that blindly performing nested queries might blow up traversals & time required and results size. However, I must insist, full-path matching seems ill-advised, file systems have a really high branching factor, and searching them quickly and effortlessly (few keystrokes, forgiving argument order, concatentative/append-only use supported) is what makes From painful experience, I can report that searching chained from partial matches helps a lot on low-resource systems. Nested matching names are not entirely contrived, but requerying with a more limited depth, or now glob matching are what I'll try. Fiddling with the shell cursor to modify queries is also frustrating in practice. Thank you for your work maintaining -- answering random usage questions, and considering design space around the tool! |
One thing that may help concatenative use is $ fd --full-path --search-path ~/.local/lib/python3.10/ /brotab/ --and api -e py
Does it? I see how it could, but I expect I/O and syscall overhead to dominate pattern matching. Let's check: tavianator@tachyon $ hyperfine -w2 "fd -u brotab ~" "fd -u --full-path brotab ~"
Benchmark 1: fd -u brotab ~
Time (mean ± σ): 1.151 s ± 0.014 s [User: 18.505 s, System: 33.398 s]
Range (min … max): 1.134 s … 1.180 s 10 runs
Benchmark 2: fd -u --full-path brotab ~
Time (mean ± σ): 1.151 s ± 0.008 s [User: 20.426 s, System: 32.466 s]
Range (min … max): 1.142 s … 1.164 s 10 runs
Summary
fd -u --full-path brotab ~ ran
1.00 ± 0.01 times faster than fd -u brotab ~ And here's a more representative benchmark for your use case. I changed it up because I don't have any copies of tavianator@tachyon $ hyperfine "fd -u --search-path ~ --full-path /requests/ --and api -e py" "fd -u -td --prune --search-path ~ requests -X fd -u api -e py"
Benchmark 1: fd -u --search-path ~ --full-path /requests/ --and api -e py
Time (mean ± σ): 1.126 s ± 0.014 s [User: 14.427 s, System: 37.160 s]
Range (min … max): 1.110 s … 1.149 s 10 runs
Benchmark 2: fd -u -td --prune --search-path ~ requests -X fd -u api -e py
Time (mean ± σ): 1.156 s ± 0.012 s [User: 16.962 s, System: 35.575 s]
Range (min … max): 1.139 s … 1.181 s 10 runs
Summary
fd -u --search-path ~ --full-path /requests/ --and api -e py ran
1.03 ± 0.02 times faster than fd -u -td --prune --search-path ~ requests -X fd -u api -e py Both queries return the same set of 110 files.
First off, you may be interested in #28 and possibly https://github.com/tavianator/bfs :) Secondly, the total work is roughly the same for both approaches anyway. With one (Without
I'm kind of surprised that
True. One handy thing is most shells support Emacs-style keybindings for line editing, e.g.
You're welcome! :) |
Using
fd
version:fd 8.7.0
I find myself using fd in a chained manner.
-X
-chained invocation style.Chained-style
For example, for quickly viewing python packages, today I find myself searching for
fd brotab -td ~/.local/lib/python3.10/ -X fd api -e py
, since api is a common file and package name-component, and I'm just looking for the one today. I find myself wanting to run commands on the result, or chain a third (or more) times. I'm looking to document that pattern for other users of fd.The text was updated successfully, but these errors were encountered: