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

GlobStar support -- ** matches any number of levels #19

Open
oxinabox opened this issue Dec 7, 2018 · 11 comments
Open

GlobStar support -- ** matches any number of levels #19

oxinabox opened this issue Dec 7, 2018 · 11 comments

Comments

@oxinabox
Copy link

oxinabox commented Dec 7, 2018

This is a thing in bash's glob, and in the .gitignore pattern matching.
it is really useful e.g. for getting to the bottom of a directory hierachy.

When the globstar shell option is enabled, and * is used in a filename expansion context, two adjacent *s used as a single pattern will match all files and zero or more directories and subdirectories. If followed by a ‘/’, two adjacent *s will match only directories and subdirectories.

https://www.gnu.org/software/bash/manual/html_node/Pattern-Matching.html

@mahiki
Copy link

mahiki commented Jul 8, 2021

So it looks like this is not going to be implemented.

@oxinabox
Copy link
Author

oxinabox commented Jul 9, 2021

So it looks like this is not going to be implemented.

Why? It hasn't been implemented yet, but that doesn't mean me or someone else might not find the time in the future.

@kpa28-git
Copy link

This package extends glob.jl to add a a recursive ** pattern

@vmiheer
Copy link

vmiheer commented Aug 6, 2021

Sadly eglob doesn't seem to install using specified instructions in README.

@navidcy
Copy link

navidcy commented May 21, 2023

Eglob.jl is stale.

@vtjnash
Copy link
Owner

vtjnash commented May 21, 2023

My last look was that might not handle multiple ** correctly in rare cases, so I didn't attempt to merge that here. But if someone could write the algorithm for it, I would likely merge it.

@hhaensel
Copy link

hhaensel commented Jun 5, 2024

I tried implementing ** support.
I did tested the following patterns, but I'm mot sure if I missed one of your edge cases.

@test occursin(fn"**/*.png"d, "c.png")
@test occursin(fn"**/*.png"d, "a/c.png")
@test occursin(fn"**/*.png"d, "a/b/c.png")

@test occursin(fn"/**/*.png"d, "/c.png")
@test occursin(fn"/**/*.png"d, "/a/c.png")
@test occursin(fn"/**/*.png"d, "/a/b/c.png")

@test occursin(fn"**/*.png"d, "/c.png")
@test occursin(fn"**/*.png"d, "/a/c.png")
@test occursin(fn"**/*.png"d, "/a/b/c.png")

@test !occursin(fn"/**/*.png"d, "c.png")
@test !occursin(fn"/**/*.png"d, "a/c.png")
@test !occursin(fn"/**/*.png"d, "a/b/c.png")

@hhaensel hhaensel mentioned this issue Jun 5, 2024
@hhaensel
Copy link

hhaensel commented Jun 5, 2024

Two more important ones:

@test occursin(fn"**.png"d, "c.png")
@test !occursin(fn"**.png"d, "a/b/c.png")

@hhaensel
Copy link

hhaensel commented Jun 5, 2024

Found one edge case that fails. Pattern with ending "**" currently don't match all files.

@hhaensel
Copy link

hhaensel commented Jun 5, 2024

But that can probably be solved by replacing ending "**" by "**/*"

@hhaensel
Copy link

hhaensel commented Jun 5, 2024

With that modification, also the following tests pass

@test occursin(fn"**"d, "c.png")
@test occursin(fn"**"d, "a/c.png")
@test occursin(fn"**"d, "/a/c.png")
@test occursin(fn"/**"d, "/a/c.png")
@test occursin(fn"/a/**"d, "/a/c.png")
@test !occursin(fn"/b/**"d, "/a/c.png")
@test !occursin(fn"/**"d, "a/c.png")

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

Successfully merging a pull request may close this issue.

7 participants