Navigation Menu

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

Print warning if --hidden is not set and search pattern starts with a dot #615

Closed
Porkepix opened this issue Jun 10, 2020 · 3 comments
Closed

Comments

@Porkepix
Copy link

I doon't know if this is a correct idea considering the double meaning the dot represent: both "any character" for its regex meaning and the fact it's an hidden file/folder.

However, searching today after for example .gitlab-ci.yml files in a whole tree, it didn't found anything at first, well because hidden file, so -H flag is needed.

I considered it could be a nice addition, if string start exactly by a dot to enable the flag, or not exclude hidden files with exact matching. This can however conflict with the "any character" meaning of the dot, so I'll let you decide whether this is a good idea or not.

@sharkdp
Copy link
Owner

sharkdp commented Jun 11, 2020

Thank you for your feedback.

I like the idea in general, but I certainly don't want to enable it for a pattern like .gitlab… because, as you said, the . here represents something else (match any character). In addition, it would also match files like WHATEVERgitlab…, because there is no ^ anker in the beginning of this pattern. The way you would actually search for files being called .gitlab-ci.yml would be via:

fd -H '^\.gitlab-ci\.yml$'

Having to escape all of this by hand is not very convenient, of course. This is why we have the --fixed-strings option. However, I now tend to use the -g/--glob option if I want to search for exact matches:

fd -Hg .gitlab-ci.yml

So what we could do would be the following:

If the user does not pass the --hidden/-H option and

  • supplies a regex pattern that only matches files starting with an actual dot (like ^\.xxx) or
  • supplies a glob pattern via -g .xxx that starts with a dot

… we could print a warning that no results will be found, because --hidden is not enabled.
We would need to take about platform-inconsistencies as well. Hidden files on Windows do mean something else.

@sharkdp sharkdp changed the title Suggestion: auto-enable -H flag when search pattern start with a dot Auto-enable --hidden flag when search pattern starts with a dot Dec 6, 2020
@sharkdp sharkdp changed the title Auto-enable --hidden flag when search pattern starts with a dot Print warning if --hidden is not set and search pattern starts with a dot Dec 6, 2020
@sharkdp sharkdp closed this as completed in cadaef3 Dec 6, 2020
@sharkdp
Copy link
Owner

sharkdp commented Dec 6, 2020

This is now implemented:

▶ fd -g .gitlab-ci.yml 
[fd error]: The pattern seems to only match files with a leading dot, but hidden
files are filtered by default. Consider adding -H/--hidden to search hidden files
as well or adjust your search pattern.

▶ fd '^\.gitlab-ci\.yml$'   
[fd error]: The pattern seems to only match files with a leading dot, but hidden
files are filtered by default. Consider adding -H/--hidden to search hidden files
as well or adjust your search pattern.

@sharkdp
Copy link
Owner

sharkdp commented Dec 6, 2020

released in v8.2.0.

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

2 participants