Skip to content
Myr

main.rs

This file

Path

src/main.rs

479 lines · 21.1 KiB · Rust

Last changed by

fix: Respect NO_COLOR with --list-details optionThayne McCombsbefore adoption9529f30

History of this file

Take it

The walk stopped after 200 commits: lines older than 17d849d point at it.

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

line 1why, one step back
1mod cli;

Compute colors in parallelTavian Barnesbefore adoption17d849d

lines 2–14why, one step back
2mod config;
3mod dir_entry;4mod error;5mod exec;6mod exit_codes;7mod filesystem;8mod filetypes;9mod filter;10mod output;11mod regex_helper;12mod walk;1314use std::env;

Merge pull request #1333 from tmccombs/rust-170Thayne McCombsbefore adoptiona0370aa

line 15why, one step back
15use std::io::IsTerminal;

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

line 16why, one step back
16use std::path::Path;

Compute colors in parallelTavian Barnesbefore adoption17d849d

lines 17–19why, one step back
17use std::sync::Arc;
18use std::time;19

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 20–21why, one step back
20use anyhow::{anyhow, bail, Context, Result};
21use clap::{CommandFactory, Parser};

Compute colors in parallelTavian Barnesbefore adoption17d849d

lines 22–23why, one step back
22use globset::GlobBuilder;
23use lscolors::LsColors;

Merge pull request #1139 from Uthar/masterDavid Peterbefore adoptionc9d3968

line 24why, one step back
24use regex::bytes::{Regex, RegexBuilder, RegexSetBuilder};

Compute colors in parallelTavian Barnesbefore adoption17d849d

line 25why, one step back
25

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

line 26why, one step back
26use crate::cli::{ColorWhen, Opts};

Compute colors in parallelTavian Barnesbefore adoption17d849d

lines 27–32why, one step back
27use crate::config::Config;
28use crate::exec::CommandSet;29use crate::exit_codes::ExitCode;30use crate::filetypes::FileTypes;31#[cfg(unix)]32use crate::filter::OwnerFilter;

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

line 33why, one step back
33use crate::filter::TimeFilter;

Compute colors in parallelTavian Barnesbefore adoption17d849d

lines 34–42why, one step back
34use crate::regex_helper::{pattern_has_uppercase_char, pattern_matches_strings_with_leading_dot};
3536// We use jemalloc for performance reasons, see https://github.com/sharkdp/fd/pull/48137// FIXME: re-enable jemalloc on macOS, see comment in Cargo.toml file for more infos38#[cfg(all(39 not(windows),40 not(target_os = "android"),41 not(target_os = "macos"),42 not(target_os = "freebsd"),

Don't use jemalloc on OpenBSD (jemalloc fails to compile)Nathan Houghtonbefore adoption42244e5

line 43why, one step back
43 not(target_os = "openbsd"),

Compute colors in parallelTavian Barnesbefore adoption17d849d

lines 44–70why, one step back
44 not(all(target_env = "musl", target_pointer_width = "32")),
45 not(target_arch = "riscv64"),46 feature = "use-jemalloc"47))]48#[global_allocator]49static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;5051// vivid --color-mode 8-bit generate molokai52const DEFAULT_LS_COLORS: &str = "53ow=0:or=0;38;5;16;48;5;203:no=0:ex=1;38;5;203:cd=0;38;5;203;48;5;236:mi=0;38;5;16;48;5;203:*~=0;38;5;243:st=0:pi=0;38;5;16;48;5;81:fi=0:di=0;38;5;81:so=0;38;5;16;48;5;203:bd=0;38;5;81;48;5;236:tw=0:ln=0;38;5;203:*.m=0;38;5;48:*.o=0;38;5;243:*.z=4;38;5;203:*.a=1;38;5;203:*.r=0;38;5;48:*.c=0;38;5;48:*.d=0;38;5;48:*.t=0;38;5;48:*.h=0;38;5;48:*.p=0;38;5;48:*.cc=0;38;5;48:*.ll=0;38;5;48:*.jl=0;38;5;48:*css=0;38;5;48:*.md=0;38;5;185:*.gz=4;38;5;203:*.nb=0;38;5;48:*.mn=0;38;5;48:*.go=0;38;5;48:*.xz=4;38;5;203:*.so=1;38;5;203:*.rb=0;38;5;48:*.pm=0;38;5;48:*.bc=0;38;5;243:*.py=0;38;5;48:*.as=0;38;5;48:*.pl=0;38;5;48:*.rs=0;38;5;48:*.sh=0;38;5;48:*.7z=4;38;5;203:*.ps=0;38;5;186:*.cs=0;38;5;48:*.el=0;38;5;48:*.rm=0;38;5;208:*.hs=0;38;5;48:*.td=0;38;5;48:*.ui=0;38;5;149:*.ex=0;38;5;48:*.js=0;38;5;48:*.cp=0;38;5;48:*.cr=0;38;5;48:*.la=0;38;5;243:*.kt=0;38;5;48:*.ml=0;38;5;48:*.vb=0;38;5;48:*.gv=0;38;5;48:*.lo=0;38;5;243:*.hi=0;38;5;243:*.ts=0;38;5;48:*.ko=1;38;5;203:*.hh=0;38;5;48:*.pp=0;38;5;48:*.di=0;38;5;48:*.bz=4;38;5;203:*.fs=0;38;5;48:*.png=0;38;5;208:*.zsh=0;38;5;48:*.mpg=0;38;5;208:*.pid=0;38;5;243:*.xmp=0;38;5;149:*.iso=4;38;5;203:*.m4v=0;38;5;208:*.dot=0;38;5;48:*.ods=0;38;5;186:*.inc=0;38;5;48:*.sxw=0;38;5;186:*.aif=0;38;5;208:*.git=0;38;5;243:*.gvy=0;38;5;48:*.tbz=4;38;5;203:*.log=0;38;5;243:*.txt=0;38;5;185:*.ico=0;38;5;208:*.csx=0;38;5;48:*.vob=0;38;5;208:*.pgm=0;38;5;208:*.pps=0;38;5;186:*.ics=0;38;5;186:*.img=4;38;5;203:*.fon=0;38;5;208:*.hpp=0;38;5;48:*.bsh=0;38;5;48:*.sql=0;38;5;48:*TODO=1:*.php=0;38;5;48:*.pkg=4;38;5;203:*.ps1=0;38;5;48:*.csv=0;38;5;185:*.ilg=0;38;5;243:*.ini=0;38;5;149:*.pyc=0;38;5;243:*.psd=0;38;5;208:*.htc=0;38;5;48:*.swp=0;38;5;243:*.mli=0;38;5;48:*hgrc=0;38;5;149:*.bst=0;38;5;149:*.ipp=0;38;5;48:*.fsi=0;38;5;48:*.tcl=0;38;5;48:*.exs=0;38;5;48:*.out=0;38;5;243:*.jar=4;38;5;203:*.xls=0;38;5;186:*.ppm=0;38;5;208:*.apk=4;38;5;203:*.aux=0;38;5;243:*.rpm=4;38;5;203:*.dll=1;38;5;203:*.eps=0;38;5;208:*.exe=1;38;5;203:*.doc=0;38;5;186:*.wma=0;38;5;208:*.deb=4;38;5;203:*.pod=0;38;5;48:*.ind=0;38;5;243:*.nix=0;38;5;149:*.lua=0;38;5;48:*.epp=0;38;5;48:*.dpr=0;38;5;48:*.htm=0;38;5;185:*.ogg=0;38;5;208:*.bin=4;38;5;203:*.otf=0;38;5;208:*.yml=0;38;5;149:*.pro=0;38;5;149:*.cxx=0;38;5;48:*.tex=0;38;5;48:*.fnt=0;38;5;208:*.erl=0;38;5;48:*.sty=0;38;5;243:*.bag=4;38;5;203:*.rst=0;38;5;185:*.pdf=0;38;5;186:*.pbm=0;38;5;208:*.xcf=0;38;5;208:*.clj=0;38;5;48:*.gif=0;38;5;208:*.rar=4;38;5;203:*.elm=0;38;5;48:*.bib=0;38;5;149:*.tsx=0;38;5;48:*.dmg=4;38;5;203:*.tmp=0;38;5;243:*.bcf=0;38;5;243:*.mkv=0;38;5;208:*.svg=0;38;5;208:*.cpp=0;38;5;48:*.vim=0;38;5;48:*.bmp=0;38;5;208:*.ltx=0;38;5;48:*.fls=0;38;5;243:*.flv=0;38;5;208:*.wav=0;38;5;208:*.m4a=0;38;5;208:*.mid=0;38;5;208:*.hxx=0;38;5;48:*.pas=0;38;5;48:*.wmv=0;38;5;208:*.tif=0;38;5;208:*.kex=0;38;5;186:*.mp4=0;38;5;208:*.bak=0;38;5;243:*.xlr=0;38;5;186:*.dox=0;38;5;149:*.swf=0;38;5;208:*.tar=4;38;5;203:*.tgz=4;38;5;203:*.cfg=0;38;5;149:*.xml=0;5438;5;185:*.jpg=0;38;5;208:*.mir=0;38;5;48:*.sxi=0;38;5;186:*.bz2=4;38;5;203:*.odt=0;38;5;186:*.mov=0;38;5;208:*.toc=0;38;5;243:*.bat=1;38;5;203:*.asa=0;38;5;48:*.awk=0;38;5;48:*.sbt=0;38;5;48:*.vcd=4;38;5;203:*.kts=0;38;5;48:*.arj=4;38;5;203:*.blg=0;38;5;243:*.c++=0;38;5;48:*.odp=0;38;5;186:*.bbl=0;38;5;243:*.idx=0;38;5;243:*.com=1;38;5;203:*.mp3=0;38;5;208:*.avi=0;38;5;208:*.def=0;38;5;48:*.cgi=0;38;5;48:*.zip=4;38;5;203:*.ttf=0;38;5;208:*.ppt=0;38;5;186:*.tml=0;38;5;149:*.fsx=0;38;5;48:*.h++=0;38;5;48:*.rtf=0;38;5;186:*.inl=0;38;5;48:*.yaml=0;38;5;149:*.html=0;38;5;185:*.mpeg=0;38;5;208:*.java=0;38;5;48:*.hgrc=0;38;5;149:*.orig=0;38;5;243:*.conf=0;38;5;149:*.dart=0;38;5;48:*.psm1=0;38;5;48:*.rlib=0;38;5;243:*.fish=0;38;5;48:*.bash=0;38;5;48:*.make=0;38;5;149:*.docx=0;38;5;186:*.json=0;38;5;149:*.psd1=0;38;5;48:*.lisp=0;38;5;48:*.tbz2=4;38;5;203:*.diff=0;38;5;48:*.epub=0;38;5;186:*.xlsx=0;38;5;186:*.pptx=0;38;5;186:*.toml=0;38;5;149:*.h264=0;38;5;208:*.purs=0;38;5;48:*.flac=0;38;5;208:*.tiff=0;38;5;208:*.jpeg=0;38;5;208:*.lock=0;38;5;243:*.less=0;38;5;48:*.dyn_o=0;38;5;243:*.scala=0;38;5;48:*.mdown=0;38;5;185:*.shtml=0;38;5;185:*.class=0;38;5;243:*.cache=0;38;5;243:*.cmake=0;38;5;149:*passwd=0;38;5;149:*.swift=0;38;5;48:*shadow=0;38;5;149:*.xhtml=0;38;5;185:*.patch=0;38;5;48:*.cabal=0;38;5;48:*README=0;38;5;16;48;5;186:*.toast=4;38;5;203:*.ipynb=0;38;5;48:*COPYING=0;38;5;249:*.gradle=0;38;5;48:*.matlab=0;38;5;48:*.config=0;38;5;149:*LICENSE=0;38;5;249:*.dyn_hi=0;38;5;243:*.flake8=0;38;5;149:*.groovy=0;38;5;48:*INSTALL=0;38;5;16;48;5;186:*TODO.md=1:*.ignore=0;38;5;149:*Doxyfile=0;38;5;149:*TODO.txt=1:*setup.py=0;38;5;149:*Makefile=0;38;5;149:*.gemspec=0;38;5;149:*.desktop=0;38;5;149:*.rgignore=0;38;5;149:*.markdown=0;38;5;185:*COPYRIGHT=0;38;5;249:*configure=0;38;5;149:*.DS_Store=0;38;5;243:*.kdevelop=0;38;5;149:*.fdignore=0;38;5;149:*README.md=0;38;5;16;48;5;186:*.cmake.in=0;38;5;149:*SConscript=0;38;5;149:*CODEOWNERS=0;38;5;149:*.localized=0;38;5;243:*.gitignore=0;38;5;149:*Dockerfile=0;38;5;149:*.gitconfig=0;38;5;149:*INSTALL.md=0;38;5;16;48;5;186:*README.txt=0;38;5;16;48;5;186:*SConstruct=0;38;5;149:*.scons_opt=0;38;5;243:*.travis.yml=0;38;5;186:*.gitmodules=0;38;5;149:*.synctex.gz=0;38;5;243:*LICENSE-MIT=0;38;5;249:*MANIFEST.in=0;38;5;149:*Makefile.in=0;38;5;243:*Makefile.am=0;38;5;149:*INSTALL.txt=0;38;5;16;48;5;186:*configure.ac=0;38;5;149:*.applescript=0;38;5;48:*appveyor.yml=0;38;5;186:*.fdb_latexmk=0;38;5;243:*CONTRIBUTORS=0;38;5;16;48;5;186:*.clang-format=0;38;5;149:*LICENSE-APACHE=0;38;5;249:*CMakeLists.txt=0;38;5;149:*CMakeCache.txt=0;38;5;243:*.gitattributes=0;38;5;149:*CONTRIBUTORS.md=0;38;5;16;48;5;186:*.sconsign.dblite=0;38;5;243:*requirements.txt=0;38;5;149:*CONTRIBUTORS.txt=0;38;5;16;48;5;186:*package-lock.json=0;38;5;243:*.CFUserTextEncoding=0;38;5;24355";5657fn main() {58 let result = run();59 match result {60 Ok(exit_code) => {61 exit_code.exit();62 }63 Err(err) => {64 eprintln!("[fd error]: {:#}", err);65 ExitCode::GeneralError.exit();66 }67 }68}6970fn run() -> Result<ExitCode> {

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

line 71why, one step back
71 let opts = Opts::parse();

Compute colors in parallelTavian Barnesbefore adoption17d849d

line 72why, one step back
72

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 73–76why, one step back
73 #[cfg(feature = "completions")]
74 if let Some(shell) = opts.gen_completions()? {75 return print_completions(shell);76 }

Compute colors in parallelTavian Barnesbefore adoption17d849d

line 77why, one step back
77

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 78–84why, one step back
78 set_working_dir(&opts)?;
79 let search_paths = opts.search_paths()?;80 if search_paths.is_empty() {81 bail!("No valid search paths given.");82 }8384 ensure_search_pattern_is_not_a_path(&opts)?;

Merge pull request #1139 from Uthar/masterDavid Peterbefore adoptionc9d3968

lines 85–87why, one step back
85 let pattern = &opts.pattern;
86 let exprs = &opts.exprs;87 let empty = Vec::new();

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

line 88why, one step back
88

Merge pull request #1139 from Uthar/masterDavid Peterbefore adoptionc9d3968

lines 89–105why, one step back
89 let pattern_regexps = exprs
90 .as_ref()91 .unwrap_or(&empty)92 .iter()93 .chain([pattern])94 .map(|pat| build_pattern_regex(pat, &opts))95 .collect::<Result<Vec<String>>>()?;9697 let config = construct_config(opts, &pattern_regexps)?;9899 ensure_use_hidden_option_for_leading_dot_pattern(&config, &pattern_regexps)?;100101 let regexps = pattern_regexps102 .into_iter()103 .map(|pat| build_regex(pat, &config))104 .collect::<Result<Vec<Regex>>>()?;105

walk: New WorkerState struct shared by the worker threadsTavian Barnesbefore adoption8bbbd76

line 106why, one step back
106 walk::scan(&search_paths, regexps, config)

Compute colors in parallelTavian Barnesbefore adoption17d849d

lines 107–108why, one step back
107}
108

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 109–112why, one step back
109#[cfg(feature = "completions")]
110#[cold]111fn print_completions(shell: clap_complete::Shell) -> Result<ExitCode> {112 // The program name is the first argument.

Merge pull request #1173 from zappolowski/fix-completion-program-nameThayne McCombsbefore adoptionce4e867

lines 113–116why, one step back
113 let first_arg = env::args().next();
114 let program_name = first_arg115 .as_ref()116 .map(Path::new)

Merge pull request #1178 from tmccombs/windows-completion-fixDavid Peterbefore adoptiondb2590d

line 117why, one step back
117 .and_then(|path| path.file_stem())

Merge pull request #1173 from zappolowski/fix-completion-program-nameThayne McCombsbefore adoptionce4e867

lines 118–119why, one step back
118 .and_then(|file| file.to_str())
119 .unwrap_or("fd");

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 120–121why, one step back
120 let mut cmd = Opts::command();
121 cmd.build();

Merge pull request #1173 from zappolowski/fix-completion-program-nameThayne McCombsbefore adoptionce4e867

line 122why, one step back
122 clap_complete::generate(shell, &mut cmd, program_name, &mut std::io::stdout());

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 123–127why, one step back
123 Ok(ExitCode::Success)
124}125126fn set_working_dir(opts: &Opts) -> Result<()> {127 if let Some(ref base_directory) = opts.base_directory {

Compute colors in parallelTavian Barnesbefore adoption17d849d

lines 128–144why, one step back
128 if !filesystem::is_existing_directory(base_directory) {
129 return Err(anyhow!(130 "The '--base-directory' path '{}' is not a directory.",131 base_directory.to_string_lossy()132 ));133 }134 env::set_current_dir(base_directory).with_context(|| {135 format!(136 "Could not set '{}' as the current working directory",137 base_directory.to_string_lossy()138 )139 })?;140 }141 Ok(())142}143144/// Detect if the user accidentally supplied a path instead of a search pattern

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 145–148why, one step back
145fn ensure_search_pattern_is_not_a_path(opts: &Opts) -> Result<()> {
146 if !opts.full_path147 && opts.pattern.contains(std::path::MAIN_SEPARATOR)148 && Path::new(&opts.pattern).is_dir()

Compute colors in parallelTavian Barnesbefore adoption17d849d

lines 149–156why, one step back
149 {
150 Err(anyhow!(151 "The search pattern '{pattern}' contains a path-separation character ('{sep}') \152 and will not lead to any search results.\n\n\153 If you want to search for all files inside the '{pattern}' directory, use a match-all pattern:\n\n \154 fd . '{pattern}'\n\n\155 Instead, if you want your pattern to match the full file path, use:\n\n \156 fd --full-path '{pattern}'",

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

line 157why, one step back
157 pattern = &opts.pattern,

Compute colors in parallelTavian Barnesbefore adoption17d849d

lines 158–164why, one step back
158 sep = std::path::MAIN_SEPARATOR,
159 ))160 } else {161 Ok(())162 }163}164

Merge pull request #1139 from Uthar/masterDavid Peterbefore adoptionc9d3968

line 165why, one step back
165fn build_pattern_regex(pattern: &str, opts: &Opts) -> Result<String> {

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

line 166why, one step back
166 Ok(if opts.glob && !pattern.is_empty() {

Compute colors in parallelTavian Barnesbefore adoption17d849d

lines 167–168why, one step back
167 let glob = GlobBuilder::new(pattern).literal_separator(true).build()?;
168 glob.regex().to_owned()

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

line 169why, one step back
169 } else if opts.fixed_strings {

Compute colors in parallelTavian Barnesbefore adoption17d849d

lines 170–190why, one step back
170 // Treat pattern as literal string if '--fixed-strings' is used
171 regex::escape(pattern)172 } else {173 String::from(pattern)174 })175}176177fn check_path_separator_length(path_separator: Option<&str>) -> Result<()> {178 match (cfg!(windows), path_separator) {179 (true, Some(sep)) if sep.len() > 1 => Err(anyhow!(180 "A path separator must be exactly one byte, but \181 the given separator is {} bytes: '{}'.\n\182 In some shells on Windows, '/' is automatically \183 expanded. Try to use '//' instead.",184 sep.len(),185 sep186 )),187 _ => Ok(()),188 }189}190

Merge pull request #1139 from Uthar/masterDavid Peterbefore adoptionc9d3968

line 191why, one step back
191fn construct_config(mut opts: Opts, pattern_regexps: &[String]) -> Result<Config> {

Compute colors in parallelTavian Barnesbefore adoption17d849d

line 192why, one step back
192 // The search will be case-sensitive if the command line flag is set or

Merge pull request #1139 from Uthar/masterDavid Peterbefore adoptionc9d3968

lines 193–198why, one step back
193 // if any of the patterns has an uppercase character (smart case).
194 let case_sensitive = !opts.ignore_case195 && (opts.case_sensitive196 || pattern_regexps197 .iter()198 .any(|pat| pattern_has_uppercase_char(pat)));

Compute colors in parallelTavian Barnesbefore adoption17d849d

line 199why, one step back
199

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 200–203why, one step back
200 let path_separator = opts
201 .path_separator202 .take()203 .or_else(filesystem::default_path_separator);

Compute colors in parallelTavian Barnesbefore adoption17d849d

lines 204–208why, one step back
204 let actual_path_separator = path_separator
205 .clone()206 .unwrap_or_else(|| std::path::MAIN_SEPARATOR.to_string());207 check_path_separator_length(path_separator.as_deref())?;208

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 209–210why, one step back
209 let size_limits = std::mem::take(&mut opts.size);
210 let time_constraints = extract_time_constraints(&opts)?;

Compute colors in parallelTavian Barnesbefore adoption17d849d

line 211why, one step back
211 #[cfg(unix)]

Merge pull request #1164 from tmccombs/owner-without-panicDavid Peterbefore adoption99d1db8

line 212why, one step back
212 let owner_constraint: Option<OwnerFilter> = opts.owner.and_then(OwnerFilter::filter_ignore);

Compute colors in parallelTavian Barnesbefore adoption17d849d

lines 213–215why, one step back
213
214 #[cfg(windows)]215 let ansi_colors_support =

Merge pull request #1192 from tmccombs/ansi-term-deprecatedTavian Barnesbefore adoption6e3eb26

line 216why, one step back
216 nu_ansi_term::enable_ansi_support().is_ok() || std::env::var_os("TERM").is_some();

Compute colors in parallelTavian Barnesbefore adoption17d849d

lines 217–219why, one step back
217 #[cfg(not(windows))]
218 let ansi_colors_support = true;219

Merge pull request #1333 from tmccombs/rust-170Thayne McCombsbefore adoptiona0370aa

line 220why, one step back
220 let interactive_terminal = std::io::stdout().is_terminal();

Merge pull request #1421 from acuteenvy/fix-no-colorTavian Barnesbefore adoptiond62bbbb

line 221why, one step back
221

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 222–225why, one step back
222 let colored_output = match opts.color {
223 ColorWhen::Always => true,224 ColorWhen::Never => false,225 ColorWhen::Auto => {

Merge pull request #1421 from acuteenvy/fix-no-colorTavian Barnesbefore adoptiond62bbbb

lines 226–227why, one step back
226 let no_color = env::var_os("NO_COLOR").is_some_and(|x| !x.is_empty());
227 ansi_colors_support && !no_color && interactive_terminal

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

line 228why, one step back
228 }

Compute colors in parallelTavian Barnesbefore adoption17d849d

lines 229–235why, one step back
229 };
230231 let ls_colors = if colored_output {232 Some(LsColors::from_env().unwrap_or_else(|| LsColors::from_string(DEFAULT_LS_COLORS)))233 } else {234 None235 };

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 236–237why, one step back
236 let command = extract_command(&mut opts, colored_output)?;
237 let has_command = command.is_some();

Compute colors in parallelTavian Barnesbefore adoption17d849d

lines 238–240why, one step back
238
239 Ok(Config {240 case_sensitive,

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 241–244why, one step back
241 search_full_path: opts.full_path,
242 ignore_hidden: !(opts.hidden || opts.rg_alias_ignore()),243 read_fdignore: !(opts.no_ignore || opts.rg_alias_ignore()),244 read_vcsignore: !(opts.no_ignore || opts.rg_alias_ignore() || opts.no_ignore_vcs),

Merge pull request #1216 from vegerot/pr1216David Peterbefore adoptionaf9daff

line 245why, one step back
245 require_git_to_read_vcsignore: !opts.no_require_git,

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

line 246why, one step back
246 read_parent_ignore: !opts.no_ignore_parent,

Merge pull request #1211 from tmccombs/fix-global-ignoreThayne McCombsbefore adoption7c86c7d

lines 247–249why, one step back
247 read_global_ignore: !(opts.no_ignore
248 || opts.rg_alias_ignore()249 || opts.no_global_ignore_file),

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 250–256why, one step back
250 follow_links: opts.follow,
251 one_file_system: opts.one_file_system,252 null_separator: opts.null_separator,253 quiet: opts.quiet,254 max_depth: opts.max_depth(),255 min_depth: opts.min_depth(),256 prune: opts.prune,

Merge pull request #1410 from tmccombs/available-parallelismThayne McCombsbefore adoptionc96b1af

line 257why, one step back
257 threads: opts.threads().get(),

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

line 258why, one step back
258 max_buffer_time: opts.max_buffer_time,

Compute colors in parallelTavian Barnesbefore adoption17d849d

lines 259–260why, one step back
259 ls_colors,
260 interactive_terminal,

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 261–262why, one step back
261 file_types: opts.filetype.as_ref().map(|values| {
262 use crate::cli::FileType::*;

Compute colors in parallelTavian Barnesbefore adoption17d849d

lines 263–265why, one step back
263 let mut file_types = FileTypes::default();
264 for value in values {265 match value {

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 266–269why, one step back
266 File => file_types.files = true,
267 Directory => file_types.directories = true,268 Symlink => file_types.symlinks = true,269 Executable => {

Compute colors in parallelTavian Barnesbefore adoption17d849d

lines 270–272why, one step back
270 file_types.executables_only = true;
271 file_types.files = true;272 }

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

line 273why, one step back
273 Empty => file_types.empty_only = true,

Support character and block device file typesChristian Göttschebefore adoption36bc840

lines 274–275why, one step back
274 BlockDevice => file_types.block_devices = true,
275 CharDevice => file_types.char_devices = true,

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 276–277why, one step back
276 Socket => file_types.sockets = true,
277 Pipe => file_types.pipes = true,

Compute colors in parallelTavian Barnesbefore adoption17d849d

lines 278–288why, one step back
278 }
279 }280281 // If only 'empty' was specified, search for both files and directories:282 if file_types.empty_only && !(file_types.files || file_types.directories) {283 file_types.files = true;284 file_types.directories = true;285 }286287 file_types288 }),

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 289–291why, one step back
289 extensions: opts
290 .extensions291 .as_ref()

Compute colors in parallelTavian Barnesbefore adoption17d849d

lines 292–293why, one step back
292 .map(|exts| {
293 let patterns = exts

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

line 294why, one step back
294 .iter()

Compute colors in parallelTavian Barnesbefore adoption17d849d

lines 295–302why, one step back
295 .map(|e| e.trim_start_matches('.'))
296 .map(|e| format!(r".\.{}$", regex::escape(e)));297 RegexSetBuilder::new(patterns)298 .case_insensitive(true)299 .build()300 })301 .transpose()?,302 command: command.map(Arc::new),

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 303–305why, one step back
303 batch_size: opts.batch_size,
304 exclude_patterns: opts.exclude.iter().map(|p| String::from("!") + p).collect(),305 ignore_files: std::mem::take(&mut opts.ignore_file),

Compute colors in parallelTavian Barnesbefore adoption17d849d

lines 306–309why, one step back
306 size_constraints: size_limits,
307 time_constraints,308 #[cfg(unix)]309 owner_constraint,

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

line 310why, one step back
310 show_filesystem_errors: opts.show_errors,

Compute colors in parallelTavian Barnesbefore adoption17d849d

lines 311–312why, one step back
311 path_separator,
312 actual_path_separator,

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 313–315why, one step back
313 max_results: opts.max_results(),
314 strip_cwd_prefix: (opts.no_search_paths()315 && (opts.strip_cwd_prefix || !(opts.null_separator || has_command))),

Compute colors in parallelTavian Barnesbefore adoption17d849d

lines 316–318why, one step back
316 })
317}318

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 319–327why, one step back
319fn extract_command(opts: &mut Opts, colored_output: bool) -> Result<Option<CommandSet>> {
320 opts.exec321 .command322 .take()323 .map(Ok)324 .or_else(|| {325 if !opts.list_details {326 return None;327 }

Compute colors in parallelTavian Barnesbefore adoption17d849d

line 328why, one step back
328

fix: Respect NO_COLOR with --list-details optionThayne McCombsbefore adoption9529f30

line 329why, one step back
329 let res = determine_ls_command(colored_output)

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

lines 330–333why, one step back
330 .map(|cmd| CommandSet::new_batch([cmd]).unwrap());
331 Some(res)332 })333 .transpose()

Compute colors in parallelTavian Barnesbefore adoption17d849d

lines 334–335why, one step back
334}
335

fix: Respect NO_COLOR with --list-details optionThayne McCombsbefore adoption9529f30

line 336why, one step back
336fn determine_ls_command(colored_output: bool) -> Result<Vec<&'static str>> {

Compute colors in parallelTavian Barnesbefore adoption17d849d

lines 337–338why, one step back
337 #[allow(unused)]
338 let gnu_ls = |command_name| {

fix: Respect NO_COLOR with --list-details optionThayne McCombsbefore adoption9529f30

lines 339–343why, one step back
339 let color_arg = if colored_output {
340 "--color=always"341 } else {342 "--color=never"343 };

Compute colors in parallelTavian Barnesbefore adoption17d849d

lines 344–419why, one step back
344 // Note: we use short options here (instead of --long-options) to support more
345 // platforms (like BusyBox).346 vec![347 command_name,348 "-l", // long listing format349 "-h", // human readable file sizes350 "-d", // list directories themselves, not their contents351 color_arg,352 ]353 };354 let cmd: Vec<&str> = if cfg!(unix) {355 if !cfg!(any(356 target_os = "macos",357 target_os = "dragonfly",358 target_os = "freebsd",359 target_os = "netbsd",360 target_os = "openbsd"361 )) {362 // Assume ls is GNU ls363 gnu_ls("ls")364 } else {365 // MacOS, DragonFlyBSD, FreeBSD366 use std::process::{Command, Stdio};367368 // Use GNU ls, if available (support for --color=auto, better LS_COLORS support)369 let gnu_ls_exists = Command::new("gls")370 .arg("--version")371 .stdout(Stdio::null())372 .stderr(Stdio::null())373 .status()374 .is_ok();375376 if gnu_ls_exists {377 gnu_ls("gls")378 } else {379 let mut cmd = vec![380 "ls", // BSD version of ls381 "-l", // long listing format382 "-h", // '--human-readable' is not available, '-h' is383 "-d", // '--directory' is not available, but '-d' is384 ];385386 if !cfg!(any(target_os = "netbsd", target_os = "openbsd")) && colored_output {387 // -G is not available in NetBSD's and OpenBSD's ls388 cmd.push("-G");389 }390391 cmd392 }393 }394 } else if cfg!(windows) {395 use std::process::{Command, Stdio};396397 // Use GNU ls, if available398 let gnu_ls_exists = Command::new("ls")399 .arg("--version")400 .stdout(Stdio::null())401 .stderr(Stdio::null())402 .status()403 .is_ok();404405 if gnu_ls_exists {406 gnu_ls("ls")407 } else {408 return Err(anyhow!(409 "'fd --list-details' is not supported on Windows unless GNU 'ls' is installed."410 ));411 }412 } else {413 return Err(anyhow!(414 "'fd --list-details' is not supported on this platform."415 ));416 };417 Ok(cmd)418}419

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

line 420why, one step back
420fn extract_time_constraints(opts: &Opts) -> Result<Vec<TimeFilter>> {

Compute colors in parallelTavian Barnesbefore adoption17d849d

lines 421–422why, one step back
421 let now = time::SystemTime::now();
422 let mut time_constraints: Vec<TimeFilter> = Vec::new();

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

line 423why, one step back
423 if let Some(ref t) = opts.changed_within {

Compute colors in parallelTavian Barnesbefore adoption17d849d

lines 424–432why, one step back
424 if let Some(f) = TimeFilter::after(&now, t) {
425 time_constraints.push(f);426 } else {427 return Err(anyhow!(428 "'{}' is not a valid date or duration. See 'fd --help'.",429 t430 ));431 }432 }

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

line 433why, one step back
433 if let Some(ref t) = opts.changed_before {

Compute colors in parallelTavian Barnesbefore adoption17d849d

lines 434–447why, one step back
434 if let Some(f) = TimeFilter::before(&now, t) {
435 time_constraints.push(f);436 } else {437 return Err(anyhow!(438 "'{}' is not a valid date or duration. See 'fd --help'.",439 t440 ));441 }442 }443 Ok(time_constraints)444}445446fn ensure_use_hidden_option_for_leading_dot_pattern(447 config: &Config,

Merge pull request #1139 from Uthar/masterDavid Peterbefore adoptionc9d3968

line 448why, one step back
448 pattern_regexps: &[String],

Compute colors in parallelTavian Barnesbefore adoption17d849d

line 449why, one step back
449) -> Result<()> {

Merge pull request #1139 from Uthar/masterDavid Peterbefore adoptionc9d3968

lines 450–454why, one step back
450 if cfg!(unix)
451 && config.ignore_hidden452 && pattern_regexps453 .iter()454 .any(|pat| pattern_matches_strings_with_leading_dot(pat))

Compute colors in parallelTavian Barnesbefore adoption17d849d

lines 455–456why, one step back
455 {
456 Err(anyhow!(

Merge pull request #1139 from Uthar/masterDavid Peterbefore adoptionc9d3968

line 457why, one step back
457 "The pattern(s) seems to only match files with a leading dot, but hidden files are \

Compute colors in parallelTavian Barnesbefore adoption17d849d

line 458why, one step back
458 filtered by default. Consider adding -H/--hidden to search hidden files as well \

Merge pull request #1139 from Uthar/masterDavid Peterbefore adoptionc9d3968

line 459why, one step back
459 or adjust your search pattern(s)."

Compute colors in parallelTavian Barnesbefore adoption17d849d

lines 460–479why, one step back
460 ))
461 } else {462 Ok(())463 }464}465466fn build_regex(pattern_regex: String, config: &Config) -> Result<regex::bytes::Regex> {467 RegexBuilder::new(&pattern_regex)468 .case_insensitive(!config.case_sensitive)469 .dot_matches_new_line(true)470 .build()471 .map_err(|e| {472 anyhow!(473 "{}\n\nNote: You can use the '--fixed-strings' option to search for a \474 literal string instead of a regular expression. Alternatively, you can \475 also use the '--glob' option to match on a glob pattern.",476 e.to_string()477 )478 })479}