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 -w/--word-regexp arg #63

Merged
merged 1 commit into from
Jan 8, 2024
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
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