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

weird behavior of exclude #1264

Closed
unusualevent opened this issue Feb 26, 2023 · 3 comments
Closed

weird behavior of exclude #1264

unusualevent opened this issue Feb 26, 2023 · 3 comments
Labels

Comments

@unusualevent
Copy link

fd 8.3.1

okay, so, if I have a folder with a bunch of predictable notes, logically I'd use "exclude", right?

this is slightly unrelated and more nuanced than #865 which deals with how the library in burntsushi parses excludes, which, okay it's buggy.

let's start where fd does work:

fd '([0-9]{2})-([0-9]{2})-([0-9]{2}).md' path/to/folder finds the predictable ones I don't want, works correctly.

remember, the goal here is to get things in that folder that don't match. let's explore it!

fd -E '([0-9]{2})-([0-9]{2})-([0-9]{2}).md' path/to/folder complains about path/to/folder because it thinks it's a search pattern (this is the logical way to run this search, according to your readme)

fd -E '([0-9]{2})-([0-9]{2})-([0-9]{2}).md' . path/to/folder lists all files (because it takes the dot as a pattern) (an attempted fix based off what your error message suggests for the "find all" pattern, which means that exclude is a recessive trait compared to the dominant "find all", such that mixing excludes and patterns is probably undefined behavior, and the error message should just tell you to not do it)

(yes, I tried it both ways, hoping this was a weird order of operations problem that you'll see further down) fd . -E '([0-9]{2})-([0-9]{2})-([0-9]{2}).md' path/to/folder

FYI, the non-exclude case (fd '([0-9]{2})-([0-9]{2})-([0-9]{2}).md' . path/to/folder) isn't much better, it searches both . (e.g., PWD/CWD) and path/to/folder (treats . as a folder) - which has to do with it suddenly thinking . is a path and not a pattern, because I already provided a first one - which kinda tells me that the "you should use the . pattern" guidance in that error message is flawed in more cases than expected

the search would proceed as expected if I moved the current directory to the location I specified in the path option

which begs two questions:
A) why doesn't fd just change CWD to resolve this buggy exclude behavior
B) why did I make this issue offering you the chance to improve this software instead of moving into the directory myself in the script

@unusualevent
Copy link
Author

now that I look at it, even /in/ that directory fd -E doesn't work, maybe my regex is just bad?

though fd in normal mode works fine.

# incorrect (matching everything):
 ❯ fd -E '([0-9]{2})-([0-9]{2})-([0-9]{2}).md' 
2023-02-26.md
2023-02-27.md
hello.md

# correct, only showing matches:
 ❯ fd '([0-9]{2})-([0-9]{2})-([0-9]{2}).md' 
2023-02-26.md
2023-02-27.md

@neingeist
Copy link

Apparently, -E takes glob patterns, not a regexen.

@tmccombs
Copy link
Collaborator

Yeah, so -E uses gitigbore syntax. It is effectively the same as putting that pattern in a .ignore file, but on the command line.

I think this is really a duplicate of #198, and will close as such. Let me know if you think it should stay open for some reason

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

No branches or pull requests

3 participants