Fd: Add --exclude option.

Created on 10 Oct 2017  路  13Comments  路  Source: sharkdp/fd

Add an --exclude option which takes a .gitignore style pattern to exclude from the search (the option can be specified multiple times to add multiple excludes).

Maybe also consider a complementary --include option.

Implementation

The argument(s) would be added to the WalkBuilder with the overrides method, with a "!" prepended so they are exclusions, not inclusions. Alternatively, write the arguments to a temporary file and use add_ignore. (It may be worth adding a PR to ignore to add an easier way to add exclude globs to overrides).

feature-request good first issue

Most helpful comment

I would prefer --exclude/--include, modifying text files for temporarily ignoring a certain directory seems a bit overkill. Ignore files are supported already, and this would just be a override (or addition) to that.

All 13 comments

Yes this can certainly help with integrations along with CLI convenience. I was hoping to integrate fd with my Vim file find plugin Vim-Quickly. rg and ag file search allow for exclusion options which lets me exclude Vim's "wildignore" patterns. I don't really want to integrate something that will frustrate users by not ignoring "wildignore", so I'll hold off until this is implemented.

Just one plugin isn't a big deal, but others looking to integrate with fd might have the same needs and this would be helpful for them.

@tmccombs Thank you for writing this up. Sounds good to me.

Seems like the overrides method is the right way to go. If I understand correctly, multiple overrides can be added via OverrideBuilder::add.

I was previously thinking about adding an --exclude option that would take a regex as an argument, but I think adding .gitignore-style globs is the better way.

I think --ignore-file (just like ripgrep) would be better than mixing two syntaxes on the commandline, then can override any includes/excludes in the file.

Also see the --iglob option of ripgrep.

(馃槢 I can turn ripgrep into a simpler fd command like this: rg --files --glob PATTERN)

@tmccombs @Detegr What do you think? Would --ignore-file be preferable over --exclude/--include (and/or --mount, see #74)?

Just a thought, a feature mentioned in the README is fd is 50% shorter than find, using --exclude over --ignore-file would be consistent with that.

I would prefer --exclude/--include, modifying text files for temporarily ignoring a certain directory seems a bit overkill. Ignore files are supported already, and this would just be a override (or addition) to that.

I think --ignore <ignore_rule> and --ignore-file <ignore_file> are better. A rule can include or exclude what should be ignored, so no need to have two different flags for <ignore_rule>.

I'm not picky about the name. But I do think it would be inconvenient to have to edit a temporary file to temporarily ignore files.

I agree that the rule/glob can specify whether the file should be included or excluded. What comes to the naming, I think --glob (and/or --iglob?) is a fine name to keep the cli similar than in ripgrep. This feature is basically the same, right?

I feel the discussion about --ignore-file should be in a separate issue as it is a different, though quite similar, feature.

EDIT: Oh, but we already have --glob flag in #97. I'm a bit confused now, is that something different?

I agree that the rule/glob can specify whether the file should be included or excluded. What comes to the naming, I think --glob (and/or --iglob?) is a fine name to keep the cli similar than in ripgrep. This feature is basically the same, right?

Yes. I'm also in favor of keeping this in sync with ripgrep. Let's implement this as --glob (and possibly --iglob). We also add --include/--exclude as aliases for --glob/--glob '!xxx'.

I feel the discussion about --ignore-file should be in a separate issue as it is a different, though quite similar, feature.

Agreed. As you said, this is already supported to a certain extent (by creating a ~/.ignore file, for example).

EDIT: Oh, but we already have --glob flag in #97. I'm a bit confused now, is that something different?

Yes. That is a bit unfortunate. #97 is a discussion / feature request to add --glob to switch from normal regex matching to glob-matching. I'm open for suggestions.

@Detegr Yeah, #97 implement the (near) traditional globbing mode in posix shells. A different thing.

My first thought about --include was that it is used to add more regex patterns, not the gitignore pattern. I also have similar sense about --exclude and --ignore, but --ignore seems easier to remember.

About the case-sensitivity of this flag (of whatever name), I don't know if smart case should apply when it is just temporary. I can imagine that I use the auto-complete function of the shell to get the directory name, then turn it into a rule.

Then --glob and --iglob. Their meanings in ripgrep is not very intuitive. Better check it more carefully.

This is now supported (see #148)

Was this page helpful?
0 / 5 - 0 ratings