sharkdp/fd

[BUG] fd --glob seems wrong

EloB opened this issue · 3 comments

EloB commented

Checks

  • I have read the troubleshooting section and still think this is a bug.

Describe the bug you encountered:

I've tried to use:

> mkdir -p hello/world
> touch hello/world/index.js
> fd
# hello/
# hello/world/
# hello/world/index.js
> fd -g 'hello/**/*.js'
# (No output this seems wrong)
> fd -g '**/*.js'
# hello/world/index.js
> fd -g '**/*.js' hello # I know that this is possible but glob usually support that type of pattern above.
# hello/world/index.js

Describe what you expected to happen:

See above

What version of fd are you using?

fd 9.0.0

Which operating system / distribution are you on?

uname -srm
Darwin 22.6.0 arm64

By default, fd is just comparing the file name (e.g. index.js) to the glob. It seems a bit strange that **/*.js matches at all, but it happens to work because recursive globs like **/* will also match top level files (see https://docs.rs/globset/latest/globset/#syntax).

You can turn on --full-path but then the matching is against the full absolute path (see #839)

$ fd --full-path -g 'hello/**/*.js' # Probably no results
$ fd --full-path -g "$PWD/hello/**/*.js"
hello/world/index.js
EloB commented

I think this answers my question. Thanks!

It may be worth printing a warning if a glob includes / without --full-path. GNU find does:

$ find -name 'foo/bar'
find: warning: ‘-name’ matches against basenames only, but the given pattern contains a directory separator (‘/’), thus the expression will evaluate to false all the time.  Did you mean ‘-wholename’?