Skip to content
Myr

config.rs

This file

Path

src/config.rs

143 lines · 4.8 KiB · Rust

Last changed by

Merge pull request #1928 from tmccombs/full-path-fixesTavian Barnesbefore adoptiond6b44b8

History of this file

Take it

1use std::{path::PathBuf, sync::Arc, time::Duration};23use lscolors::LsColors;4use regex::bytes::RegexSet;56use crate::exec::CommandSet;7use crate::filetypes::FileTypes;8#[cfg(unix)]9use crate::filter::OwnerFilter;10use crate::filter::{SizeFilter, TimeFilter};11use crate::fmt::FormatTemplate;1213/// Configuration options for *fd*.14pub struct Config {15    /// Whether the search is case-sensitive or case-insensitive.16    pub case_sensitive: bool,1718    /// Cached current working directory for absolute path construction.19    /// Populated when `--full-path` is set; `None` means search by filename only.20    pub full_path_base: Option<PathBuf>,2122    /// Whether to ignore hidden files and directories (or not).23    pub ignore_hidden: bool,2425    /// Whether to respect `.fdignore` files or not.26    pub read_fdignore: bool,2728    /// Whether to respect ignore files in parent directories or not.29    pub read_parent_ignore: bool,3031    /// Whether to respect VCS ignore files (`.gitignore`, ..) or not.32    pub read_vcsignore: bool,3334    /// Whether to require a `.git` directory to respect gitignore files.35    pub require_git_to_read_vcsignore: bool,3637    /// Whether to respect the global ignore file or not.38    pub read_global_ignore: bool,3940    /// Whether to follow symlinks or not.41    pub follow_links: bool,4243    /// Whether to limit the search to starting file system or not.44    pub one_file_system: 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 minimum depth for reported entries, or `None`.56    pub min_depth: Option<usize>,5758    /// Whether to stop traversing into matching directories.59    pub prune: bool,6061    /// The number of threads to use.62    pub threads: usize,6364    /// If true, the program doesn't print anything and will instead return an exit code of 065    /// if there's at least one match. Otherwise, the exit code will be 1.66    pub quiet: bool,6768    /// Time to buffer results internally before streaming to the console. This is useful to69    /// provide a sorted output, in case the total execution time is shorter than70    /// `max_buffer_time`.71    pub max_buffer_time: Option<Duration>,7273    /// `None` if the output should not be colorized. Otherwise, a `LsColors` instance that defines74    /// how to style different filetypes.75    pub ls_colors: Option<LsColors>,7677    /// Whether or not we are writing to an interactive terminal78    #[cfg_attr(not(unix), allow(unused))]79    pub interactive_terminal: bool,8081    /// The type of file to search for. If set to `None`, all file types are displayed. If82    /// set to `Some(..)`, only the types that are specified are shown.83    pub file_types: Option<FileTypes>,8485    /// The extension to search for. Only entries matching the extension will be included.86    ///87    /// The value (if present) will be a lowercase string without leading dots.88    pub extensions: Option<RegexSet>,8990    /// A format string to use to format results, similarly to exec91    pub format: Option<FormatTemplate>,9293    /// If a value is supplied, each item found will be used to generate and execute commands.94    pub command: Option<Arc<CommandSet>>,9596    /// Maximum number of search results to pass to each `command`. If zero, the number is97    /// unlimited.98    pub batch_size: usize,99100    /// A list of glob patterns that should be excluded from the search.101    pub exclude_patterns: Vec<String>,102103    /// A list of custom ignore files.104    pub ignore_files: Vec<PathBuf>,105106    /// The given constraints on the size of returned files107    pub size_constraints: Vec<SizeFilter>,108109    /// Constraints on last modification time of files110    pub time_constraints: Vec<TimeFilter>,111112    #[cfg(unix)]113    /// User/group ownership constraint114    pub owner_constraint: Option<OwnerFilter>,115116    /// Whether or not to display filesystem errors117    pub show_filesystem_errors: bool,118119    /// The separator used to print file paths.120    pub path_separator: Option<String>,121122    /// The actual separator, either the system default separator or `path_separator`123    pub actual_path_separator: String,124125    /// The maximum number of search results126    pub max_results: Option<usize>,127128    /// Whether or not to strip the './' prefix for search results129    pub strip_cwd_prefix: bool,130131    /// Whether or not to use hyperlinks on paths132    pub hyperlink: bool,133134    /// Names that should stop traversal down their parent. (e.g. https://bford.info/cachedir/).135    pub ignore_contain: Vec<String>,136}137138impl Config {139    /// Check whether results are being printed.140    pub fn is_printing(&self) -> bool {141        self.command.is_none()142    }143}