Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "find-files"
version = "0.1.7"
version = "0.1.8"
description = "Find Files (ff) utility recursively searches the files whose names match the specified RegExp pattern in the provided directory (defaults to the current directory if not provided)."
authors = ["Vishal Telangre <[email protected]>"]
license = "Unlicense OR MIT"
Expand Down
113 changes: 62 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ FLAGS:
OPTIONS:
-x, --exclude <exclude> Exclude files and directories matching this
regular expression from the search results.
-L, --level <level> Recursively search only given level directories
deep. By default no depth restriction is imposed.
A value of 0 would always yield zero results. A
value of 1 searches for the direct children in
the given path.
-j, --threads <threads> The approximate number of threads to use. A value
of 0 (which is the default) results in thread
count set to available CPU cores.
Expand All @@ -105,91 +110,97 @@ Following examples demonstrate just a tip of an iceberg.

- List paths of files recursively in the current working directory matching `article` string.

```
ff article
```
```
ff article
```

- List files having `.png`, or `.PNG` extension.

```
ff png$
```
```
ff png$
```

- List files having strict `.PNG` extension.

```
ff -s PNG$
```
```
ff -s PNG$
```

- Search various image files.

```
ff "\.(png|jpg|jpeg|gif|svg)$"
```
```
ff "\.(png|jpg|jpeg|gif|svg)$"
```

- List files whose path matches `controllers` string.

```
ff controllers
```
```
ff controllers
```

- Search `.js` files in `./spec` directory.

```
ff \.js ./spec
```
```
ff \.js ./spec
```

- Search a file which is expected to be inside hidden `.git` directory whose name contains `commit` or something similar.

```bash
$ ff git.*commit
```bash
$ ff git.*commit

./.git/COMMIT_EDITMSG
# omitted other results
```
./.git/COMMIT_EDITMSG
# omitted other results
```

- Do not show hidden files and directories in the search results.

```
ff something -H
```
```
ff something -H
```

- Do not show those files and directories in the search results which are enlisted in `.gitignore`.

```
ff src/.*js$ -G
```
```
ff src/.*js$ -G
```

Without `-G (--ignore-gitignore)` flag in the above command, it also includes the results in the directories such as `node_modules` by default.
Without `-G (--ignore-gitignore)` flag in the above command, it also includes the results in the directories such as `node_modules` by default.

- Do not show paths which are just directories and not actual files.

```bash
$ ff -D user
```bash
$ ff -D user

./app/models/user.rb
./app/models/user/address.rb
./specs/models/user_spec.rb
./specs/models/user/address_spec.rb
```
./app/models/user.rb
./app/models/user/address.rb
./specs/models/user_spec.rb
./specs/models/user/address_spec.rb
```

Without `-D (--exclude-dir-paths)` flag in the above command, it also includes the paths of the matching directories in the results as follows.
Without `-D (--exclude-dir-paths)` flag in the above command, it also includes the paths of the matching directories in the results as follows.

```bash
$ ff user
```bash
$ ff user

./app/models/user.rb
./app/models/user
./app/models/user/address.rb
./specs/models/user_spec.rb
./specs/models/user
./specs/models/user/address_spec.rb
```
./app/models/user.rb
./app/models/user
./app/models/user/address.rb
./specs/models/user_spec.rb
./specs/models/user
./specs/models/user/address_spec.rb
```

- Exclude (omit) files and directories which match the provided optional exclude RegExp pattern.

```
ff rb$ app/controllers -x /(audit|admin|sso|api)/
```
```
ff rb$ app/controllers -x /(audit|admin|sso|api)/
```

Above command will show paths of all files whose name ends with `rb` inside the relative `app/controllers` directory excluding the paths which match `/(audit|admin|sso|api)/` pattern.

- Limit searching beyond 3 levels deep in the given path.

Above command will show paths of all files whose name ends with `rb` inside the relative `app/controllers` directory excluding the paths which match `/(audit|admin|sso|api)/` pattern.
```
ff -L 3 .js$
```
7 changes: 7 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ pub fn app() -> ArgMatches<'static> {
.short("s")
.long("case-sensitive"),
)
.arg(
Arg::with_name("level")
.help("Recursively search only given level directories deep. By default no depth restriction is imposed. A value of 0 would always yield zero results. A value of 1 searches for the direct children in the given path.")
.short("L")
.takes_value(true)
.long("level"),
)
.arg(
Arg::with_name("threads")
.help("The approximate number of threads to use. A value of 0 (which is the default) results in thread count set to available CPU cores.")
Expand Down
8 changes: 8 additions & 0 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub struct Args {
pub ignore_gitignore: bool,
pub ignore_hidden: bool,
pub case_sensitive: bool,
pub level: Option<usize>,
pub threads: usize,
pub exclude_reg_exp: Option<Regex>,
}
Expand Down Expand Up @@ -76,6 +77,12 @@ impl ArgMatchesWrapper {
}
}

fn level(&self) -> Option<usize> {
let matches = &self.matches;

clap::value_t!(matches.value_of("level"), usize).ok()
}

fn threads(&self) -> usize {
let matches = &self.matches;
let threads = clap::value_t!(matches.value_of("threads"), usize).unwrap_or(0);
Expand Down Expand Up @@ -132,6 +139,7 @@ impl ArgMatchesWrapper {
ignore_gitignore: self.should_ignore_gitignore_files(),
case_sensitive: self.is_case_sensitive(),
reg_exp: self.search_pattern(),
level: self.level(),
threads: self.threads(),
exclude_reg_exp: self.exclude_reg_exp(),
}
Expand Down
1 change: 1 addition & 0 deletions src/walker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ impl<'a> Walker<'a> {
let walker = WalkBuilder::new(&self.args.root_path)
.hidden(self.args.ignore_hidden)
.git_ignore(self.args.ignore_gitignore)
.max_depth(self.args.level)
.threads(self.args.threads)
.build_parallel();

Expand Down