Skip to content

Commit

Permalink
add -w/--word-regexp arg (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
konradsz committed Jan 8, 2024
1 parent 0789d8e commit 4ab556b
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Runs [grep](https://crates.io/crates/grep) ([ripgrep's](https://github.com/Burnt
--theme <THEME> UI color theme [default: dark] [possible values: light, dark]
--type-list Show all supported file types and their corresponding globs.
-V, --version Print version information.
-w, --word-regexp Only show matches surrounded by word boundaries
```
NOTE: `ig` respects `ripgrep`'s [configuration file](https://github.com/BurntSushi/ripgrep/blob/master/GUIDE.md#configuration-file) if `RIPGREP_CONFIG_PATH` environment variable is set and reads all supported options from it.

Expand Down
3 changes: 3 additions & 0 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ pub struct Args {
/// Follow symbolic links while traversing directories.
#[clap(short = 'L', long = "follow")]
pub follow_links: bool,
/// Only show matches surrounded by word boundaries.
#[clap(short = 'w', long = "word-regexp")]
pub word_regexp: bool,
/// Include files and directories for searching that match the given glob.
/// Multiple globs may be provided.
#[clap(short, long)]
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 @@ -15,6 +15,7 @@ pub struct SearchConfig {
pub types: Types,
pub search_hidden: bool,
pub follow_links: bool,
pub word_regexp: bool,
}

impl SearchConfig {
Expand All @@ -32,6 +33,7 @@ impl SearchConfig {
types,
search_hidden: false,
follow_links: false,
word_regexp: false,
})
}

Expand Down Expand Up @@ -80,4 +82,9 @@ impl SearchConfig {
self.follow_links = follow_links;
self
}

pub fn word_regexp(mut self, word_regexp: bool) -> Self {
self.word_regexp = word_regexp;
self
}
}
1 change: 1 addition & 0 deletions src/ig/searcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ fn run(path: &Path, config: SearchConfig, tx: mpsc::Sender<Event>) {
.line_terminator(Some(b'\n'))
.case_insensitive(config.case_insensitive)
.case_smart(config.case_smart)
.word(config.word_regexp)
.build(&config.pattern)
.expect("Cannot build RegexMatcher");

Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ fn main() -> Result<()> {
.case_smart(args.smart_case)
.search_hidden(args.search_hidden)
.follow_links(args.follow_links)
.word_regexp(args.word_regexp)
.globs(args.glob)?
.file_types(args.type_matching, args.type_not)?;

Expand Down

0 comments on commit 4ab556b

Please sign in to comment.