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

Add --glob/-g option for glob-based search #284

Closed
sharkdp opened this issue Apr 19, 2018 · 4 comments
Closed

Add --glob/-g option for glob-based search #284

sharkdp opened this issue Apr 19, 2018 · 4 comments

Comments

@sharkdp
Copy link
Owner

sharkdp commented Apr 19, 2018

A glob-based search (in addition to the default regex-based search) has been requested a few times (see #97, #157). I think we should consider to add this.

A few things to consider are:

  • Smart case, --case-sensitive and --ignore-case should work as expected
  • Interplay with other command line options has to be reviewed (--fixed-strings, --full-path, --extension)

Implementation-wise, we would probably just create a regex from the glob-pattern (glob syntax: https://docs.rs/globset/0.3.0/globset/#syntax). Also, we should enable "dot-all", just like in #111. Note that there is a (possible outdated) implementation here: #96. If nothing else, we should definitely looks at the extensive tests.

Note: a --regex option could be an optional extension to override --glob (if someone wants to alias fd="fd --glob", for example).

@kugel-
Copy link

kugel- commented Jul 5, 2019

Just discovered fd, after years of find. While I found it great initially, when I discovered that globbing isn't supported that was the first "meh" moment.

For the implementation...wouldn't it be easier to tread it more like a fixed string but call fnmatch(3) on the filenames instead of plain string comparison (I know Rust too little to tell)? fnmatch(3) is the standard function that bash and find use for globbing.

@tmccombs
Copy link
Collaborator

tmccombs commented Jul 5, 2019

Pedantic, but I doubt bash uses fnmatch for globbing, since it supports richer matching than fnmatch supports.

@sharkdp
Copy link
Owner Author

sharkdp commented Jul 7, 2019

For the implementation...wouldn't it be easier to tread it more like a fixed string but call fnmatch(3) on the filenames instead of plain string comparison (I know Rust too little to tell)? fnmatch(3) is the standard function that bash and find use for globbing.

The implementation I suggested is probably the easiest one, given how fd currently works. It has a potential downside performance-wise because the matching would be regex-based. But the Rust regex library is extremely fast.

I would guess that the glob-matching semantics are the same, so I would hope that there is no drawback in choosing the "globs via regexes" route.

@sharkdp
Copy link
Owner Author

sharkdp commented Sep 15, 2019

Released in v7.4.0.

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

No branches or pull requests

3 participants