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

Detect when user supplied path instead of pattern #235

Closed
sharkdp opened this issue Feb 12, 2018 · 2 comments
Closed

Detect when user supplied path instead of pattern #235

sharkdp opened this issue Feb 12, 2018 · 2 comments

Comments

@sharkdp
Copy link
Owner

sharkdp commented Feb 12, 2018

From time to time it happens to me that I forget to supply a regex-pattern when using an explicit search path. In particular, this happens when I use --extension EXT/-e EXT because it feels like EXT is a pattern by itself:

> fd -e jpg /share/pictures    # this will not do what you expect

The right way would be to use fd -e jpg . /share/pictures or fd -e jpg "" /share/pictures.

Instead, what the command above will try to do is to search for files in the current directory that match the regular expression /share/pictures (there will be none). I was wondering whether we could detect such cases and warn the user.

A possible implementation could look like this:

If all of the following conditions are fulfilled:

  • only a single argument is given (which fd normally interprets as a search pattern)
  • the pattern contains a path-separation character (/ or \)
  • (the pattern is an existing path in the filesystem)
  • --full-path/-p has not been enabled (otherwise, we could potentially find entries that match the pattern)

... print a warning:

The search pattern "/share/pictures" looks like a path. If you want to specify a
root directory, use an empty search pattern: `fd [options] "" /share/pictures`.
@sharkdp
Copy link
Owner Author

sharkdp commented Feb 25, 2018

In addition, we could also suggest --full-path/-p if somebody really wants to search for a part of a path.

@sharkdp
Copy link
Owner Author

sharkdp commented Mar 26, 2018

Released as part of fd v7.0.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

1 participant