Merge remote-tracking branch 'origin/master' into no-strip/760
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Peter · committed by David Peter · parents 06c58b9, 0484486 · Browse files · 19 files·+443 added−117 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
19 files+443 added−117 removed
- tests:+67 added−0 removed
- other:+376 added−117 removed
Provenance
- Commit
92bd785- Tree
c8dff9b- Author
David Peter <mail@david-peter.de>- Committer
David Peter <mail@david-peter.de>- Parent 1
06c58b9- Parent 2
0484486
19 files changed+443 added−117 removed
deleted:.github/ISSUE_TEMPLATE/bug_report.md-28 removed
12345678910111213141516171819202122232425262728---name: Bug Reportabout: Report a bug.title: ""labels: bugassignees: ''
---
**Describe the bug you encountered:**
<!--Please check out the troubleshooting section first: https://github.com/sharkdp/fd#troubleshooting-->
**Describe what you expected to happen:**
**What version of `fd` are you using?**<!-- paste the output of `fd --version` here -->
**Which operating system / distribution are you on?**<!--Unix: paste the output of `uname -srm` and `lsb_release -a` here.Windows: please tell us your Windows version-->added:.github/ISSUE_TEMPLATE/bug_report.yaml+41 added
1234567891011121314151617181920212223242526272829303132333435363738394041name: Bug Reportdescription: Report a bug.title: "[BUG] "labels: bugbody: - type: markdown attributes: value: | Please check out the [troubleshooting section](https://github.com/sharkdp/fd#troubleshooting) first. - type: checkboxes attributes: options: - label: I have read the troubleshooting section and still think this is a bug. required: true - type: textarea id: bug attributes: label: "Describe the bug you encountered:" validations: required: true - type: textarea id: expected attributes: label: "Describe what you expected to happen:" - type: input id: version attributes: label: "What version of `fd` are you using?" placeholder: "paste the output of `fd --version` here" validations: required: true - type: textarea id: os attributes: label: Which operating system / distribution are you on? placeholder: | Unix: paste the output of `uname -srm` and `lsb_release -a` here. Windows: please tell us your Windows version render: shell validations: required: truemodified:contrib/completion/_fd+1 added
136 unmodified lines137 138 + '(exec-cmds)' # execute command139 '(long-listing max-results)'{-x+,--exec=}'[execute command for each search result]:command: _command_names -e:*\;::program arguments: _normal'140 '(long-listing max-results)'{-X+,--exec-batch=}'[execute command for all search results at once]:command: _command_names -e:*\;::program arguments: _normal'141+ '(long-listing max-results)--batch-size=[max number of args for each -X call]:size'142 143 + other144 '!(--max-buffer-time)--max-buffer-time=[set amount of time to buffer before showing output]:time (ms)'145 124 unmodified linesmodified:doc/fd.1+41 added-9 removed
26 unmodified lines27 .SH OPTIONS28 .TP29 .B \-H, \-\-hidden30 Include hidden files and directories in the search results31-(default: hidden files and directories are skipped).31+(default: hidden files and directories are skipped). The flag can be overridden with '--no-hidden'.32 .TP33 .B \-I, \-\-no\-ignore34 Show search results from files and directories that would otherwise be ignored by35 .RS12 unmodified lines48 The global fd ignore file (usually49 .I $HOME/.config/fd/ignore50 )51 .RE52+.IP53+The flag can be overridden with '--ignore'.54 .TP55 .B \-u, \-\-unrestricted56 Alias for '--no-ignore'. Can be repeated; '-uu' is an alias for '--no-ignore --hidden'.57 .TP5 unmodified lines63 and the global gitignore configuration64 .RI ( core.excludesFile65 git setting, which defaults to66 .IR $HOME/.config/git/ignore ).67+The flag can be overridden with '--ignore-vcs'.68 .TP69 .B \-s, \-\-case\-sensitive70 Perform a case-sensitive search. By default, fd uses case-insensitive searches, unless the71 pattern contains an uppercase character (smart case).14 unmodified lines86 performs substring comparison. If you want to match on an exact filename, consider using '\-\-glob'.87 .TP88 .B \-a, \-\-absolute\-path89 Shows the full path starting from the root as opposed to relative paths.90+The flag can be overridden with '--relative-path'.91 .TP92 .B \-l, \-\-list\-details93 Use a detailed listing format like 'ls -l'. This is basically an alias94 for '--exec-batch ls -l' with some additional 'ls' options. This can be used1 unmodified line96 sort order.97 .TP98 .B \-L, \-\-follow99 By default, fd does not descend into symlinked directories. Using this flag, symbolic links are96-also traversed.100+also traversed. The flag can be overridden with '--no-follow'.101 .TP102 .B \-p, \-\-full\-path103 By default, the search pattern is only matched against the filename (or directory name). Using104 this flag, the52 unmodified lines157 .IP "d, directory"158 directories159 .IP "l, symlink"160 symbolic links157-.IP "x, executable"158-executable (files)159-.IP "e, empty"160-empty files or directories161 .IP "s, socket"162 sockets163 .IP "p, pipe"164 named pipes (FIFOs)165+.IP "x, executable"166+executable (files)167+.IP "e, empty"168+empty files or directories169 .RE170 171 .RS168-This option can be used repeatedly to allow for multiple file types.172+This option can be specified more than once to include multiple file types.173+Searching for '--type file --type symlink' will show both regular files as well as174+symlinks. Note that the 'executable' and 'empty' filters work differently: '--type175+executable' implies '--type file' by default. And '--type empty' searches for176+empty files and directories, unless either '--type file' or '--type directory' is177+specified in addition.178+179+Examples:180+ - Only search for files:181+ fd --type file …182+ fd -tf …183+ - Find both files and symlinks184+ fd --type file --type symlink …185+ fd -tf -tl …186+ - Find executable files:187+ fd --type executable188+ fd -tx189+ - Find empty files:190+ fd --type empty --type file191+ fd -te -tf192+ - Find empty directories:193+ fd --type empty --type directory194+ fd -te -td195 .RE196 .TP197 .BI "\-e, \-\-extension " ext198 Filter search results by file extension69 unmodified lines268 .RE269 .TP270 .BI "\-\-changed-within " date|duration271 Filter results based on the file modification time.246-Files with modification times greater than or equal to the argument will be returned.272+Files with modification times greater than the argument will be returned.273 The argument can be provided as a duration (\fI10h, 1d, 35min\fR) or as a specific point274 in time in either full RFC3339 format with time zone, or as a date or datetime in the275 local time zone (\fIYYYY-MM-DD\fR or \fIYYYY-MM-DD HH:MM:SS\fR).276 .B --change-newer-than4 unmodified lines281 \-\-change-newer-than "2018-10-27 10:00:00"282 .TP283 .BI "\-\-changed-before " date|duration284 Filter results based on the file modification time.259-Files with modification times less than or equal to the argument will be returned.285+Files with modification times less than the argument will be returned.286 The argument can be provided as a duration (\fI10h, 1d, 35min\fR) or as a specific point287 in time in either full RFC3339 format with time zone, or as a date or datetime in the288 local time zone (\fIYYYY-MM-DD\fR or \fIYYYY-MM-DD HH:MM:SS\fR).289 .B --change-older-than140 unmodified lines430 $ fd -e py431 .TP432 .RI "Open all search results with vim:"433 $ fd pattern -X vim434+.TP435+.BI "\-\-batch\-size " size436+Pass at most437+.I size438+arguments to each call to the command given with -X.439+.TP440 .SH SEE ALSO441 .BR find (1)modified:src/exec/job.rs+14 added-1 removed
48 unmodified lines49 rx: Receiver<WorkerResult>,50 cmd: &CommandTemplate,51 show_filesystem_errors: bool,52 buffer_output: bool,53+ limit: usize,54 ) -> ExitCode {55 let paths = rx.iter().filter_map(|value| match value {56 WorkerResult::Entry(val) => Some(val),57 WorkerResult::Error(err) => {2 unmodified lines60 }61 None62 }63 });63- cmd.generate_and_execute_batch(paths, buffer_output)64+ if limit == 0 {65+ // no limit66+ return cmd.generate_and_execute_batch(paths, buffer_output);67+ }68+69+ let mut exit_codes = Vec::new();70+ let mut peekable = paths.peekable();71+ while peekable.peek().is_some() {72+ let limited = peekable.by_ref().take(limit);73+ let exit_code = cmd.generate_and_execute_batch(limited, buffer_output);74+ exit_codes.push(exit_code);75+ }76+ merge_exitcodes(exit_codes)77 }modified:src/exec/mod.rs+3 added-4 removed
8 unmodified lines9 use std::process::{Command, Stdio};10 use std::sync::{Arc, Mutex};11 12 use anyhow::{anyhow, Result};13-use lazy_static::lazy_static;13+use once_cell::sync::Lazy;14 use regex::Regex;15 16 use crate::exit_codes::ExitCode;17 52 unmodified lines70 where71 I: IntoIterator<Item = S>,72 S: AsRef<str>,73 {74- lazy_static! {75- static ref PLACEHOLDER_PATTERN: Regex = Regex::new(r"\{(/?\.?|//)\}").unwrap();76- }74+ static PLACEHOLDER_PATTERN: Lazy<Regex> =75+ Lazy::new(|| Regex::new(r"\{(/?\.?|//)\}").unwrap());76 77 let mut args = Vec::new();78 let mut has_placeholder = false;79 379 unmodified linesmodified:src/filter/size.rs+3 added-4 removed
1-use lazy_static::lazy_static;1+use once_cell::sync::Lazy;2 use regex::Regex;3 4-lazy_static! {5- static ref SIZE_CAPTURES: Regex = Regex::new(r"(?i)^([+-]?)(\d+)(b|[kmgt]i?b?)$").unwrap();6-}4+static SIZE_CAPTURES: Lazy<Regex> =5+ Lazy::new(|| Regex::new(r"(?i)^([+-]?)(\d+)(b|[kmgt]i?b?)$").unwrap());6 7 #[derive(Clone, Copy, Debug, PartialEq)]8 pub enum SizeFilter {9 Max(u64),202 unmodified linesmodified:src/filter/time.rs+2 added-2 removed
37 unmodified lines38 }39 40 pub fn applies_to(&self, t: &SystemTime) -> bool {41 match self {42- TimeFilter::Before(limit) => t <= limit,43- TimeFilter::After(limit) => t >= limit,42+ TimeFilter::Before(limit) => t < limit,43+ TimeFilter::After(limit) => t > limit,44 }45 }46 }47 84 unmodified linesmodified:src/app.rs+102 added-13 removed
23 unmodified lines24 .help("Search hidden files and directories")25 .long_help(26 "Include hidden directories and files in the search results (default: \27 hidden files and directories are skipped). Files and directories are \28- considered to be hidden if their name starts with a `.` sign (dot).",28+ considered to be hidden if their name starts with a `.` sign (dot). \29+ The flag can be overridden with --no-hidden.",30 ),31 )32 .arg(33+ Arg::with_name("no-hidden")34+ .long("no-hidden")35+ .overrides_with("hidden")36+ .hidden(true)37+ .long_help(38+ "Overrides --hidden.",39+ ),40+ )41+ .arg(42 Arg::with_name("no-ignore")43 .long("no-ignore")44 .short("I")45 .overrides_with("no-ignore")46 .help("Do not respect .(git|fd)ignore files")47 .long_help(48 "Show search results from files and directories that would otherwise be \39- ignored by '.gitignore', '.ignore', '.fdignore', or the global ignore file.",49+ ignored by '.gitignore', '.ignore', '.fdignore', or the global ignore file. \50+ The flag can be overridden with --ignore.",51 ),52 )53 .arg(54+ Arg::with_name("ignore")55+ .long("ignore")56+ .overrides_with("no-ignore")57+ .hidden(true)58+ .long_help(59+ "Overrides --no-ignore.",60+ ),61+ )62+ .arg(63 Arg::with_name("no-ignore-vcs")64 .long("no-ignore-vcs")65 .overrides_with("no-ignore-vcs")66 .hidden_short_help(true)67 .help("Do not respect .gitignore files")68 .long_help(69 "Show search results from files and directories that would otherwise be \50- ignored by '.gitignore' files.",70+ ignored by '.gitignore' files. The flag can be overridden with --ignore-vcs.",71 ),72 )73 .arg(74+ Arg::with_name("ignore-vcs")75+ .long("ignore-vcs")76+ .overrides_with("no-ignore-vcs")77+ .hidden(true)78+ .long_help(79+ "Overrides --no-ignore-vcs.",80+ ),81+ )82+ .arg(83 Arg::with_name("no-ignore-parent")84 .long("no-ignore-parent")85 .overrides_with("no-ignore-parent")86 .hidden_short_help(true)13 unmodified lines100 .arg(101 Arg::with_name("rg-alias-hidden-ignore")102 .short("u")103 .long("unrestricted")104+ .overrides_with_all(&["ignore", "no-hidden"])105 .multiple(true)106 .hidden_short_help(true)107 .help("Alias for '--no-ignore', and '--hidden' when given twice")108 .long_help(65 unmodified lines174 .short("a")175 .overrides_with("absolute-path")176 .help("Show absolute instead of relative paths")177 .long_help(148- "Shows the full path starting from the root as opposed to relative paths.",178+ "Shows the full path starting from the root as opposed to relative paths. \179+ The flag can be overridden with --relative-path.",180 ),181 )182 .arg(183+ Arg::with_name("relative-path")184+ .long("relative-path")185+ .overrides_with("absolute-path")186+ .hidden(true)187+ .long_help(188+ "Overrides --absolute-path.",189+ ),190+ )191+ .arg(192 Arg::with_name("list-details")193 .long("list-details")194 .short("l")195 .conflicts_with("absolute-path")13 unmodified lines209 .overrides_with("follow")210 .help("Follow symbolic links")211 .long_help(212 "By default, fd does not descend into symlinked directories. Using this \173- flag, symbolic links are also traversed.",213+ flag, symbolic links are also traversed. \214+ Flag can be overriden with --no-follow.",215 ),216 )217 .arg(218+ Arg::with_name("no-follow")219+ .long("no-follow")220+ .overrides_with("follow")221+ .hidden(true)222+ .long_help(223+ "Overrides --follow.",224+ ),225+ )226+ .arg(227 Arg::with_name("full-path")228 .long("full-path")229 .short("p")230 .overrides_with("full-path")181- .help("Search full path (default: file-/dirname only)")231+ .help("Search full abs. path (default: filename only)")232 .long_help(233 "By default, the search pattern is only matched against the filename (or \184- directory name). Using this flag, the pattern is matched against the \185- full path.",234+ directory name). Using this flag, the pattern is matched against the full \235+ (absolute) path. Example:\n \236+ fd --glob -p '**/.git/config'",237 ),238 )239 .arg(240 Arg::with_name("null_separator")58 unmodified lines299 .long("prune")300 .conflicts_with_all(&["size", "exact-depth"])301 .hidden_short_help(true)302 .help("Do not traverse into matching directories")252- .long_help("Do not traverse into matching directories.")303+ .long_help("Do not traverse into directories that match the search criteria. If \304+ you want to exclude specific directories, use the '--exclude=…' option.")305 )306 .arg(307 Arg::with_name("file-type")308 .long("type")23 unmodified lines332 "Filter by type: file (f), directory (d), symlink (l),\nexecutable (x), \333 empty (e), socket (s), pipe (p)",334 )335 .long_help(284- "Filter the search by type (multiple allowable filetypes can be specified):\n \336+ "Filter the search by type:\n \337 'f' or 'file': regular files\n \338 'd' or 'directory': directories\n \339 'l' or 'symlink': symbolic links\n \288- 'x' or 'executable': executables\n \289- 'e' or 'empty': empty files or directories\n \340 's' or 'socket': socket\n \291- 'p' or 'pipe': named pipe (FIFO)",341+ 'p' or 'pipe': named pipe (FIFO)\n\n \342+ 'x' or 'executable': executables\n \343+ 'e' or 'empty': empty files or directories\n\n\344+ This option can be specified more than once to include multiple file types. \345+ Searching for '--type file --type symlink' will show both regular files as \346+ well as symlinks. Note that the 'executable' and 'empty' filters work differently: \347+ '--type executable' implies '--type file' by default. And '--type empty' searches \348+ for empty files and directories, unless either '--type file' or '--type directory' \349+ is specified in addition.\n\n\350+ Examples:\n \351+ - Only search for files:\n \352+ fd --type file …\n \353+ fd -tf …\n \354+ - Find both files and symlinks\n \355+ fd --type file --type symlink …\n \356+ fd -tf -tl …\n \357+ - Find executable files:\n \358+ fd --type executable\n \359+ fd -tx\n \360+ - Find empty files:\n \361+ fd --type empty --type file\n \362+ fd -te -tf\n \363+ - Find empty directories:\n \364+ fd --type empty --type directory\n \365+ fd -te -td"366 ),367 )368 .arg(369 Arg::with_name("extension")69 unmodified lines439 "440 ),441 )442 .arg(443+ Arg::with_name("batch-size")444+ .long("batch-size")445+ .takes_value(true)446+ .value_name("size")447+ .hidden_short_help(true)448+ .requires("exec-batch")449+ .help("Max number of arguments to run as a batch with -X")450+ .long_help(451+ "Maximum number of arguments to pass to the command given with -X. \452+ If the number of results is greater than the given size, \453+ the command given with -X is run again with remaining arguments. \454+ A batch size of zero means there is no limit.",455+ ),456+ )457+ .arg(458 Arg::with_name("exclude")459 .long("exclude")460 .short("E")461 .takes_value(true)299 unmodified linesmodified:src/config.rs+4 added
83 unmodified lines84 85 /// If a value is supplied, each item found will be used to generate and execute commands.86 pub command: Option<Arc<CommandTemplate>>,87 88+ /// Maximum number of search results to pass to each `command`. If zero, the number is89+ /// unlimited.90+ pub batch_size: usize,91+92 /// A list of glob patterns that should be excluded from the search.93 pub exclude_patterns: Vec<String>,94 95 /// A list of custom ignore files.24 unmodified linesmodified:src/exit_codes.rs+20 added
1+use std::process;2+3+#[cfg(unix)]4+use nix::sys::signal::{raise, signal, SigHandler, Signal};5+6 #[derive(Debug, Clone, Copy, PartialEq)]7 pub enum ExitCode {8 Success,9 HasResults(bool),15 unmodified lines25 impl ExitCode {26 fn is_error(self) -> bool {27 i32::from(self) != 028 }29+30+ /// Exit the process with the appropriate code.31+ pub fn exit(self) -> ! {32+ #[cfg(unix)]33+ if self == ExitCode::KilledBySigint {34+ // Get rid of the SIGINT handler, if present, and raise SIGINT35+ unsafe {36+ if signal(Signal::SIGINT, SigHandler::SigDfl).is_ok() {37+ let _ = raise(Signal::SIGINT);38+ }39+ }40+ }41+42+ process::exit(self.into())43+ }44 }45 46 pub fn merge_exitcodes(results: impl IntoIterator<Item = ExitCode>) -> ExitCode {47 if results.into_iter().any(ExitCode::is_error) {47 unmodified linesmodified:src/main.rs+8 added-3 removed
10 unmodified lines11 mod walk;12 13 use std::env;14 use std::path::{Path, PathBuf};15-use std::process;15 use std::sync::Arc;16 use std::time;17 18 use anyhow::{anyhow, Context, Result};33 unmodified lines52 fn main() {53 let result = run();54 match result {55 Ok(exit_code) => {57- process::exit(exit_code.into());56+ exit_code.exit();57 }58 Err(err) => {59 eprintln!("[fd error]: {:#}", err);61- process::exit(ExitCode::GeneralError.into());60+ ExitCode::GeneralError.exit();61 }62 }63 }64 281 unmodified lines346 .build()347 })348 .transpose()?,349 command: command.map(Arc::new),350+ batch_size: matches351+ .value_of("batch-size")352+ .map(|n| n.parse::<usize>())353+ .transpose()354+ .context("Failed to parse --batch-size argument")?355+ .unwrap_or_default(),356 exclude_patterns: matches357 .values_of("exclude")358 .map(|v| v.map(|p| String::from("!") + p).collect())359 .unwrap_or_else(Vec::new),209 unmodified linesmodified:src/output.rs+39 added-20 removed
1+use std::borrow::Cow;2 use std::io::{self, StdoutLock, Write};3 use std::path::Path;3-use std::process;4 use std::sync::atomic::{AtomicBool, Ordering};5 use std::sync::Arc;6 7-use lscolors::{LsColors, Style};7+use lscolors::{Indicator, LsColors, Style};8 9 use crate::config::Config;10 use crate::error::print_error;11 use crate::exit_codes::ExitCode;24 unmodified lines36 37 if let Err(e) = r {38 if e.kind() == ::std::io::ErrorKind::BrokenPipe {39 // Exit gracefully in case of a broken pipe (e.g. 'fd ... | head -n 3').40- process::exit(0);40+ ExitCode::Success.exit();41 } else {42 print_error(format!("Could not write to output: {}", e));43- process::exit(ExitCode::GeneralError.into());43+ ExitCode::GeneralError.exit();44 }45 }46 }47 4 unmodified lines52 config: &Config,53 ls_colors: &LsColors,54 wants_to_quit: &Arc<AtomicBool>,55 ) -> io::Result<()> {56- let default_style = ansi_term::Style::default();56+ // Split the path between the parent and the last component57+ let mut offset = 0;58+ let path_str = path.to_string_lossy();59 58- // Traverse the path and colorize each component59- for (component, style) in ls_colors.style_for_path_components(path) {60- let style = style61- .map(Style::to_ansi_term_style)62- .unwrap_or(default_style);60+ if let Some(parent) = path.parent() {61+ offset = parent.to_string_lossy().len();62+ for c in path_str[offset..].chars() {63+ if std::path::is_separator(c) {64+ offset += c.len_utf8();65+ } else {66+ break;67+ }68+ }69+ }70 64- let mut path_string = component.to_string_lossy();71+ if offset > 0 {72+ let mut parent_str = Cow::from(&path_str[..offset]);73 if let Some(ref separator) = config.path_separator {66- *path_string.to_mut() = replace_path_separator(&path_string, separator);74+ *parent_str.to_mut() = replace_path_separator(&parent_str, separator);75 }68- write!(stdout, "{}", style.paint(path_string))?;76 70- // TODO: can we move this out of the if-statement? Why do we call it that often?71- if wants_to_quit.load(Ordering::Relaxed) {72- writeln!(stdout)?;73- process::exit(ExitCode::KilledBySigint.into());74- }77+ let style = ls_colors78+ .style_for_indicator(Indicator::Directory)79+ .map(Style::to_ansi_term_style)80+ .unwrap_or_default();81+ write!(stdout, "{}", style.paint(parent_str))?;82 }83 84+ let style = ls_colors85+ .style_for_path(path)86+ .map(Style::to_ansi_term_style)87+ .unwrap_or_default();88+ write!(stdout, "{}", style.paint(&path_str[offset..]))?;89+90 if config.null_separator {78- write!(stdout, "\0")91+ write!(stdout, "\0")?;92 } else {80- writeln!(stdout)93+ writeln!(stdout)?;94 }95+96+ if wants_to_quit.load(Ordering::Relaxed) {97+ ExitCode::KilledBySigint.exit();98+ }99+100+ Ok(())101 }102 103 // TODO: this function is performance critical and can probably be optimized104 fn print_entry_uncolorized_base(40 unmodified linesmodified:src/walk.rs+9 added-6 removed
1 unmodified line2 use std::ffi::OsStr;3 use std::fs::{FileType, Metadata};4 use std::io;5 use std::path::{Path, PathBuf};6-use std::process;6 use std::sync::atomic::{AtomicBool, Ordering};7 use std::sync::mpsc::{channel, Receiver, Sender};8 use std::sync::{Arc, Mutex};9 use std::thread;125 unmodified lines135 let wants_to_quit = Arc::new(AtomicBool::new(false));136 if config.ls_colors.is_some() && config.command.is_none() {137 let wq = Arc::clone(&wants_to_quit);138 ctrlc::set_handler(move || {140- if wq.load(Ordering::Relaxed) {139+ if wq.fetch_or(true, Ordering::Relaxed) {140 // Ctrl-C has been pressed twice, exit NOW142- process::exit(ExitCode::KilledBySigint.into());143- } else {144- wq.store(true, Ordering::Relaxed);141+ ExitCode::KilledBySigint.exit();142 }143 })144 .unwrap();145 }29 unmodified lines175 thread::spawn(move || {176 // This will be set to `Some` if the `--exec` argument was supplied.177 if let Some(ref cmd) = config.command {178 if cmd.in_batch_mode() {182- exec::batch(rx, cmd, show_filesystem_errors, enable_output_buffering)179+ exec::batch(180+ rx,181+ cmd,182+ show_filesystem_errors,183+ enable_output_buffering,184+ config.batch_size,185+ )186 } else {187 let shared_rx = Arc::new(Mutex::new(rx));188 189 let out_perm = Arc::new(Mutex::new(()));333 unmodified linesmodified:tests/tests.rs+67 added
2 unmodified lines3 use std::fs;4 use std::io::Write;5 use std::path::Path;6 use std::time::{Duration, SystemTime};7+use test_case::test_case;8 9 use normpath::PathExt;10 use regex::escape;11 1406 unmodified lines1418 );1419 }1420 }1421 1422+#[test]1423+fn test_exec_batch_with_limit() {1424+ // TODO Test for windows1425+ if cfg!(windows) {1426+ return;1427+ }1428+1429+ let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);1430+1431+ te.assert_output(1432+ &["foo", "--batch-size", "0", "--exec-batch", "echo", "{}"],1433+ "./a.foo ./one/b.foo ./one/two/C.Foo2 ./one/two/c.foo ./one/two/three/d.foo ./one/two/three/directory_foo",1434+ );1435+1436+ let output = te.assert_success_and_get_output(1437+ ".",1438+ &["foo", "--batch-size=2", "--exec-batch", "echo", "{}"],1439+ );1440+ let stdout = String::from_utf8_lossy(&output.stdout);1441+1442+ for line in stdout.lines() {1443+ assert_eq!(2, line.split_whitespace().count());1444+ }1445+1446+ let mut paths: Vec<_> = stdout1447+ .lines()1448+ .flat_map(|line| line.split_whitespace())1449+ .collect();1450+ paths.sort_unstable();1451+ assert_eq!(1452+ &paths,1453+ &[1454+ "./a.foo",1455+ "./one/b.foo",1456+ "./one/two/C.Foo2",1457+ "./one/two/c.foo",1458+ "./one/two/three/d.foo",1459+ "./one/two/three/directory_foo"1460+ ],1461+ );1462+}1463+1464 /// Shell script execution (--exec) with a custom --path-separator1465 #[test]1466 fn test_exec_with_separator() {1467 let (te, abs_path) = get_test_env_with_abs_path(DEFAULT_DIRS, DEFAULT_FILES);473 unmodified lines1941 1942 te.assert_failure(&["--max-results=a"]);1943 }1944 1945+#[test_case("--hidden", &["--no-hidden"] ; "hidden")]1946+#[test_case("--no-ignore", &["--ignore"] ; "no-ignore")]1947+#[test_case("--no-ignore-vcs", &["--ignore-vcs"] ; "no-ignore-vcs")]1948+#[test_case("--follow", &["--no-follow"] ; "follow")]1949+#[test_case("--absolute-path", &["--relative-path"] ; "absolute-path")]1950+#[test_case("-u", &["--ignore"] ; "u")]1951+#[test_case("-uu", &["--ignore", "--no-hidden"] ; "uu")]1952+fn test_opposing(flag: &str, opposing_flags: &[&str]) {1953+ let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);1954+1955+ let mut flags = vec![flag];1956+ flags.extend_from_slice(opposing_flags);1957+ let out_no_flags = te.assert_success_and_get_output(".", &[]);1958+ let out_opposing_flags = te.assert_success_and_get_output(".", &flags);1959+1960+ assert_eq!(1961+ out_no_flags,1962+ out_opposing_flags,1963+ "{} should override {}",1964+ opposing_flags.join(" "),1965+ flag1966+ );1967+}1968+1969 /// Print error if search pattern starts with a dot and --hidden is not set1970 /// (Unix only, hidden files on Windows work differently)1971 #[test]1972 #[cfg(unix)]30 unmodified linesmodified:Cargo.lock+70 added-21 removed
29 unmodified lines30 ]31 32 [[package]]33 name = "anyhow"34-version = "1.0.44"34+version = "1.0.45"35 source = "registry+https://github.com/rust-lang/crates.io-index"36-checksum = "61604a8f862e1d5c3229fdd78f8b02c68dcf73a4c4b05fd636d12240aaa242c1"36+checksum = "ee10e43ae4a853c0a3591d4e2ada1719e553be18199d9da9d4a83f5927c2f5c7"37 38 [[package]]39 name = "atty"40 version = "0.2.14"12 unmodified lines53 checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"54 55 [[package]]56 name = "bitflags"57-version = "1.2.1"57+version = "1.3.2"58 source = "registry+https://github.com/rust-lang/crates.io-index"59-checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"59+checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"60 61 [[package]]62 name = "bstr"63-version = "0.2.16"63+version = "0.2.17"64 source = "registry+https://github.com/rust-lang/crates.io-index"65-checksum = "90682c8d613ad3373e66de8c6411e0ae2ab2571e879d2efbf73558cc66f21279"65+checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223"66 dependencies = [67 "memchr",68 ]69 70 [[package]]71 name = "cc"72-version = "1.0.70"72+version = "1.0.72"73 source = "registry+https://github.com/rust-lang/crates.io-index"74-checksum = "d26a6ce4b6a484fa3edb70f7efa6fc430fd2b87285fe8b84304fd0936faa0dc0"74+checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee"75 76 [[package]]77 name = "cfg-if"78 version = "1.0.0"40 unmodified lines119 ]120 121 [[package]]122 name = "ctrlc"123-version = "3.2.0"123+version = "3.2.1"124 source = "registry+https://github.com/rust-lang/crates.io-index"125-checksum = "377c9b002a72a0b2c1a18c62e2f3864bdfea4a015e3683a96e24aa45dd6c02d1"125+checksum = "a19c6cedffdc8c03a3346d723eb20bd85a13362bb96dc2ac000842c6381ec7bf"126 dependencies = [127 "nix",128 "winapi",129 ]41 unmodified lines171 "globset",172 "humantime",173 "ignore",174 "jemallocator",175- "lazy_static",175 "libc",176 "lscolors",177+ "nix",178 "normpath",179 "num_cpus",180 "once_cell",181 "regex",182 "regex-syntax",183 "tempdir",184+ "test-case",185 "users",186 "version_check",187 ]188 112 unmodified lines301 checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"302 303 [[package]]304 name = "libc"304-version = "0.2.103"305+version = "0.2.107"306 source = "registry+https://github.com/rust-lang/crates.io-index"306-checksum = "dd8f7255a17a627354f321ef0055d63b898c6fb27eff628af4d1b66b7331edf6"307+checksum = "fbe5e23404da5b4f555ef85ebed98fb4083e55a00c317800bc2a50ede9f3d219"308 309 [[package]]310 name = "log"311 version = "0.4.14"4 unmodified lines316 ]317 318 [[package]]319 name = "lscolors"319-version = "0.7.1"320+version = "0.8.1"321 source = "registry+https://github.com/rust-lang/crates.io-index"321-checksum = "d24b894c45c9da468621cdd615a5a79ee5e5523dd4f75c76ebc03d458940c16e"322+checksum = "9dd58d8727f3035fa6d5272f16b519741fd4875936b99d8a7cde21291b7d9174"323 dependencies = [324 "ansi_term 0.12.1",325 ]326 13 unmodified lines340 ]341 342 [[package]]343 name = "nix"343-version = "0.22.1"344+version = "0.23.0"345 source = "registry+https://github.com/rust-lang/crates.io-index"345-checksum = "e7555d6c7164cc913be1ce7f95cbecdabda61eb2ccd89008524af306fb7f5031"346+checksum = "f305c2c2e4c39a82f7bf0bf65fb557f9070ce06781d4f2454295cc34b1c43188"347 dependencies = [348 "bitflags",349 "cc",350 "cfg-if",2 unmodified lines353 ]354 355 [[package]]356 name = "normpath"356-version = "0.3.0"357+version = "0.3.1"358 source = "registry+https://github.com/rust-lang/crates.io-index"358-checksum = "27e6e8f70e9fbbe3752d330d769e3424f24b9458ce266df93a3b456902fd696a"359+checksum = "640c20e9df4a2d4a5adad5b47e17d76dac3e824346b181931c3ec9f7a85687b1"360 dependencies = [361 "winapi",362 ]363 32 unmodified lines396 source = "registry+https://github.com/rust-lang/crates.io-index"397 checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56"398 399 [[package]]400+name = "proc-macro2"401+version = "1.0.32"402+source = "registry+https://github.com/rust-lang/crates.io-index"403+checksum = "ba508cc11742c0dc5c1659771673afbab7a0efab23aa17e854cbab0837ed0b43"404+dependencies = [405+ "unicode-xid",406+]407+408+[[package]]409+name = "quote"410+version = "1.0.10"411+source = "registry+https://github.com/rust-lang/crates.io-index"412+checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05"413+dependencies = [414+ "proc-macro2",415+]416+417+[[package]]418 name = "rand"419 version = "0.4.6"420 source = "registry+https://github.com/rust-lang/crates.io-index"421 checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293"89 unmodified lines511 source = "registry+https://github.com/rust-lang/crates.io-index"512 checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"513 514 [[package]]515+name = "syn"516+version = "1.0.81"517+source = "registry+https://github.com/rust-lang/crates.io-index"518+checksum = "f2afee18b8beb5a596ecb4a2dce128c719b4ba399d34126b9e4396e3f9860966"519+dependencies = [520+ "proc-macro2",521+ "quote",522+ "unicode-xid",523+]524+525+[[package]]526 name = "tempdir"527 version = "0.3.7"528 source = "registry+https://github.com/rust-lang/crates.io-index"529 checksum = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8"12 unmodified lines542 "winapi",543 ]544 545 [[package]]546+name = "test-case"547+version = "1.2.1"548+source = "registry+https://github.com/rust-lang/crates.io-index"549+checksum = "c7cad0a06f9a61e94355aa3b3dc92d85ab9c83406722b1ca5e918d4297c12c23"550+dependencies = [551+ "cfg-if",552+ "proc-macro2",553+ "quote",554+ "syn",555+ "version_check",556+]557+558+[[package]]559 name = "textwrap"560 version = "0.11.0"561 source = "registry+https://github.com/rust-lang/crates.io-index"562 checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"22 unmodified lines585 ]586 587 [[package]]588 name = "unicode-width"546-version = "0.1.8"589+version = "0.1.9"590 source = "registry+https://github.com/rust-lang/crates.io-index"548-checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"591+checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973"592 593 [[package]]594+name = "unicode-xid"595+version = "0.2.2"596+source = "registry+https://github.com/rust-lang/crates.io-index"597+checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"598+599+[[package]]600 name = "users"601 version = "0.11.0"602 source = "registry+https://github.com/rust-lang/crates.io-index"603 checksum = "24cc0f6d6f267b73e5a2cadf007ba8f9bc39c6a6f9666f8cf25ea809a153b032"64 unmodified linesmodified:Cargo.toml+4 added-3 removed
35 unmodified lines36 [dependencies]37 ansi_term = "0.12"38 atty = "0.2"39 ignore = "0.4.3"40-lazy_static = "1.1.0"40 num_cpus = "1.8"41 regex = "1.5.4"42 regex-syntax = "0.6"43 ctrlc = "3.2"44 humantime = "2.1"46-lscolors = "0.7"45+lscolors = "0.8"46 globset = "0.4"47 anyhow = "1.0"48 dirs-next = "2.0"49 normpath = "0.3"5 unmodified lines55 features = ["suggestions", "color", "wrap_help"]56 57 [target.'cfg(unix)'.dependencies]58 users = "0.11.0"59+nix = "0.23.0"60 61 [target.'cfg(all(unix, not(target_os = "redox")))'.dependencies]62 libc = "0.2"63 5 unmodified lines69 70 [dev-dependencies]71 diff = "0.1"72 tempdir = "0.3"73-filetime = "0.2.15"73+filetime = "0.2"74+test-case = "1.2"75 76 [profile.release]77 lto = true78 codegen-units = 1modified:CHANGELOG.md+7 added-2 removed
2 unmodified lines3 ## Performance improvements4 5 - File metadata is now cached between the different filters that require it (e.g. `--owner`,6 `--size`), reducing the number of `stat` syscalls when multiple filters are used; see #8637+- Colorized output is now significantly faster, see #720 and #853 (@tavianator)8 9 ## Features9-- Don't buffer command output from `--exec` when using a single thread. See #52210 11+- Don't buffer command output from `--exec` when using a single thread. See #52212 - Add new `-q, --quiet` flag, see #303 (@Asha20)12-13 - Add new `--no-ignore-parent` flag, see #787 (@will459)14+- Add new `--batch-size` flag, see #410 (@devonhollowood)15+- Add opposing command-line options, see #595 (@Asha20)16+- Add support for more filesystem indicators in `LS_COLORS`, see17+ https://github.com/sharkdp/lscolors/pull/35 (@tavianator)18 19 ## Bugfixes20 21 - Always show the `./` prefix for search results unless the output is a TTY or `--strip-cwd-prefix` is set, see #760 and #861 (@jcaplan)4 unmodified lines26 - Use local time zone for time functions (`--change-newer-than`, `--change-older-than`), see #631 (@jacobmischka)27 - Support `--list-details` on more platforms (like BusyBox), see #78328 - The filters `--owner`, `--size`, and `--changed-{within,before}` now apply to symbolic links29 themselves, rather than the link target, except when `--follow` is specified; see #86330+- Change time comparisons to be exclusive, see #794 (@jacobmischka)31 32 ## Changes33 34 - Apply custom `--path-separator` to commands run with `--exec(-batch)` and `--list-details`, see #697 (@aswild)509 unmodified linesmodified:README.md+8 added-1 removed
416 unmodified lines417 > fd -- '-pattern'418 > fd '[-]pattern'419 ```420 421+### "Command not found" for `alias`es or shell functions422+423+Shell `alias`es and shell functions can not be used for command execution via `fd -x` or424+`fd -X`. In `zsh`, you can make the alias global via `alias -g myalias="…"`. In `bash`,425+you can use `export -f my_function` to make available to child processes. You would still426+need to call `fd -x bash -c 'my_function "$1"' bash`. For other use cases or shells, use427+a (temporary) shell script.428+429 ## Integration with other programs430 431 ### Using fd with `fzf`432 241 unmodified lines674 675 - [sharkdp](https://github.com/sharkdp)676 - [tmccombs](https://github.com/tmccombs)677 - [tavianator](https://github.com/tavianator)670-- [pemistahl](https://github.com/pemistahl/)678 679 ## License680 681 Copyright (c) 2017-2021 The fd developers4 unmodified lines