mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2024-12-12 19:18:24 +02:00
d79add341b
This PR introduces a new sub-crate, `ignore`, which primarily provides a fast recursive directory iterator that respects ignore files like gitignore and other configurable filtering rules based on globs or even file types. This results in a substantial source of complexity moved out of ripgrep's core and into a reusable component that others can now (hopefully) benefit from. While much of the ignore code carried over from ripgrep's core, a substantial portion of it was rewritten with the following goals in mind: 1. Reuse matchers built from gitignore files across directory iteration. 2. Design the matcher data structure to be amenable for parallelizing directory iteration. (Indeed, writing the parallel iterator is the next step.) Fixes #9, #44, #45
67 lines
1.8 KiB
Markdown
67 lines
1.8 KiB
Markdown
ignore
|
|
======
|
|
The ignore crate provides a fast recursive directory iterator that respects
|
|
various filters such as globs, file types and `.gitignore` files. This crate
|
|
also provides lower level direct access to gitignore and file type matchers.
|
|
|
|
[![Linux build status](https://api.travis-ci.org/BurntSushi/ripgrep.png)](https://travis-ci.org/BurntSushi/ripgrep)
|
|
[![Windows build status](https://ci.appveyor.com/api/projects/status/github/BurntSushi/ripgrep?svg=true)](https://ci.appveyor.com/project/BurntSushi/ripgrep)
|
|
[![](https://img.shields.io/crates/v/ignore.svg)](https://crates.io/crates/ignore)
|
|
|
|
Dual-licensed under MIT or the [UNLICENSE](http://unlicense.org).
|
|
|
|
### Documentation
|
|
|
|
[https://docs.rs/ignore](https://docs.rs/ignore)
|
|
|
|
### Usage
|
|
|
|
Add this to your `Cargo.toml`:
|
|
|
|
```toml
|
|
[dependencies]
|
|
ignore = "0.1"
|
|
```
|
|
|
|
and this to your crate root:
|
|
|
|
```rust
|
|
extern crate ignore;
|
|
```
|
|
|
|
### Example
|
|
|
|
This example shows the most basic usage of this crate. This code will
|
|
recursively traverse the current directory while automatically filtering out
|
|
files and directories according to ignore globs found in files like
|
|
`.ignore` and `.gitignore`:
|
|
|
|
|
|
```rust,no_run
|
|
use ignore::Walk;
|
|
|
|
for result in Walk::new("./") {
|
|
// Each item yielded by the iterator is either a directory entry or an
|
|
// error, so either print the path or the error.
|
|
match result {
|
|
Ok(entry) => println!("{}", entry.path().display()),
|
|
Err(err) => println!("ERROR: {}", err),
|
|
}
|
|
}
|
|
```
|
|
|
|
### Example: advanced
|
|
|
|
By default, the recursive directory iterator will ignore hidden files and
|
|
directories. This can be disabled by building the iterator with `WalkBuilder`:
|
|
|
|
```rust,no_run
|
|
use ignore::WalkBuilder;
|
|
|
|
for result in WalkBuilder::new("./").hidden(false).build() {
|
|
println!("{:?}", result);
|
|
}
|
|
```
|
|
|
|
See the documentation for `WalkBuilder` for many other options.
|