-
-
Notifications
You must be signed in to change notification settings - Fork 824
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
More ways to anchor patterns #1476
Comments
For a workaround on the current version of tavianator@graphene $ touch '\*?[]'
tavianator@graphene $ fd -g "$(echo '\*?[]' | sed 's/\([][\\*?]\)/\\\1/g')"
\*?[]
tavianator@graphene $ find -name "$(echo '\*?[]' | sed 's/\([][\\*?]\)/\\\1/g')"
./\*?[] You could make a shell function for it: globesc() {
printf '%s' "$1" | sed 's/\([][\\*?]\)/\\\1/g'
}
fd -g "$(globesc '\*?[]')" |
I would not be terribly opposed to a new flag like |
So --anchored would have an effect on regex patterns and on fixed-string patterns, but not on glob patterns (because they are anchored already)? Or would we introduce this as an option instead of a flag ( |
I've started prototyping, here's the help output:
(I refrained from making it as general as possible: no word-start / word-end / additive ArgAction::Append flags that are unlikely to be used. But because I had it in mind, I prefer --no-anchor to an --anchor=none that would not be additive) |
globset would need to be patched, however, as anchoring is always done inside Token::to_regex_with with no builder customisation. But since globs are written by hand and still easy to script if needed, having --anchor conflict with --glob works for me. |
I would like to use fixed-string patterns to match against a whole basename (something like find -name while disabling fnmatch or quoting metacharacters).
Right now, glob patterns are anchored to match the entire input (as determined by --full-path), and regex patterns aren't, and by adding * or ^$ it's easy to tweak them to get the desired anchoring. But with fixed-string patterns, there's no easy way to turn them into regexes or globs from a shell pipeline (one needs to call regex::escape with a matching crate version) to have patterns match start/end/whole input.
The text was updated successfully, but these errors were encountered: