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

Optionally allow pattern elision #312

Closed
studoot opened this issue Jul 23, 2018 · 5 comments
Closed

Optionally allow pattern elision #312

studoot opened this issue Jul 23, 2018 · 5 comments

Comments

@studoot
Copy link

studoot commented Jul 23, 2018

This is related to #235 - maybe it's just me, but I search for files by just their extension often enough that when I see the warning below, I wish yet again that fd could fill in the match-all pattern for me...

Error: The search pattern '/mnt/e/code/vcpkg/' contains a path-separation character ('/') and will not lead to any search results.

If you want to search for all files inside the '/mnt/e/code/vcpkg/' directory, use a match-all pattern:

  fd . '/mnt/e/code/vcpkg/'

Instead, if you want to search for the pattern in the full path, use:

  fd --full-path '/mnt/e/code/vcpkg/'

Having an option to enable this feels beneficial (if only to me, I guess!). Maybe only in the case that a filtering option (such as -e or -t) has also been used?

@sharkdp
Copy link
Owner

sharkdp commented Jul 23, 2018

Interesting idea. I have to admit that I also see this error from time to time 😄.

What I definitely want to avoid is any sort of ambiguity (or confusion on the user side). I think it would be quite unfortunate that the following two commands would do completely different things:

fd -e txt docs/  # Search for "*.txt" in the "docs" folder
fd -e txt docs   # Search current directory for entries matching "docs" and "*.txt"

@studoot
Copy link
Author

studoot commented Jul 23, 2018

I think having the directory separator in the pattern/path disambiguates sufficiently (and is consistent with some things in Linux - think of ‘ls -l’ of a directory symlink with/without a trailing slash.

I was thinking of a flag to indicate that if the error situation was seen, to tell fd which option (if either) to use. Then an ‘fd’ alias could be defined with that option set. Say ‘--pattern-or-path=(path|pattern|none)’?

@sharkdp
Copy link
Owner

sharkdp commented Jul 30, 2018

I think having the directory separator in the pattern/path disambiguates sufficiently (and is consistent with some things in Linux - think of ‘ls -l’ of a directory symlink with/without a trailing slash.

Ok, but ls -l always expects a PATH argument. For fd, we would change the semantics of the argument from PATH to PATTERN. I can definitely see how that could be very confusing.

I was thinking of a flag to indicate that if the error situation was seen, to tell fd which option (if either) to use. Then an ‘fd’ alias could be defined with that option set. Say ‘--pattern-or-path=(path|pattern|none)’?

I'd like to avoid "bloat" when it comes to command line options (longer --help output, additional tests due to more possible command line combinations, etc), so I always hesitate when new command line options are suggested. This one in particular does not feel very natural to me. One option could be a more general --path-before-pattern command-line flag (maybe someone has an idea for a better name), which would change fd's usage from

fd [FLAGS/OPTIONS] [<pattern>] [<path>...]

to

fd [FLAGS/OPTIONS] [<path>] [<pattern>]

or possibly even

fd [FLAGS/OPTIONS] [<path>] [<pattern>...]

which would have other benefits as well.

@sharkdp
Copy link
Owner

sharkdp commented Aug 19, 2018

This is related to both #315 and #277.

@sharkdp
Copy link
Owner

sharkdp commented Oct 27, 2018

The --path-before-pattern doesn't feel very natural for me. I'm going to close this as "won't fix" for now. If someone comes with a better idea, I'm happy to reconsider this.

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

No branches or pull requests

2 participants