diff --git a/README.md b/README.md index f7fe472..fde156b 100644 --- a/README.md +++ b/README.md @@ -17,25 +17,26 @@ 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 Text editor used to open selected match. - [possible values: check supported text editors section] ---custom-command Custom command used to open selected match. - Must contain {file_name} and {line_number} tokens (check Custom Command section). --g, --glob Include files and directories for searching that match the given glob. - Multiple globs may be provided. --h, --help Print help information --i, --ignore-case Searches case insensitively. --S, --smart-case Searches case insensitively if the pattern is all lowercase. - Search case sensitively otherwise. --t, --type Only search files matching TYPE. - Multiple types may be provided. --T, --type-not Do not search files matching TYPE-NOT. - Multiple types-not may be provided. - --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. +-., --hidden Search hidden files and directories. By default, hidden files and + directories are skipped. + --editor Text editor used to open selected match. + [possible values: check supported text editors section] + --custom-command Custom command used to open selected match. + Must contain {file_name} and {line_number} tokens (check Custom Command section). +-g, --glob Include files and directories for searching that match the given glob. + Multiple globs may be provided. +-h, --help Print help information +-i, --ignore-case Searches case insensitively. +-L, --follow Follow symbolic links while traversing directories +-S, --smart-case Searches case insensitively if the pattern is all lowercase. + Search case sensitively otherwise. +-t, --type Only search files matching TYPE. + Multiple types may be provided. +-T, --type-not Do not search files matching TYPE-NOT. + Multiple types-not may be provided. + --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. ``` 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 9848b90..ba35b03 100644 --- a/src/args.rs +++ b/src/args.rs @@ -43,6 +43,9 @@ pub struct Args { /// By default, hidden files and directories are skipped. #[clap(short = '.', long = "hidden")] pub search_hidden: bool, + /// Follow symbolic links while traversing directories. + #[clap(short = 'L', long = "follow")] + pub follow_links: 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 e1e4e71..6239b93 100644 --- a/src/ig/search_config.rs +++ b/src/ig/search_config.rs @@ -14,6 +14,7 @@ pub struct SearchConfig { pub overrides: Override, pub types: Types, pub search_hidden: bool, + pub follow_links: bool, } impl SearchConfig { @@ -30,6 +31,7 @@ impl SearchConfig { overrides: Override::empty(), types, search_hidden: false, + follow_links: false, }) } @@ -73,4 +75,9 @@ impl SearchConfig { self.search_hidden = search_hidden; self } + + pub fn follow_links(mut self, follow_links: bool) -> Self { + self.follow_links = follow_links; + self + } } diff --git a/src/ig/searcher.rs b/src/ig/searcher.rs index e170d15..4a68494 100644 --- a/src/ig/searcher.rs +++ b/src/ig/searcher.rs @@ -51,13 +51,15 @@ fn run(path: &Path, config: SearchConfig, tx: mpsc::Sender) { .case_smart(config.case_smart) .build(&config.pattern) .expect("Cannot build RegexMatcher"); - let mut builder = WalkBuilder::new(path); + let mut builder = WalkBuilder::new(path); let walk_parallel = builder .overrides(config.overrides.clone()) .types(config.types.clone()) .hidden(!config.search_hidden) + .follow_links(config.follow_links) .build_parallel(); + walk_parallel.run(move || { let tx = tx.clone(); let matcher = matcher.clone(); diff --git a/src/main.rs b/src/main.rs index 7fee58a..08bbf27 100644 --- a/src/main.rs +++ b/src/main.rs @@ -39,6 +39,7 @@ fn main() -> Result<()> { .case_insensitive(args.ignore_case) .case_smart(args.smart_case) .search_hidden(args.search_hidden) + .follow_links(args.follow_links) .globs(args.glob)? .file_types(args.type_matching, args.type_not)?;