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

Add --exclude option. #89

Closed
tmccombs opened this issue Oct 10, 2017 · 13 comments
Closed

Add --exclude option. #89

tmccombs opened this issue Oct 10, 2017 · 13 comments

Comments

@tmccombs
Copy link
Collaborator

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).

@shawnaxsom
Copy link

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.

@sharkdp
Copy link
Owner

sharkdp commented Oct 10, 2017

@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.

@jakwings
Copy link
Contributor

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.

@jakwings
Copy link
Contributor

Also see the --iglob option of ripgrep.

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

@sharkdp
Copy link
Owner

sharkdp commented Oct 13, 2017

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

@Doxterpepper
Copy link
Contributor

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.

@Detegr
Copy link
Contributor

Detegr commented Oct 16, 2017

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.

@jakwings
Copy link
Contributor

jakwings commented Oct 16, 2017

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>.

@tmccombs
Copy link
Collaborator Author

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.

@Detegr
Copy link
Contributor

Detegr commented Oct 17, 2017

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?

@sharkdp
Copy link
Owner

sharkdp commented Oct 17, 2017

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.

@jakwings
Copy link
Contributor

@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.

sharkdp added a commit that referenced this issue Oct 22, 2017
* Add `--exclude`/`-E` option.
* Support for multiple exclude patterns

Example:
``` bash
> fd --exclude 'tests/**/*.rs' mod
src/exec/mod.rs
src/fshelper/mod.rs
src/lscolors/mod.rs
```

Closes #89
sharkdp added a commit that referenced this issue Oct 22, 2017
* Add `--exclude`/`-E` option.
* Support for multiple exclude patterns

Example:
``` bash
> fd --exclude 'tests/**/*.rs' mod
src/exec/mod.rs
src/fshelper/mod.rs
src/lscolors/mod.rs
```

Closes #89
sharkdp added a commit that referenced this issue Oct 25, 2017
* Add `--exclude`/`-E` option.
* Support for multiple exclude patterns

Example:
``` bash
> fd --exclude 'tests/**/*.rs' mod
src/exec/mod.rs
src/fshelper/mod.rs
src/lscolors/mod.rs
```

Closes #89
sharkdp added a commit that referenced this issue Oct 25, 2017
* Add `--exclude`/`-E` option.
* Support for multiple exclude patterns

Example:
``` bash
> fd --exclude 'tests/**/*.rs' mod
src/exec/mod.rs
src/fshelper/mod.rs
src/lscolors/mod.rs
```

Closes #89
@sharkdp
Copy link
Owner

sharkdp commented Oct 25, 2017

This is now supported (see #148)

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

6 participants