Skip to content

Commit

Permalink
add follow symlinks option
Browse files Browse the repository at this point in the history
  • Loading branch information
konradsz committed Nov 12, 2023
1 parent 5ab8377 commit e139886
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 20 deletions.
39 changes: 20 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <EDITOR> Text editor used to open selected match.
[possible values: check supported text editors section]
--custom-command <CUSTOM_COMMAND> Custom command used to open selected match.
Must contain {file_name} and {line_number} tokens (check Custom Command section).
-g, --glob <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 <TYPE_MATCHING> Only search files matching TYPE.
Multiple types may be provided.
-T, --type-not <TYPE_NOT> Do not search files matching TYPE-NOT.
Multiple types-not may be provided.
--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.
-., --hidden Search hidden files and directories. By default, hidden files and
directories are skipped.
--editor <EDITOR> Text editor used to open selected match.
[possible values: check supported text editors section]
--custom-command <COMMAND> Custom command used to open selected match.
Must contain {file_name} and {line_number} tokens (check Custom Command section).
-g, --glob <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 <TYPE_MATCHING> Only search files matching TYPE.
Multiple types may be provided.
-T, --type-not <TYPE_NOT> Do not search files matching TYPE-NOT.
Multiple types-not may be provided.
--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.
```
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 @@ -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)]
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 @@ -14,6 +14,7 @@ pub struct SearchConfig {
pub overrides: Override,
pub types: Types,
pub search_hidden: bool,
pub follow_links: bool,
}

impl SearchConfig {
Expand All @@ -30,6 +31,7 @@ impl SearchConfig {
overrides: Override::empty(),
types,
search_hidden: false,
follow_links: false,
})
}

Expand Down Expand Up @@ -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
}
}
4 changes: 3 additions & 1 deletion src/ig/searcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,15 @@ fn run(path: &Path, config: SearchConfig, tx: mpsc::Sender<Event>) {
.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();
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;

Expand Down

0 comments on commit e139886

Please sign in to comment.