-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
stdin is not searched if it is a directory #2906
Comments
if this is too niche to spend your time fixing, i am a rust developer and would be willing to fix this. |
I don't understand the use case. You mention quick wrapper scripts, but I don't really get it. I write lots of wrapper scripts, and it's easy to forward arguments from the wrapper script to a command run by that wrapper script. You don't mention the expected behavior here. I guess you're expecting ripgrep to search it as if it were just a directory provided as an argument? Do other Unix commands do this? I've never seen this usage pattern before. The way ripgrep works is that it looks for something resembling a file on stdin to search. And if it can't find a file (which it can't in this case), it searches the current working directory. This is actually a heuristic and this heuristic has caused lots of problems because it's common for things to pass something that looks like a file on stdin even when it's not really intended. So I'm very hesitant to change that heuristic. And your suggesting here would add a third case to that heuristic. I think at best the docs can be improved. The man page already mentions this behavior, although I suppose it could be slightly more precise to cover this case. But I'm not even sure this is worth doing because this seems so idiosyncratic to me. Maybe you can elaborate more.
Note that it's not just the initial effort here. It's also the ongoing maintenance burden that stuff like this adds. Especially to what is already a finicky heuristic. |
yes, unless all those arguments are already used for something (eg. constructing the regex to search with)
yes, that's what "recurses into" means
unix commands don't typically change behavior based on the type of stdin. they sometime do for stdout, but usually just for terminal colors or automatically invoking a pager. usually they just crash if any stdio is a directory, not silently ignore it.
I was under the impression it just checked if stdin was a pty, and if not, treats it like it was passed as an argument. |
Ah sorry I missed this.
ripgrep isn't without precedent here, but yes, one of the downsides of messing around with stdin like this is that there are indeed some cases where ripgrep will ignore what's on stdin and search the current working directory. This is why in ripgrep 14, I introduced some logging messages (that appear when you pass
No, it's more complicated than that. Whether it's a pty or not is a minimum criteria: Lines 170 to 250 in bf63fe8
I've pushed a wording change to the man page to cover this case. |
Please tick this box to confirm you have reviewed the above.
What version of ripgrep are you using?
ripgrep 13.0.0
-SIMD -AVX (compiled)
+SIMD -AVX (runtime)
How did you install ripgrep?
nix-inst ripgrep
https://codeberg.org/binarycat/nix-inst
What operating system are you using ripgrep on?
NixOS 24.05 (Uakari)
Describe your bug.
if stdin is a directory, ripgrep acts like it is a terminal
What are the steps to reproduce the behavior?
rg a < some_dir
What is the actual behavior?
if stdin is a directory, ripgrep acts like it is a terminal
What is the expected behavior?
ripgrep recurses into stdin
yes this is kinda a weird request, but it's useful for quick scripts that wrap rg, with no way to pass file arguments to rg.
filing this as a bug because although i can't find any docs that say "ripgrep searches stdin unless it is a terminal", they probably should exist.
The text was updated successfully, but these errors were encountered: