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

[Feature request] Grep style directory exclusion #8

Closed
bag-man opened this issue Feb 26, 2016 · 6 comments
Closed

[Feature request] Grep style directory exclusion #8

bag-man opened this issue Feb 26, 2016 · 6 comments

Comments

@bag-man
Copy link

bag-man commented Feb 26, 2016

I've been using bfs for a while now, it is excellent. One thing that find is terrible for is excluding directories, and I thought maybe bfs could add on a more use friendly system.

It would be a lot nicer if there was the option to exclude/include directories/files in the same way that grep does:

--exclude-dir={build,vendor,.git,node_modules} --include=*.{css,vcl,conf,yml,jade,js,styl,php,config,html} --exclude={*.min.js,tags,json}

I'd be quite interested in helping to write this functionality, but I thought I would raise it as an issue first to see what your thoughts on it are.

@tavianator
Copy link
Owner

So the find analogues of those are:

# --include=*.css
-name '*.css'

# --exclude=*.min.js
! -name '*.min.js'

# --exclude-dir=.git
! -name .git -o -prune -false

I think the first two are fine, but the last one is totally unreasonable. I think the right approach would be:

-exclude .git

which would prune anything named .git without printing it. -nohidden would be equivalent to -exclude '.?*'.

Another thing that's nicer with the grep syntax you give is giving multiple patterns:

# --include=*.{css,vcl,...}
-name '*.css' -o -name '*.vcl' -o ...

Much more compact with the brace-expansion. FNM_EXTMATCH would let you do this at least:

-name '+(*.css|*.vcl|...)'

@tavianator
Copy link
Owner

Actually -name .git -exclude would be a bit more powerful and consistent with -prune. Basically it would do what people expect -prune to do.

@tavianator
Copy link
Owner

Oh damn, -name .git -exclude can't work. If -name .git returns false then the predicate short-circuits and -exclude won't even run.

@tavianator
Copy link
Owner

@bag-man The https://github.com/tavianator/bfs/tree/exclude branch implements this syntax:

bfs -exclude -name .git

What do you think?

@bag-man
Copy link
Author

bag-man commented Feb 10, 2017

@tavianator Nice one, although I noticed that this worked:

bfs -exclude -name node_modules -name package.json

But this didn't:

bfs -name package.json -exclude -name node_modules

Which is a little confusing.

@merwok
Copy link

merwok commented Jan 28, 2018

Throwing another idea here: I’ve recently started using ag (the silver searcher), a grep replacement that looks for a .gitignore file for patterns to ignore. There is also a command-line option to add ignores.

ag replaces a bunch of grep aliases that I was using to look for things in codebases; I don’t have to think about excluding __pycache__ or node_modules or build/dist directories.
It would be amazing to have bfs be a similar better replacement for good old inflexible find.

@tavianator tavianator added this to the 2.0 milestone Oct 14, 2020
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