Skip to content
Myr

cli.rs

This file

Path

src/cli.rs

876 lines · 31.1 KiB · Rust

Last changed by

Add test for gitignore workaroundThayne McCombsbefore adoption6647085

History of this file

Take it

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

line 1why, one step back
1use std::num::NonZeroUsize;

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

lines 2–22why, one step back
2use std::path::{Path, PathBuf};
3use std::time::Duration;45use anyhow::anyhow;6use clap::{7 error::ErrorKind, value_parser, Arg, ArgAction, ArgGroup, ArgMatches, Command, Parser,8 ValueEnum,9};10#[cfg(feature = "completions")]11use clap_complete::Shell;12use normpath::PathExt;1314use crate::error::print_error;15use crate::exec::CommandSet;16use crate::filesystem;17#[cfg(unix)]18use crate::filter::OwnerFilter;19use crate::filter::SizeFilter;2021#[derive(Parser)]22#[command(

Change clap CLI binary name to 'fd'David Peterbefore adoptionac35b11

line 23why, one step back
23 name = "fd",

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

line 24why, one step back
24 version,

Add simple 'about' textDavid Peterbefore adoption7f5bc98

line 25why, one step back
25 about = "A program to find entries in your filesystem",

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

line 26why, one step back
26 after_long_help = "Bugs can be reported on GitHub: https://github.com/sharkdp/fd/issues",

Set max. term width to make help texts easier to readDavid Peterbefore adoption70c4865

line 27why, one step back
27 max_term_width = 98,

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

lines 28–29why, one step back
28 args_override_self = true,
29 group(ArgGroup::new("execs").args(&["exec", "exec_batch", "list_details"]).conflicts_with_all(&[

Merge pull request #1398 from tmccombs/clap-updateThayne McCombsbefore adoptionb8e7cbd

line 30why, one step back
30 "max_results", "quiet", "max_one_result"])),

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

lines 31–32why, one step back
31)]
32pub struct Opts {

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 33–35why, one step back
33 /// Include hidden directories and files in the search results (default:
34 /// hidden files and directories are skipped). Files and directories are35 /// considered to be hidden if their name starts with a `.` sign (dot).

docs: Document exclusion of .git/Thayne McCombsbefore adoption53fd416

lines 36–37why, one step back
36 /// Any files or directories that are ignored due to the rules described by
37 /// --no-ignore are still ignored unless otherwise specified.

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

line 38why, one step back
38 /// The flag can be overridden with --no-hidden.

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

lines 39–41why, one step back
39 #[arg(
40 long,41 short = 'H',

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 42–43why, one step back
42 help = "Search hidden files and directories",
43 long_help

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

lines 44–46why, one step back
44 )]
45 pub hidden: bool,46

Merge pull request #1170 from tmccombs/clap-improvements-2Thayne McCombsbefore adoption85e3ada

lines 47–50why, one step back
47 /// Overrides --hidden
48 #[arg(long, overrides_with = "hidden", hide = true, action = ArgAction::SetTrue)]49 no_hidden: (),50

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

line 51why, one step back
51 /// Show search results from files and directories that would otherwise be

Merge pull request #1540 from tmccombs/revert-git-ignoreThayne McCombsbefore adoption31f2839

line 52why, one step back
52 /// ignored by '.gitignore', '.ignore', '.fdignore', or the global ignore file,

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

line 53why, one step back
53 /// The flag can be overridden with --ignore.

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

lines 54–56why, one step back
54 #[arg(
55 long,56 short = 'I',

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 57–58why, one step back
57 help = "Do not respect .(git|fd)ignore files",
58 long_help

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

lines 59–61why, one step back
59 )]
60 pub no_ignore: bool,61

Merge pull request #1170 from tmccombs/clap-improvements-2Thayne McCombsbefore adoption85e3ada

lines 62–65why, one step back
62 /// Overrides --no-ignore
63 #[arg(long, overrides_with = "no_ignore", hide = true, action = ArgAction::SetTrue)]64 ignore: (),65

Merge pull request #1540 from tmccombs/revert-git-ignoreThayne McCombsbefore adoption31f2839

line 66why, one step back
66 ///Show search results from files and directories that

docs: Some tweaks from reviewThayne McCombsbefore adoption08910e4

lines 67–68why, one step back
67 ///would otherwise be ignored by '.gitignore' files.
68 ///The flag can be overridden with --ignore-vcs.

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

lines 69–71why, one step back
69 #[arg(
70 long,71 hide_short_help = true,

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 72–73why, one step back
72 help = "Do not respect .gitignore files",
73 long_help

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

lines 74–76why, one step back
74 )]
75 pub no_ignore_vcs: bool,76

Merge pull request #1170 from tmccombs/clap-improvements-2Thayne McCombsbefore adoption85e3ada

lines 77–80why, one step back
77 /// Overrides --no-ignore-vcs
78 #[arg(long, overrides_with = "no_ignore_vcs", hide = true, action = ArgAction::SetTrue)]79 ignore_vcs: (),80

Merge pull request #1216 from vegerot/pr1216David Peterbefore adoptionaf9daff

lines 81–102why, one step back
81 /// Do not require a git repository to respect gitignores.
82 /// By default, fd will only respect global gitignore rules, .gitignore rules,83 /// and local exclude rules if fd detects that you are searching inside a84 /// git repository. This flag allows you to relax this restriction such that85 /// fd will respect all git related ignore rules regardless of whether you're86 /// searching in a git repository or not.87 ///88 ///89 /// This flag can be disabled with --require-git.90 #[arg(91 long,92 overrides_with = "require_git",93 hide_short_help = true,94 // same description as ripgrep's flag: ripgrep/crates/core/app.rs95 long_help96 )]97 pub no_require_git: bool,9899 /// Overrides --no-require-git100 #[arg(long, overrides_with = "no_require_git", hide = true, action = ArgAction::SetTrue)]101 require_git: (),102

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 103–104why, one step back
103 /// Show search results from files and directories that would otherwise be
104 /// ignored by '.gitignore', '.ignore', or '.fdignore' files in parent directories.

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

lines 105–107why, one step back
105 #[arg(
106 long,107 hide_short_help = true,

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 108–109why, one step back
108 help = "Do not respect .(git|fd)ignore files in parent directories",
109 long_help

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

lines 110–116why, one step back
110 )]
111 pub no_ignore_parent: bool,112113 /// Do not respect the global ignore file114 #[arg(long, hide = true)]115 pub no_global_ignore_file: bool,116

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 117–118why, one step back
117 /// Perform an unrestricted search, including ignored and hidden files. This is
118 /// an alias for '--no-ignore --hidden'.

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

line 119why, one step back
119 #[arg(long = "unrestricted", short = 'u', overrides_with_all(&["ignore", "no_hidden"]), action(ArgAction::Count), hide_short_help = true,

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 120–121why, one step back
120 help = "Unrestricted search, alias for '--no-ignore --hidden'",
121 long_help,

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

lines 122–135why, one step back
122 )]
123 rg_alias_hidden_ignore: u8,124125 /// Case-sensitive search (default: smart case)126 #[arg(127 long,128 short = 's',129 overrides_with("ignore_case"),130 long_help = "Perform a case-sensitive search. By default, fd uses case-insensitive \131 searches, unless the pattern contains an uppercase character (smart \132 case)."133 )]134 pub case_sensitive: bool,135

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 136–138why, one step back
136 /// Perform a case-insensitive search. By default, fd uses case-insensitive
137 /// searches, unless the pattern contains an uppercase character (smart138 /// case).

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

lines 139–142why, one step back
139 #[arg(
140 long,141 short = 'i',142 overrides_with("case_sensitive"),

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 143–144why, one step back
143 help = "Case-insensitive search (default: smart case)",
144 long_help

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

lines 145–147why, one step back
145 )]
146 pub ignore_case: bool,147

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

line 148why, one step back
148 /// Perform a glob-based search instead of a regular expression search.

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

lines 149–152why, one step back
149 #[arg(
150 long,151 short = 'g',152 conflicts_with("fixed_strings"),

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 153–154why, one step back
153 help = "Glob-based search (default: regular expression)",
154 long_help

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

lines 155–157why, one step back
155 )]
156 pub glob: bool,157

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 158–159why, one step back
158 /// Perform a regular-expression based search (default). This can be used to
159 /// override --glob.

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

lines 160–163why, one step back
160 #[arg(
161 long,162 overrides_with("glob"),163 hide_short_help = true,

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 164–165why, one step back
164 help = "Regular-expression based search (default)",
165 long_help

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

lines 166–168why, one step back
166 )]
167 pub regex: bool,168

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 169–171why, one step back
169 /// Treat the pattern as a literal string instead of a regular expression. Note
170 /// that this also performs substring comparison. If you want to match on an171 /// exact filename, consider using '--glob'.

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

lines 172–176why, one step back
172 #[arg(
173 long,174 short = 'F',175 alias = "literal",176 hide_short_help = true,

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 177–178why, one step back
177 help = "Treat pattern as literal string stead of regex",
178 long_help

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

lines 179–181why, one step back
179 )]
180 pub fixed_strings: bool,181

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 182–184why, one step back
182 /// Add additional required search patterns, all of which must be matched. Multiple
183 /// additional patterns can be specified. The patterns are regular184 /// expressions, unless '--glob' or '--fixed-strings' is used.

Merge pull request #1139 from Uthar/masterDavid Peterbefore adoptionc9d3968

lines 185–187why, one step back
185 #[arg(
186 long = "and",187 value_name = "pattern",

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 188–189why, one step back
188 help = "Additional search patterns that need to be matched",
189 long_help,

Merge pull request #1139 from Uthar/masterDavid Peterbefore adoptionc9d3968

lines 190–194why, one step back
190 hide_short_help = true,
191 allow_hyphen_values = true192 )]193 pub exprs: Option<Vec<String>>,194

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 195–196why, one step back
195 /// Shows the full path starting from the root as opposed to relative paths.
196 /// The flag can be overridden with --relative-path.

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

lines 197–199why, one step back
197 #[arg(
198 long,199 short = 'a',

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 200–201why, one step back
200 help = "Show absolute instead of relative paths",
201 long_help

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

lines 202–204why, one step back
202 )]
203 pub absolute_path: bool,204

Merge pull request #1170 from tmccombs/clap-improvements-2Thayne McCombsbefore adoption85e3ada

lines 205–208why, one step back
205 /// Overrides --absolute-path
206 #[arg(long, overrides_with = "absolute_path", hide = true, action = ArgAction::SetTrue)]207 relative_path: (),208

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 209–212why, one step back
209 /// Use a detailed listing format like 'ls -l'. This is basically an alias
210 /// for '--exec-batch ls -l' with some additional 'ls' options. This can be211 /// used to see more metadata, to show symlink targets and to achieve a212 /// deterministic sort order.

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

lines 213–216why, one step back
213 #[arg(
214 long,215 short = 'l',216 conflicts_with("absolute_path"),

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 217–218why, one step back
217 help = "Use a long listing format with file metadata",
218 long_help

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

lines 219–228why, one step back
219 )]
220 pub list_details: bool,221222 /// Follow symbolic links223 #[arg(224 long,225 short = 'L',226 alias = "dereference",227 long_help = "By default, fd does not descend into symlinked directories. Using this \228 flag, symbolic links are also traversed. \

Merge pull request #1409 from marcospb19/fix-docs-typoThayne McCombsbefore adoption8b5532d

line 229why, one step back
229 Flag can be overridden with --no-follow."

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

lines 230–232why, one step back
230 )]
231 pub follow: bool,232

Merge pull request #1170 from tmccombs/clap-improvements-2Thayne McCombsbefore adoption85e3ada

lines 233–236why, one step back
233 /// Overrides --follow
234 #[arg(long, overrides_with = "follow", hide = true, action = ArgAction::SetTrue)]235 no_follow: (),236

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 237–238why, one step back
237 /// By default, the search pattern is only matched against the filename (or directory name). Using this flag, the pattern is matched against the full (absolute) path. Example:
238 /// fd --glob -p '**/.git/config'

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

lines 239–241why, one step back
239 #[arg(
240 long,241 short = 'p',

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 242–244why, one step back
242 help = "Search full abs. path (default: filename only)",
243 long_help,244 verbatim_doc_comment

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

lines 245–247why, one step back
245 )]
246 pub full_path: bool,247

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 248–249why, one step back
248 /// Separate search results by the null character (instead of newlines).
249 /// Useful for piping results to 'xargs'.

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

lines 250–254why, one step back
250 #[arg(
251 long = "print0",252 short = '0',253 conflicts_with("list_details"),254 hide_short_help = true,

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 255–256why, one step back
255 help = "Separate search results by the null character",
256 long_help

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

lines 257–259why, one step back
257 )]
258 pub null_separator: bool,259

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 260–261why, one step back
260 /// Limit the directory traversal to a given depth. By default, there is no
261 /// limit on the search depth.

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

lines 262–266why, one step back
262 #[arg(
263 long,264 short = 'd',265 value_name = "depth",266 alias("maxdepth"),

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 267–268why, one step back
267 help = "Set maximum search depth (default: none)",
268 long_help

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

lines 269–272why, one step back
269 )]
270 max_depth: Option<usize>,271272 /// Only show search results starting at the given depth.

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

line 273why, one step back
273 /// See also: '--max-depth' and '--exact-depth'

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

lines 274–277why, one step back
274 #[arg(
275 long,276 value_name = "depth",277 hide_short_help = true,

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 278–279why, one step back
278 help = "Only show search results starting at the given depth.",
279 long_help

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

lines 280–282why, one step back
280 )]
281 min_depth: Option<usize>,282

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 283–284why, one step back
283 /// Only show search results at the exact given depth. This is an alias for
284 /// '--min-depth <depth> --max-depth <depth>'.

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

line 285why, one step back
285 #[arg(long, value_name = "depth", hide_short_help = true, conflicts_with_all(&["max_depth", "min_depth"]),

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 286–287why, one step back
286 help = "Only show search results at the exact given depth",
287 long_help,

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

lines 288–290why, one step back
288 )]
289 exact_depth: Option<usize>,290

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 291–297why, one step back
291 /// Exclude files/directories that match the given glob pattern. This
292 /// overrides any other ignore logic. Multiple exclude patterns can be293 /// specified.294 ///295 /// Examples:296 /// {n} --exclude '*.pyc'297 /// {n} --exclude node_modules

Reorder command line optionsDavid Peterbefore adoption12165c7

lines 298–301why, one step back
298 #[arg(
299 long,300 short = 'E',301 value_name = "pattern",

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 302–303why, one step back
302 help = "Exclude entries that match the given glob pattern",
303 long_help

Reorder command line optionsDavid Peterbefore adoption12165c7

lines 304–306why, one step back
304 )]
305 pub exclude: Vec<String>,306

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

lines 307–309why, one step back
307 /// Do not traverse into directories that match the search criteria. If
308 /// you want to exclude specific directories, use the '--exclude=…' option.309 #[arg(long, hide_short_help = true, conflicts_with_all(&["size", "exact_depth"]),

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

line 310why, one step back
310 long_help,

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

lines 311–313why, one step back
311 )]
312 pub prune: bool,313

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 314–315why, one step back
314 /// Filter the search by type:
315 /// {n} 'f' or 'file': regular files

Merge pull request #1464 from Ato2207/dir_aliasThayne McCombsbefore adoption14ed023

line 316why, one step back
316 /// {n} 'd' or 'dir' or 'directory': directories

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 317–319why, one step back
317 /// {n} 'l' or 'symlink': symbolic links
318 /// {n} 's' or 'socket': socket319 /// {n} 'p' or 'pipe': named pipe (FIFO)

Support character and block device file typesChristian Göttschebefore adoption36bc840

lines 320–321why, one step back
320 /// {n} 'b' or 'block-device': block device
321 /// {n} 'c' or 'char-device': character device

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 322–347why, one step back
322 /// {n}{n} 'x' or 'executable': executables
323 /// {n} 'e' or 'empty': empty files or directories324 ///325 /// This option can be specified more than once to include multiple file types.326 /// Searching for '--type file --type symlink' will show both regular files as327 /// well as symlinks. Note that the 'executable' and 'empty' filters work differently:328 /// '--type executable' implies '--type file' by default. And '--type empty' searches329 /// for empty files and directories, unless either '--type file' or '--type directory'330 /// is specified in addition.331 ///332 /// Examples:333 /// {n} - Only search for files:334 /// {n} fd --type file …335 /// {n} fd -tf …336 /// {n} - Find both files and symlinks337 /// {n} fd --type file --type symlink …338 /// {n} fd -tf -tl …339 /// {n} - Find executable files:340 /// {n} fd --type executable341 /// {n} fd -tx342 /// {n} - Find empty files:343 /// {n} fd --type empty --type file344 /// {n} fd -te -tf345 /// {n} - Find empty directories:346 /// {n} fd --type empty --type directory347 /// {n} fd -te -td

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

lines 348–353why, one step back
348 #[arg(
349 long = "type",350 short = 't',351 value_name = "filetype",352 hide_possible_values = true,353 value_enum,

Merge pull request #1464 from Ato2207/dir_aliasThayne McCombsbefore adoption14ed023

line 354why, one step back
354 help = "Filter by type: file (f), directory (d/dir), symlink (l), \

Support character and block device file typesChristian Göttschebefore adoption36bc840

lines 355–356why, one step back
355 executable (x), empty (e), socket (s), pipe (p), \
356 char-device (c), block-device (b)",

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

line 357why, one step back
357 long_help

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

lines 358–360why, one step back
358 )]
359 pub filetype: Option<Vec<FileType>>,360

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 361–365why, one step back
361 /// (Additionally) filter search results by their file extension. Multiple
362 /// allowable file extensions can be specified.363 ///364 /// If you want to search for files without extension,365 /// you can use the regex '^[^.]+$' as a normal search pattern.

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

lines 366–369why, one step back
366 #[arg(
367 long = "extension",368 short = 'e',369 value_name = "ext",

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 370–371why, one step back
370 help = "Filter by file extension",
371 long_help

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

lines 372–374why, one step back
372 )]
373 pub extensions: Option<Vec<String>>,374

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 375–391why, one step back
375 /// Limit results based on the size of files using the format <+-><NUM><UNIT>.
376 /// '+': file size must be greater than or equal to this377 /// '-': file size must be less than or equal to this378 ///379 /// If neither '+' nor '-' is specified, file size must be exactly equal to this.380 /// 'NUM': The numeric size (e.g. 500)381 /// 'UNIT': The units for NUM. They are not case-sensitive.382 /// Allowed unit values:383 /// 'b': bytes384 /// 'k': kilobytes (base ten, 10^3 = 1000 bytes)385 /// 'm': megabytes386 /// 'g': gigabytes387 /// 't': terabytes388 /// 'ki': kibibytes (base two, 2^10 = 1024 bytes)389 /// 'mi': mebibytes390 /// 'gi': gibibytes391 /// 'ti': tebibytes

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

line 392why, one step back
392 #[arg(long, short = 'S', value_parser = SizeFilter::from_string, allow_hyphen_values = true, verbatim_doc_comment, value_name = "size",

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 393–395why, one step back
393 help = "Limit results based on the size of files",
394 long_help,395 verbatim_doc_comment,

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

lines 396–398why, one step back
396 )]
397 pub size: Vec<SizeFilter>,398

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 399–409why, one step back
399 /// Filter results based on the file modification time. Files with modification times
400 /// greater than the argument are returned. The argument can be provided401 /// as a specific point in time (YYYY-MM-DD HH:MM:SS) or as a duration (10h, 1d, 35min).402 /// If the time is not specified, it defaults to 00:00:00.403 /// '--change-newer-than', '--newer', or '--changed-after' can be used as aliases.404 ///405 /// Examples:406 /// {n} --changed-within 2weeks407 /// {n} --change-newer-than '2018-10-27 10:00:00'408 /// {n} --newer 2018-10-27409 /// {n} --changed-after 1day

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

lines 410–413why, one step back
410 #[arg(
411 long,412 alias("change-newer-than"),413 alias("newer"),

Merge pull request #1176 from tmccombs/changed-afterDavid Peterbefore adoption8dda499

line 414why, one step back
414 alias("changed-after"),

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

line 415why, one step back
415 value_name = "date|dur",

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 416–417why, one step back
416 help = "Filter by file modification time (newer than)",
417 long_help

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

lines 418–420why, one step back
418 )]
419 pub changed_within: Option<String>,420

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 421–429why, one step back
421 /// Filter results based on the file modification time. Files with modification times
422 /// less than the argument are returned. The argument can be provided423 /// as a specific point in time (YYYY-MM-DD HH:MM:SS) or as a duration (10h, 1d, 35min).424 /// '--change-older-than' or '--older' can be used as aliases.425 ///426 /// Examples:427 /// {n} --changed-before '2018-10-27 10:00:00'428 /// {n} --change-older-than 2weeks429 /// {n} --older 2018-10-27

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

lines 430–434why, one step back
430 #[arg(
431 long,432 alias("change-older-than"),433 alias("older"),434 value_name = "date|dur",

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 435–436why, one step back
435 help = "Filter by file modification time (older than)",
436 long_help

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

lines 437–439why, one step back
437 )]
438 pub changed_before: Option<String>,439

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 440–447why, one step back
440 /// Filter files by their user and/or group.
441 /// Format: [(user|uid)][:(group|gid)]. Either side is optional.442 /// Precede either side with a '!' to exclude files instead.443 ///444 /// Examples:445 /// {n} --owner john446 /// {n} --owner :students447 /// {n} --owner '!john:students'

Reorder command line optionsDavid Peterbefore adoption12165c7

lines 448–449why, one step back
448 #[cfg(unix)]
449 #[arg(long, short = 'o', value_parser = OwnerFilter::from_string, value_name = "user:group",

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 450–451why, one step back
450 help = "Filter by owning user and/or group",
451 long_help,

Reorder command line optionsDavid Peterbefore adoption12165c7

lines 452–457why, one step back
452 )]
453 pub owner: Option<OwnerFilter>,454455 #[command(flatten)]456 pub exec: Exec,457

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 458–463why, one step back
458 /// Maximum number of arguments to pass to the command given with -X.
459 /// If the number of results is greater than the given size,460 /// the command given with -X is run again with remaining arguments.461 /// A batch size of zero means there is no limit (default), but note462 /// that batching might still happen due to OS restrictions on the463 /// maximum length of command lines.

Reorder command line optionsDavid Peterbefore adoption12165c7

lines 464–470why, one step back
464 #[arg(
465 long,466 value_name = "size",467 hide_short_help = true,468 requires("exec_batch"),469 value_parser = value_parser!(usize),470 default_value_t,

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 471–472why, one step back
471 help = "Max number of arguments to run as a batch size with -X",
472 long_help,

Reorder command line optionsDavid Peterbefore adoption12165c7

lines 473–475why, one step back
473 )]
474 pub batch_size: usize,475

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

line 476why, one step back
476 /// Add a custom ignore-file in '.gitignore' format. These files have a low precedence.

Reorder command line optionsDavid Peterbefore adoption12165c7

lines 477–480why, one step back
477 #[arg(
478 long,479 value_name = "path",480 hide_short_help = true,

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 481–482why, one step back
481 help = "Add a custom ignore-file in '.gitignore' format",
482 long_help

Reorder command line optionsDavid Peterbefore adoption12165c7

lines 483–485why, one step back
483 )]
484 pub ignore_file: Vec<PathBuf>,485

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

line 486why, one step back
486 /// Declare when to use color for the pattern match output

Reorder command line optionsDavid Peterbefore adoption12165c7

lines 487–492why, one step back
487 #[arg(
488 long,489 short = 'c',490 value_enum,491 default_value_t = ColorWhen::Auto,492 value_name = "when",

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 493–494why, one step back
493 help = "When to use colors",
494 long_help,

Reorder command line optionsDavid Peterbefore adoption12165c7

lines 495–499why, one step back
495 )]
496 pub color: ColorWhen,497498 /// Set number of threads to use for searching & executing (default: number499 /// of available CPU cores)

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

lines 500–501why, one step back
500 #[arg(long, short = 'j', value_name = "num", hide_short_help = true, value_parser = str::parse::<NonZeroUsize>)]
501 pub threads: Option<NonZeroUsize>,

Reorder command line optionsDavid Peterbefore adoption12165c7

lines 502–509why, one step back
502
503 /// Milliseconds to buffer before streaming search results to console504 ///505 /// Amount of time in milliseconds to buffer, before streaming the search506 /// results to the console.507 #[arg(long, hide = true, value_parser = parse_millis)]508 pub max_buffer_time: Option<Duration>,509

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

line 510why, one step back
510 ///Limit the number of search results to 'count' and quit immediately.

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

lines 511–514why, one step back
511 #[arg(
512 long,513 value_name = "count",514 hide_short_help = true,

Merge pull request #1394 from final-israel/make_max_results_one_conflict_with_execThayne McCombsbefore adoptionfc240f7

line 515why, one step back
515 overrides_with("max_one_result"),

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 516–517why, one step back
516 help = "Limit the number of search results",
517 long_help

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

lines 518–520why, one step back
518 )]
519 max_results: Option<usize>,520

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 521–522why, one step back
521 /// Limit the search to a single result and quit immediately.
522 /// This is an alias for '--max-results=1'.

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

lines 523–526why, one step back
523 #[arg(
524 short = '1',525 hide_short_help = true,526 overrides_with("max_results"),

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 527–528why, one step back
527 help = "Limit search to a single result",
528 long_help

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

lines 529–531why, one step back
529 )]
530 max_one_result: bool,531

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 532–535why, one step back
532 /// When the flag is present, the program does not print anything and will
533 /// return with an exit code of 0 if there is at least one match. Otherwise, the534 /// exit code will be 1.535 /// '--has-results' can be used as an alias.

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

lines 536–541why, one step back
536 #[arg(
537 long,538 short = 'q',539 alias = "has-results",540 hide_short_help = true,541 conflicts_with("max_results"),

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 542–543why, one step back
542 help = "Print nothing, exit code 0 if match found, 1 otherwise",
543 long_help

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

lines 544–546why, one step back
544 )]
545 pub quiet: bool,546

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 547–548why, one step back
547 /// Enable the display of filesystem errors for situations such as
548 /// insufficient permissions or dead symlinks.

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

lines 549–551why, one step back
549 #[arg(
550 long,551 hide_short_help = true,

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 552–553why, one step back
552 help = "Show filesystem errors",
553 long_help

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

lines 554–556why, one step back
554 )]
555 pub show_errors: bool,556

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 557–561why, one step back
557 /// Change the current working directory of fd to the provided path. This
558 /// means that search results will be shown with respect to the given base559 /// path. Note that relative paths which are passed to fd via the positional560 /// <path> argument or the '--search-path' option will also be resolved561 /// relative to this directory.

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

lines 562–565why, one step back
562 #[arg(
563 long,564 value_name = "path",565 hide_short_help = true,

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 566–567why, one step back
566 help = "Change current working directory",
567 long_help

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

lines 568–570why, one step back
568 )]
569 pub base_directory: Option<PathBuf>,570

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 571–574why, one step back
571 /// the search pattern which is either a regular expression (default) or a glob
572 /// pattern (if --glob is used). If no pattern has been specified, every entry573 /// is considered a match. If your pattern starts with a dash (-), make sure to574 /// pass '--' first, or it will be considered as a flag (fd -- '-foo').

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

lines 575–578why, one step back
575 #[arg(
576 default_value = "",577 hide_default_value = true,578 value_name = "pattern",

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 579–580why, one step back
579 help = "the search pattern (a regular expression, unless '--glob' is used; optional)",
580 long_help

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

lines 581–583why, one step back
581 )]
582 pub pattern: String,583

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 584–585why, one step back
584 /// Set the path separator to use when printing file paths. The default is
585 /// the OS-specific separator ('/' on Unix, '\' on Windows).

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

lines 586–589why, one step back
586 #[arg(
587 long,588 value_name = "separator",589 hide_short_help = true,

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 590–591why, one step back
590 help = "Set path separator when printing file paths",
591 long_help

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

lines 592–594why, one step back
592 )]
593 pub path_separator: Option<String>,594

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 595–596why, one step back
595 /// The directory where the filesystem search is rooted (optional). If
596 /// omitted, search the current working directory.

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

lines 597–598why, one step back
597 #[arg(action = ArgAction::Append,
598 value_name = "path",

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 599–600why, one step back
599 help = "the root directories for the filesystem search (optional)",
600 long_help,

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

lines 601–603why, one step back
601 )]
602 path: Vec<PathBuf>,603

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 604–606why, one step back
604 /// Provide paths to search as an alternative to the positional <path>
605 /// argument. Changes the usage to `fd [OPTIONS] --search-path <path>606 /// --search-path <path2> [<pattern>]`

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

lines 607–611why, one step back
607 #[arg(
608 long,609 conflicts_with("path"),610 value_name = "search-path",611 hide_short_help = true,

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 612–613why, one step back
612 help = "Provides paths to search as an alternative to the positional <path> argument",
613 long_help

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

lines 614–620why, one step back
614 )]
615 search_path: Vec<PathBuf>,616617 /// By default, relative paths are prefixed with './' when -x/--exec,618 /// -X/--exec-batch, or -0/--print0 are given, to reduce the risk of a619 /// path starting with '-' being treated as a command line option. Use620 /// this flag to disable this behaviour.

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

line 621why, one step back
621 #[arg(long, conflicts_with_all(&["path", "search_path"]), hide_short_help = true, long_help)]

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

lines 622–623why, one step back
622 pub strip_cwd_prefix: bool,
623

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

lines 624–627why, one step back
624 /// By default, fd will traverse the file system tree as far as other options
625 /// dictate. With this flag, fd ensures that it does not descend into a626 /// different file system than the one it started in. Comparable to the -mount627 /// or -xdev filters of find(1).

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

line 628why, one step back
628 #[cfg(any(unix, windows))]

Merge pull request #1171 from tmccombs/clap-derive-commentsDavid Peterbefore adoption8ecfdfe

line 629why, one step back
629 #[arg(long, aliases(&["mount", "xdev"]), hide_short_help = true, long_help)]

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

lines 630–644why, one step back
630 pub one_file_system: bool,
631632 #[cfg(feature = "completions")]633 #[arg(long, hide = true, exclusive = true)]634 gen_completions: Option<Option<Shell>>,635}636637impl Opts {638 pub fn search_paths(&self) -> anyhow::Result<Vec<PathBuf>> {639 // would it make sense to concatenate these?640 let paths = if !self.path.is_empty() {641 &self.path642 } else if !self.search_path.is_empty() {643 &self.search_path644 } else {

Workaround for bug with gitinored filesThayne McCombsbefore adoption6af8f09

line 645why, one step back
645 let current_directory = Path::new("./");

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

lines 646–667why, one step back
646 ensure_current_directory_exists(current_directory)?;
647 return Ok(vec![self.normalize_path(current_directory)]);648 };649 Ok(paths650 .iter()651 .filter_map(|path| {652 if filesystem::is_existing_directory(path) {653 Some(self.normalize_path(path))654 } else {655 print_error(format!(656 "Search path '{}' is not a directory.",657 path.to_string_lossy()658 ));659 None660 }661 })662 .collect())663 }664665 fn normalize_path(&self, path: &Path) -> PathBuf {666 if self.absolute_path {667 filesystem::absolute_path(path.normalize().unwrap().as_path()).unwrap()

Add test for gitignore workaroundThayne McCombsbefore adoption6647085

lines 668–670why, one step back
668 } else if path == Path::new(".") {
669 // Change "." to "./" as a workaround for https://github.com/BurntSushi/ripgrep/pull/2711670 PathBuf::from("./")

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

lines 671–692why, one step back
671 } else {
672 path.to_path_buf()673 }674 }675676 pub fn no_search_paths(&self) -> bool {677 self.path.is_empty() && self.search_path.is_empty()678 }679680 #[inline]681 pub fn rg_alias_ignore(&self) -> bool {682 self.rg_alias_hidden_ignore > 0683 }684685 pub fn max_depth(&self) -> Option<usize> {686 self.max_depth.or(self.exact_depth)687 }688689 pub fn min_depth(&self) -> Option<usize> {690 self.min_depth.or(self.exact_depth)691 }692

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

lines 693–694why, one step back
693 pub fn threads(&self) -> NonZeroUsize {
694 self.threads.unwrap_or_else(default_num_threads)

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

lines 695–699why, one step back
695 }
696697 pub fn max_results(&self) -> Option<usize> {698 self.max_results699 .filter(|&m| m > 0)

Merge pull request #1283 from tmccombs/new-rust-versionTavian Barnesbefore adoptione4bca10

line 700why, one step back
700 .or_else(|| self.max_one_result.then_some(1))

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

lines 701–707why, one step back
701 }
702703 #[cfg(feature = "completions")]704 pub fn gen_completions(&self) -> anyhow::Result<Option<Shell>> {705 self.gen_completions706 .map(|maybe_shell| match maybe_shell {707 Some(sh) => Ok(sh),

Merge pull request #1170 from tmccombs/clap-improvements-2Thayne McCombsbefore adoption85e3ada

lines 708–710why, one step back
708 None => {
709 Shell::from_env().ok_or_else(|| anyhow!("Unable to get shell from environment"))710 }

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

lines 711–713why, one step back
711 })
712 .transpose()713 }

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

lines 714–719why, one step back
714}
715716/// Get the default number of threads to use, if not explicitly specified.717fn default_num_threads() -> NonZeroUsize {718 // If we can't get the amount of parallelism for some reason, then719 // default to a single thread, because that is safe.

cli: Tweak default thread count logicTavian Barnesbefore adoptionfea1622

lines 720–723why, one step back
720 let fallback = NonZeroUsize::MIN;
721 // To limit startup overhead on massively parallel machines, don't use more722 // than 64 threads.723 let limit = NonZeroUsize::new(64).unwrap();

Merge pull request #1412 from tmccombs/limit-default-threadsThayne McCombsbefore adoption95b4dff

line 724why, one step back
724

cli: Tweak default thread count logicTavian Barnesbefore adoptionfea1622

lines 725–727why, one step back
725 std::thread::available_parallelism()
726 .unwrap_or(fallback)727 .min(limit)

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

lines 728–733why, one step back
728}
729730#[derive(Copy, Clone, PartialEq, Eq, ValueEnum)]731pub enum FileType {732 #[value(alias = "f")]733 File,

Merge pull request #1464 from Ato2207/dir_aliasThayne McCombsbefore adoption14ed023

line 734why, one step back
734 #[value(alias = "d", alias = "dir")]

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

lines 735–737why, one step back
735 Directory,
736 #[value(alias = "l")]737 Symlink,

Support character and block device file typesChristian Göttschebefore adoption36bc840

lines 738–741why, one step back
738 #[value(alias = "b")]
739 BlockDevice,740 #[value(alias = "c")]741 CharDevice,

Merge pull request #1169 from Ptipiak/mention-executable-detectionDavid Peterbefore adoption38cdeb0

line 742why, one step back
742 /// A file which is executable by the current effective user

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

lines 743–771why, one step back
743 #[value(alias = "x")]
744 Executable,745 #[value(alias = "e")]746 Empty,747 #[value(alias = "s")]748 Socket,749 #[value(alias = "p")]750 Pipe,751}752753#[derive(Copy, Clone, PartialEq, Eq, Debug, ValueEnum)]754pub enum ColorWhen {755 /// show colors if the output goes to an interactive console (default)756 Auto,757 /// always use colorized output758 Always,759 /// do not use colorized output760 Never,761}762763// there isn't a derive api for getting grouped values yet,764// so we have to use hand-rolled parsing for exec and exec-batch765pub struct Exec {766 pub command: Option<CommandSet>,767}768769impl clap::FromArgMatches for Exec {770 fn from_arg_matches(matches: &ArgMatches) -> clap::error::Result<Self> {771 let command = matches

Merge pull request #1244 from tmccombs/grouped-occurrencesDavid Peterbefore adoption73a693e

line 772why, one step back
772 .get_occurrences::<String>("exec")

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

lines 773–775why, one step back
773 .map(CommandSet::new)
774 .or_else(|| {775 matches

Merge pull request #1244 from tmccombs/grouped-occurrencesDavid Peterbefore adoption73a693e

line 776why, one step back
776 .get_occurrences::<String>("exec_batch")

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

lines 777–803why, one step back
777 .map(CommandSet::new_batch)
778 })779 .transpose()780 .map_err(|e| clap::Error::raw(ErrorKind::InvalidValue, e))?;781 Ok(Exec { command })782 }783784 fn update_from_arg_matches(&mut self, matches: &ArgMatches) -> clap::error::Result<()> {785 *self = Self::from_arg_matches(matches)?;786 Ok(())787 }788}789790impl clap::Args for Exec {791 fn augment_args(cmd: Command) -> Command {792 cmd.arg(Arg::new("exec")793 .action(ArgAction::Append)794 .long("exec")795 .short('x')796 .num_args(1..)797 .allow_hyphen_values(true)798 .value_terminator(";")799 .value_name("cmd")800 .conflicts_with("list_details")801 .help("Execute a command for each search result")802 .long_help(803 "Execute a command for each search result in parallel (use --threads=1 for sequential command execution). \

docs: Explicitly warn against relying on result order for execThayne McCombsbefore adoptionc6fcdbe

line 804why, one step back
804 There is no guarantee of the order commands are executed in, and the order should not be depended upon. \

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

lines 805–811why, one step back
805 All positional arguments following --exec are considered to be arguments to the command - not to fd. \
806 It is therefore recommended to place the '-x'/'--exec' option last.\n\807 The following placeholders are substituted before the command is executed:\n \808 '{}': path (of the current search result)\n \809 '{/}': basename\n \810 '{//}': parent directory\n \811 '{.}': path without file extension\n \

feat: Add a way to escape { and }in exec templates.Thayne McCombsbefore adoptiond9b69c8

line 812why, one step back
812 '{/.}': basename without file extension\n \

Fix documentation for brace escapesThayne McCombsbefore adoption069b181

lines 813–814why, one step back
813 '{{': literal '{' (for escaping)\n \
814 '}}': literal '}' (for escaping)\n\n\

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

lines 815–834why, one step back
815 If no placeholder is present, an implicit \"{}\" at the end is assumed.\n\n\
816 Examples:\n\n \817 - find all *.zip files and unzip them:\n\n \818 fd -e zip -x unzip\n\n \819 - find *.h and *.cpp files and run \"clang-format -i ..\" for each of them:\n\n \820 fd -e h -e cpp -x clang-format -i\n\n \821 - Convert all *.jpg files to *.png files:\n\n \822 fd -e jpg -x convert {} {.}.png\823 ",824 ),825 )826 .arg(827 Arg::new("exec_batch")828 .action(ArgAction::Append)829 .long("exec-batch")830 .short('X')831 .num_args(1..)832 .allow_hyphen_values(true)833 .value_terminator(";")834 .value_name("cmd")

Merge pull request #1168 from tmccombs/clippy-fixes-2Thayne McCombsbefore adoption9e88f91

line 835why, one step back
835 .conflicts_with_all(["exec", "list_details"])

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

lines 836–838why, one step back
836 .help("Execute a command with all search results at once")
837 .long_help(838 "Execute the given command once, with all search results as arguments.\n\

docs: Explicitly warn against relying on result order for execThayne McCombsbefore adoptionc6fcdbe

line 839why, one step back
839 The order of the arguments is non-deterministic, and should not be relied upon.\n\

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

lines 840–844why, one step back
840 One of the following placeholders is substituted before the command is executed:\n \
841 '{}': path (of all search results)\n \842 '{/}': basename\n \843 '{//}': parent directory\n \844 '{.}': path without file extension\n \

feat: Add a way to escape { and }in exec templates.Thayne McCombsbefore adoptiond9b69c8

line 845why, one step back
845 '{/.}': basename without file extension\n \

Fix --help textDavid Peterbefore adoption0fc8fac

lines 846–847why, one step back
846 '{{': literal '{' (for escaping)\n \
847 '}}': literal '}' (for escaping)\n\n\

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

lines 848–876why, one step back
848 If no placeholder is present, an implicit \"{}\" at the end is assumed.\n\n\
849 Examples:\n\n \850 - Find all test_*.py files and open them in your favorite editor:\n\n \851 fd -g 'test_*.py' -X vim\n\n \852 - Find all *.rs files and count the lines with \"wc -l ...\":\n\n \853 fd -e rs -X wc -l\854 "855 ),856 )857 }858859 fn augment_args_for_update(cmd: Command) -> Command {860 Self::augment_args(cmd)861 }862}863864fn parse_millis(arg: &str) -> Result<Duration, std::num::ParseIntError> {865 Ok(Duration::from_millis(arg.parse()?))866}867868fn ensure_current_directory_exists(current_directory: &Path) -> anyhow::Result<()> {869 if filesystem::is_existing_directory(current_directory) {870 Ok(())871 } else {872 Err(anyhow!(873 "Could not retrieve current directory (has it been deleted?)."874 ))875 }876}