diff --git a/README.md b/README.md index e711c48..984e46c 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ Runs [grep](https://crates.io/crates/grep) ([ripgrep's](https://github.com/Burnt --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. diff --git a/src/args.rs b/src/args.rs index 75eab45..ae528fc 100644 --- a/src/args.rs +++ b/src/args.rs @@ -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)] diff --git a/src/ig/search_config.rs b/src/ig/search_config.rs index 6239b93..9cb6877 100644 --- a/src/ig/search_config.rs +++ b/src/ig/search_config.rs @@ -15,6 +15,7 @@ pub struct SearchConfig { pub types: Types, pub search_hidden: bool, pub follow_links: bool, + pub word_regexp: bool, } impl SearchConfig { @@ -32,6 +33,7 @@ impl SearchConfig { types, search_hidden: false, follow_links: false, + word_regexp: false, }) } @@ -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 + } } diff --git a/src/ig/searcher.rs b/src/ig/searcher.rs index 4a68494..cc59b49 100644 --- a/src/ig/searcher.rs +++ b/src/ig/searcher.rs @@ -49,6 +49,7 @@ fn run(path: &Path, config: SearchConfig, tx: mpsc::Sender) { .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"); diff --git a/src/main.rs b/src/main.rs index 3a538a6..09a4c44 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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)?;