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

Expand glob paths on Windows #234

Open
troplin opened this Issue Nov 13, 2016 · 11 comments

Comments

Projects
None yet
5 participants
@troplin
Copy link

troplin commented Nov 13, 2016

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:

>rg PATTERN *.txt
*.txt: The filename, directory name, or volume label syntax is incorrect. (os error 123)
No files were searched, which means ripgrep probably applied a filter you didn't expect. Try running again with --debug.

It tries to open a file called *.txt, which obviously doesn't exist.

@BurntSushi

This comment has been minimized.

Copy link
Owner

BurntSushi commented Nov 13, 2016

What do other command line tools like grep do?

@BurntSushi BurntSushi added the question label Nov 13, 2016

@troplin

This comment has been minimized.

Copy link
Author

troplin commented Nov 13, 2016

grep does work as expected for me.
I installed it with cygwin though, so I'm not sure if this is a cygwin or grep feature.

But all native Windows tools I know do the expansion themselves, at least if it makes sense to expand.

@troplin

This comment has been minimized.

Copy link
Author

troplin commented Nov 13, 2016

Usually you just use FindFirstFile/FindNextFile for this.
Not sure if it uses the exact same rules as unix glob.

@BurntSushi

This comment has been minimized.

Copy link
Owner

BurntSushi commented Nov 13, 2016

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 globset. Alternatively, we could use the existing iterator in the glob crate, but it doesn't support {a,b} syntax and gets some non-UTF-8 corner cases wrong.

@BurntSushi

This comment has been minimized.

Copy link
Owner

BurntSushi commented Mar 13, 2017

I think what this means is that I need to add a glob iterator to globset. Alternatively, we could use the existing iterator in the glob crate, but it doesn't support {a,b} syntax and gets some non-UTF-8 corner cases wrong.

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.

@BurntSushi BurntSushi added the icebox label Mar 13, 2017

@troplin

This comment has been minimized.

Copy link
Author

troplin commented Mar 14, 2017

I thinks using the Windows API is better than nothing and probably easier to implement.
I might give it a try if I find the time.

@BurntSushi

This comment has been minimized.

Copy link
Owner

BurntSushi commented Mar 14, 2017

@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.)

@BurntSushi

This comment has been minimized.

Copy link
Owner

BurntSushi commented Feb 2, 2018

Question: should ripgrep support Unix-style globbing here, or should it use the standard FindFirstFile/FindNextFile APIs, presumably to be consistent with other Windows CLI tools?

cc @retep998 @roblourens

@roblourens

This comment has been minimized.

Copy link
Contributor

roblourens commented Feb 2, 2018

Do the windows APIs support anything besides * and ?? It's not clear.

This doesn't affect vscode scenarios, but as a CLI user, I'd prefer more powerful patterns.

@sabi0

This comment has been minimized.

Copy link

sabi0 commented Sep 26, 2018

How about -g <GLOB> using Unix-style globs (as it does already) and just <GLOB> falling back to Windows API?

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.

@HerbM

This comment has been minimized.

Copy link

HerbM commented Oct 28, 2018

FYI:
cmd.exe does NOT support anything but * and ? (specifically NOT [a-z] character classes).
PowerShell does support the character classes as part of "wildcards" (what it calls Globbing.

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:

*.txt: The filename, directory name, or volume label syntax is incorrect. (os error 123)

Maybe add,

use '-g FilePattern' for globbing (wildcard file patterns)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.