Skip to content

Commit

Permalink
support for searching hidden files and directories
Browse files Browse the repository at this point in the history
  • Loading branch information
konradsz committed Mar 2, 2022
1 parent ce3f46d commit 265ee8f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Runs [grep](https://crates.io/crates/grep) ([ripgrep's](https://github.com/Burnt

### Options
```
-., --hidden Search hidden files and directories. By default, hidden files and
directories are skipped.
--editor <EDITOR> Text editor used to open selected match. [env: IGREP_EDITOR=]
[default: vim] [possible values: vim, neovim, nvim, nano]
-g, --glob <GLOB> Include files and directories for searching that match the given glob.
Expand Down
7 changes: 7 additions & 0 deletions src/ig/search_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub struct SearchConfig {
pub case_smart: bool,
pub overrides: Override,
pub types: Types,
pub search_hidden: bool,
}

impl SearchConfig {
Expand All @@ -27,6 +28,7 @@ impl SearchConfig {
case_smart: false,
overrides: Override::empty(),
types,
search_hidden: false,
})
}

Expand Down Expand Up @@ -65,4 +67,9 @@ impl SearchConfig {
self.types = builder.build()?;
Ok(self)
}

pub fn search_hidden(mut self, search_hidden: bool) -> Self {
self.search_hidden = search_hidden;
self
}
}
1 change: 1 addition & 0 deletions src/ig/searcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ impl SearcherImpl {
let walk_parallel = builder
.overrides(self.config.overrides.clone())
.types(self.config.types.clone())
.hidden(!self.config.search_hidden)
.build_parallel();
walk_parallel.run(move || {
let tx = tx.clone();
Expand Down
5 changes: 5 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ struct Args {
/// Search case sensitively otherwise.
#[clap(short = 'S', long)]
smart_case: bool,
/// Search hidden files and directories.
/// By default, hidden files and directories are skipped.
#[clap(short = '.', long = "hidden")]
search_hidden: bool,
/// Include files and directories for searching that match the given glob.
/// Multiple globs may be provided.
#[clap(short, long)]
Expand Down Expand Up @@ -73,6 +77,7 @@ fn main() -> Result<()> {
let search_config = ig::SearchConfig::from(args.pattern.unwrap(), path)?
.case_insensitive(args.ignore_case)
.case_smart(args.smart_case)
.search_hidden(args.search_hidden)
.globs(args.glob)?
.file_types(args.type_matching, args.type_not)?;

Expand Down

0 comments on commit 265ee8f

Please sign in to comment.