Skip to content
Myr

internal.rs

This file

Path

src/internal.rs

114 lines · 3.9 KiB · Rust

Last changed by

Add support for exclude-patternssharkdpbefore adoption5ad69fb

History of this file

Take it

Relicense under MIT/Apache-2.0Antti Keränenbefore adoption701b8f2

lines 1–8why, one step back
1// Copyright (c) 2017 fd developers
2// Licensed under the Apache License, Version 2.03// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0>4// or the MIT license <LICENSE-MIT or http://opensource.org/licenses/MIT>,5// at your option. All files in the project carrying such6// notice may not be copied, modified, or distributed except7// according to those terms.8

break main into separate modulesGarrett Squirebefore adoptionccb899a

lines 9–12why, one step back
9use std::process;
10use std::time;11use std::io::Write;12

Merge pull request #116 from mmstick/execDavid Peterbefore adoptione0eab07

line 13why, one step back
13use exec::TokenizedCommand;

break main into separate modulesGarrett Squirebefore adoptionccb899a

lines 14–15why, one step back
14use lscolors::LsColors;
15use walk::FileType;

Improve smart case to only consider literal uppercase chars (#103)Matthias Reitingerbefore adoptionb441528

line 16why, one step back
16use regex_syntax::{Expr, ExprBuilder};

break main into separate modulesGarrett Squirebefore adoptionccb899a

lines 17–29why, one step back
17
18/// Defines how to display search result paths.19#[derive(PartialEq)]20pub enum PathDisplay {21 /// As an absolute path22 Absolute,2324 /// As a relative path25 Relative,26}2728/// Configuration options for *fd*.29pub struct FdOptions {

Add -i, --ignore-caseJ.Wbefore adoptione075e1c

line 30why, one step back
30 /// Whether the search is case-sensitive or case-insensitive.

break main into separate modulesGarrett Squirebefore adoptionccb899a

lines 31–76why, one step back
31 pub case_sensitive: bool,
3233 /// Whether to search within the full file path or just the base name (filename or directory34 /// name).35 pub search_full_path: bool,3637 /// Whether to ignore hidden files and directories (or not).38 pub ignore_hidden: bool,3940 /// Whether to respect VCS ignore files (`.gitignore`, `.ignore`, ..) or not.41 pub read_ignore: bool,4243 /// Whether to follow symlinks or not.44 pub follow_links: bool,4546 /// Whether elements of output should be separated by a null character47 pub null_separator: bool,4849 /// The maximum search depth, or `None` if no maximum search depth should be set.50 ///51 /// A depth of `1` includes all files under the current directory, a depth of `2` also includes52 /// all files under subdirectories of the current directory, etc.53 pub max_depth: Option<usize>,5455 /// The number of threads to use.56 pub threads: usize,5758 /// Time to buffer results internally before streaming to the console. This is useful to59 /// provide a sorted output, in case the total execution time is shorter than60 /// `max_buffer_time`.61 pub max_buffer_time: Option<time::Duration>,6263 /// Display results as relative or absolute path.64 pub path_display: PathDisplay,6566 /// `None` if the output should not be colorized. Otherwise, a `LsColors` instance that defines67 /// how to style different filetypes.68 pub ls_colors: Option<LsColors>,6970 /// The type of file to search for. All files other than the specified type will be ignored.71 pub file_type: FileType,7273 /// The extension to search for. Only entries matching the extension will be included.74 ///75 /// The value (if present) will be a lowercase string without leading dots.76 pub extension: Option<String>,

Merge pull request #116 from mmstick/execDavid Peterbefore adoptione0eab07

lines 77–79why, one step back
77
78 /// If a value is supplied, each item found will be used to generate and execute commands.79 pub command: Option<TokenizedCommand>,

Add support for exclude-patternssharkdpbefore adoption5ad69fb

lines 80–82why, one step back
80
81 /// A list of glob patterns that should be excluded from the search.82 pub exclude_patterns: Vec<String>,

break main into separate modulesGarrett Squirebefore adoptionccb899a

lines 83–88why, one step back
83}
8485/// Print error message to stderr and exit with status `1`.86pub fn error(message: &str) -> ! {87 writeln!(&mut ::std::io::stderr(), "{}", message).expect("Failed writing to stderr");88 process::exit(1);

Improve smart case to only consider literal uppercase chars (#103)Matthias Reitingerbefore adoptionb441528

lines 89–107why, one step back
89}
9091/// Determine if a regex pattern contains a literal uppercase character.92pub fn pattern_has_uppercase_char(pattern: &str) -> bool {93 ExprBuilder::new()94 .parse(pattern)95 .map(|expr| expr_has_uppercase_char(&expr))96 .unwrap_or(false)97}9899/// Determine if a regex expression contains a literal uppercase character.100fn expr_has_uppercase_char(expr: &Expr) -> bool {101 match *expr {102 Expr::Literal { ref chars, .. } => chars.iter().any(|c| c.is_uppercase()),103 Expr::Class(ref ranges) => {104 ranges.iter().any(|r| {105 r.start.is_uppercase() || r.end.is_uppercase()106 })107 }

Updates and preparations for v5.0sharkdpbefore adoptione9cf8af

line 108why, one step back
108 Expr::Group { ref e, .. } |

Improve smart case to only consider literal uppercase chars (#103)Matthias Reitingerbefore adoptionb441528

lines 109–113why, one step back
109 Expr::Repeat { ref e, .. } => expr_has_uppercase_char(e),
110 Expr::Concat(ref es) => es.iter().any(expr_has_uppercase_char),111 Expr::Alternate(ref es) => es.iter().any(expr_has_uppercase_char),112 _ => false,113 }

break main into separate modulesGarrett Squirebefore adoptionccb899a

line 114why, one step back
114}