-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Expand glob paths on Windows #234
Comments
What do other command line tools like |
But all native Windows tools I know do the expansion themselves, at least if it makes sense to expand. |
Usually you just use FindFirstFile/FindNextFile for this. |
sigh Indeed, it looks like globbing is done as part of the command line program: https://cygwin.com/ml/cygwin/2009-12/msg01097.html Other instances of the same problem:
I think what this means is that I need to add a glob iterator to |
The other other alternative is to use the standard Windows APIs for this. It seems like the kinds of globs it supports are not as nice as Unix-style globbing, but perhaps that's what Windows users expect, so it could be defensible to use that. I don't anticipate working on this soon unfortunately. |
I thinks using the Windows API is better than nothing and probably easier to implement. |
@troplin Thanks! If you do, I would hope to see the Windows logic put behind a separate crate. :-) (Which could live inside ripgrep, or could be yours to maintain.) |
Question: should ripgrep support Unix-style globbing here, or should it use the standard |
Do the windows APIs support anything besides This doesn't affect vscode scenarios, but as a CLI user, I'd prefer more powerful patterns. |
How about Basically there is already such behavior separation between ripgrep and shell globbing on Linux. And Windows CLI is just an "inferior shell" one might argue. So it would be natural for (emulated) "shell globbing" to work in the shell native way. |
FYI: Current -g switch in RipGrep seems to work fine with ?, *, [class] It does NOT work without the -g (which is as designed but a bit unexpected for a Windows only user.) Worth putting out a Windows specific warning when the last thing on the line is *.txt or similar and nothing to search, instead of the current warning:
Maybe add,
|
+1 for @HerbM's suggestion about mentioning the I've hit this issue before, but due to being in the middle of something, I've just moved over to searching in vscode instead of using RipGrep. I'm guessing that plenty of other Windows users have hit the same issue. Updating the error message would resolve this and make it immediately obvious how to do what the user was trying to do. ps. Awesome tool btw! This is the only issue I've hit - other than that, it's amazing! Thanks for the great work! |
@dracan Thanks for the feedback! Funny note though: VS Code's search uses ripgrep. :) |
Definite +1 for yelling at the operator about -g, at the very least. Counterpoint though:
Functions as one would expect with glob-expansion ... as does I know windows path expansions is a pain in the behind, but there's a case to be made for functional parity when even |
Folks, +1 comments are not all that useful. Instead of basically just saying "me too", it would help if Windows users could answer questions I've asked. For example: #234 (comment) |
So I suppose you didn't like my proposal from #234 (comment) ? |
I have two answers to my question do far. Both of them are different. Yours is one of them. More input from others would be great. In particular, I would love to hear how existing cli utilities work. Do they use standard unix globbing? Or shell native globbing? And more importantly, do users actually like that? |
I believe most utilities use IMO "consistency" is more important than "liking". So I would vote for using shell native globbing with |
That would be an acceptable minimum but I would strongly prefer unix parity here so that tools that rely on ripgrep don't need to split code paths for windows. |
As a Windows user, IMO just
I'd argue for globbing in all elements of the path, not just on the leaf element, and supporting Unix style globbing is powerful, and might be a bit more consistent cross-platform, but (a) you'd have to add an escaping mechanism (see above) and (b) not all Unix shells use the exactly same globbing syntax, so it's still not entirely portable. I dont think it's worth it, personally. |
@pfmoore Thanks for the feedback! I think the two choices here are "support Windows-style globbing using the corresponding winapi calls" or "support Unix-style globbing." I don't think I'm willing to do some inbetween state. Also, note that ripgrep already supports Unix-style globbing on Windows with the |
I have filed issue #1667 after browsing open issues which brought me here. IMHO the best option would be for ripgrep to behave
So, this is no inbetween state - it is just checking for the type of environment (shell) and behaving accordingly. There's no RUST for OS/2, but there we have the same situation, the normal OS/2 CMD (or 4OS2) and a UNIX-like environment with Dash (instead of Bash). |
I believe ripgrep should not reimplement Unix globbing by default because it creates an incorrect expectation that a responsibility of the shell should be the responsibility of individual programs, demanding everyone repeat the work that the shell is very well capable of doing itself. |
That's a fair point, but if end users are hitting this problem in a popular shell and there is no work-around for them, then it makes sense to me for ripgrep to expand the globs. AIUI, this is standard for Windows CLI tools? Although I'm not 100% sure on that. It might also help here to enumerate the shells that fail to expand globs. Is it just |
Powershell leaves it to the program as well. It’s the standard on windows that globbing is done by the individual program - in fact, the C runtime glob-expands argv automatically, so programs written in C get this behaviour without needing any explicit code for it. |
Is the argv globbing behavior exposed as a user function to call, at least? It's slightly disappointing to hear PowerShell is afflicted with this. Globbing may start with a string, yes, but morally it expands to generate a list, the kind of nicely-structured data PowerShell likes. e.g. note this deviation between "classic" shell globbing and POSIX-compliant globbing:
|
@workingjubilee AIUI, you're supposed to use
Is this documented anywhere? |
The thing is, it's not a matter of being "afflicted". It's a design choice - not all arguments are filenames, so why should the shell arbitrarily choose to treat them as such? But regardless of philosophy, it is a reality that Windows shells don't glob arguments, and it's extremely clumsy (probably impossible if you use
I found this. I'm surprised it says it's not the default - maybe MSVC links that in by default and that document is about the C runtime not the compiler. Or maybe my memory is faulty, and it always needed the extra object file linking in. it's been quite a long while since I programmed in C in earnest. But all of that's very much for C, I don't know how or if it would relate to Rust. |
Choose one! |
Personally, I choose having the application do the globbing on operating systems where that's the norm... |
Please go open an issue in the thousands of other application repos where this problem will remain unsolved by addressing it here, then. |
Can we stop this tit-for-tat? This issue tracker is for ripgrep. I appreciate the argument that it would be better if this were solved in shell, but that is not a trump card IMO. It's just one consideration of many. This issue is open because I generally think this is worth fixing on ripgrep's side, but I also simultaneously am not currently prioritizing it. |
Sorry, you're right. |
On Windows, glob expansion is not done by the shell (cmd.exe), but left to the individual program.
That means, that currently something like this doesn't work:
It tries to open a file called
*.txt
, which obviously doesn't exist.The text was updated successfully, but these errors were encountered: