Merge pull request #861 from jcaplan/no-strip/760
Before adoption: this commit came in with the history the project adopted, so no landing records it.
show "./" prefix when search path provided
authored by David Peter · committed by GitHub · parents 0484486, 92bd785 · Browse files · 7 files·+425 added−378 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
7 files+425 added−378 removed
- tests:+403 added−371 removed
- other:+22 added−7 removed
Provenance
- Commit
b211ded- Tree
c8dff9b- Author
David Peter <sharkdp@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent 1
0484486- Parent 2
92bd785
7 files changed+425 added−378 removed
modified:src/exec/mod.rs+1 added-4 removed
12 unmodified lines13 use once_cell::sync::Lazy;14 use regex::Regex;15 16 use crate::exit_codes::ExitCode;17-use crate::filesystem::strip_current_dir;17 18 use self::command::execute_command;19 use self::input::{basename, dirname, remove_extension};20 pub use self::job::{batch, job};121 unmodified lines142 input: &Path,143 out_perm: Arc<Mutex<()>>,144 buffer_output: bool,145 ) -> ExitCode {147- let input = strip_current_dir(input);148-146 let mut cmd = Command::new(self.args[0].generate(&input, self.path_separator.as_deref()));147 for arg in &self.args[1..] {148 cmd.arg(arg.generate(&input, self.path_separator.as_deref()));149 }23 unmodified lines173 174 // A single `Tokens` is expected175 // So we can directly consume the iterator once and for all176 for path in &mut paths {180- cmd.arg(arg.generate(strip_current_dir(path), self.path_separator.as_deref()));177+ cmd.arg(arg.generate(path, self.path_separator.as_deref()));178 has_path = true;179 }180 } else {181 cmd.arg(arg.generate("", None));277 unmodified linesmodified:src/app.rs+11 added
702 unmodified lines703 "Provide paths to search as an alternative to the positional <path> \704 argument. Changes the usage to `fd [FLAGS/OPTIONS] --search-path <path> \705 --search-path <path2> [<pattern>]`",706 ),707+ )708+ .arg(709+ Arg::with_name("strip-cwd-prefix")710+ .long("strip-cwd-prefix")711+ .conflicts_with_all(&["path", "search-path"])712+ .hidden_short_help(true)713+ .help("strip './' prefix from non-tty outputs")714+ .long_help(715+ "By default, relative paths are prefixed with './' when the output goes to a non \716+ interactive terminal (TTY). Use this flag to disable this behaviour."717+ )718 );719 720 if cfg!(unix) {721 app = app.arg(39 unmodified linesmodified:src/config.rs+3 added
111 unmodified lines112 pub path_separator: Option<String>,113 114 /// The maximum number of search results115 pub max_results: Option<usize>,116+117+ /// Whether or not to strip the './' prefix for search results118+ pub strip_cwd_prefix: bool,119 }modified:src/main.rs+3 added
378 unmodified lines379 } else {380 None381 }382 }),383+ strip_cwd_prefix: (!matches.is_present("path")384+ && !matches.is_present("search-path")385+ && (interactive_terminal || matches.is_present("strip-cwd-prefix"))),386 })387 }388 389 fn extract_command(179 unmodified linesmodified:src/output.rs+3 added-3 removed
20 unmodified lines21 entry: &Path,22 config: &Config,23 wants_to_quit: &Arc<AtomicBool>,24 ) {25- let path = if entry.is_absolute() {26- entry27- } else {25+ let path = if config.strip_cwd_prefix {26 strip_current_dir(entry)27+ } else {28+ entry29 };30 31 let r = if let Some(ref ls_colors) = config.ls_colors {32 print_entry_colorized(stdout, path, config, ls_colors, wants_to_quit)112 unmodified linesmodified:tests/tests.rs+403 added-371 removed
59 unmodified lines60 #[test]61 fn test_simple() {62 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);63 64- te.assert_output(&["a.foo"], "a.foo");65- te.assert_output(&["b.foo"], "one/b.foo");66- te.assert_output(&["d.foo"], "one/two/three/d.foo");64+ te.assert_output(&["a.foo"], "./a.foo");65+ te.assert_output(&["b.foo"], "./one/b.foo");66+ te.assert_output(&["d.foo"], "./one/two/three/d.foo");67 68 te.assert_output(69 &["foo"],70- "a.foo71- one/b.foo72- one/two/c.foo73- one/two/C.Foo274- one/two/three/d.foo75- one/two/three/directory_foo",70+ "./a.foo71+ ./one/b.foo72+ ./one/two/c.foo73+ ./one/two/C.Foo274+ ./one/two/three/d.foo75+ ./one/two/three/directory_foo",76 );77 }78 79 /// Test each pattern type with an empty pattern.80 #[test]81 fn test_empty_pattern() {82 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);83- let expected = "a.foo84- e1 e285- one86- one/b.foo87- one/two88- one/two/c.foo89- one/two/C.Foo290- one/two/three91- one/two/three/d.foo92- one/two/three/directory_foo93- symlink";83+ let expected = "./a.foo84+ ./e1 e285+ ./one86+ ./one/b.foo87+ ./one/two88+ ./one/two/c.foo89+ ./one/two/C.Foo290+ ./one/two/three91+ ./one/two/three/d.foo92+ ./one/two/three/directory_foo93+ ./symlink";94 95 te.assert_output(&["--regex"], expected);96 te.assert_output(&["--fixed-strings"], expected);97 te.assert_output(&["--glob"], expected);110 unmodified lines208 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);209 210 te.assert_output(211 &["[a-c].foo"],212- "a.foo213- one/b.foo214- one/two/c.foo215- one/two/C.Foo2",212+ "./a.foo213+ ./one/b.foo214+ ./one/two/c.foo215+ ./one/two/C.Foo2",216 );217 218 te.assert_output(219 &["--case-sensitive", "[a-c].foo"],220- "a.foo221- one/b.foo222- one/two/c.foo",220+ "./a.foo221+ ./one/b.foo222+ ./one/two/c.foo",223 );224 }225 226 /// Smart case2 unmodified lines229 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);230 231 te.assert_output(232 &["c.foo"],233- "one/two/c.foo234- one/two/C.Foo2",233+ "./one/two/c.foo234+ ./one/two/C.Foo2",235 );236 237- te.assert_output(&["C.Foo"], "one/two/C.Foo2");237+ te.assert_output(&["C.Foo"], "./one/two/C.Foo2");238 239- te.assert_output(&["Foo"], "one/two/C.Foo2");239+ te.assert_output(&["Foo"], "./one/two/C.Foo2");240 241 // Only literal uppercase chars should trigger case sensitivity.242 te.assert_output(243 &["\\Ac"],244- "one/two/c.foo245- one/two/C.Foo2",244+ "./one/two/c.foo245+ ./one/two/C.Foo2",246 );247- te.assert_output(&["\\AC"], "one/two/C.Foo2");247+ te.assert_output(&["\\AC"], "./one/two/C.Foo2");248 }249 250 /// Case sensitivity (--case-sensitive)251 #[test]252 fn test_case_sensitive() {253 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);254 255- te.assert_output(&["--case-sensitive", "c.foo"], "one/two/c.foo");255+ te.assert_output(&["--case-sensitive", "c.foo"], "./one/two/c.foo");256 257- te.assert_output(&["--case-sensitive", "C.Foo"], "one/two/C.Foo2");257+ te.assert_output(&["--case-sensitive", "C.Foo"], "./one/two/C.Foo2");258 259 te.assert_output(260 &["--ignore-case", "--case-sensitive", "C.Foo"],261- "one/two/C.Foo2",261+ "./one/two/C.Foo2",262 );263 }264 265 /// Case insensitivity (--ignore-case)2 unmodified lines268 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);269 270 te.assert_output(271 &["--ignore-case", "C.Foo"],272- "one/two/c.foo273- one/two/C.Foo2",272+ "./one/two/c.foo273+ ./one/two/C.Foo2",274 );275 276 te.assert_output(277 &["--case-sensitive", "--ignore-case", "C.Foo"],278- "one/two/c.foo279- one/two/C.Foo2",278+ "./one/two/c.foo279+ ./one/two/C.Foo2",280 );281 }282 283 /// Glob-based searches (--glob)2 unmodified lines286 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);287 288 te.assert_output(289 &["--glob", "*.foo"],290- "a.foo291- one/b.foo292- one/two/c.foo293- one/two/three/d.foo",290+ "./a.foo291+ ./one/b.foo292+ ./one/two/c.foo293+ ./one/two/three/d.foo",294 );295 296 te.assert_output(297 &["--glob", "[a-c].foo"],298- "a.foo299- one/b.foo300- one/two/c.foo",298+ "./a.foo299+ ./one/b.foo300+ ./one/two/c.foo",301 );302 303 te.assert_output(304 &["--glob", "[a-c].foo*"],305- "a.foo306- one/b.foo307- one/two/C.Foo2308- one/two/c.foo",305+ "./a.foo306+ ./one/b.foo307+ ./one/two/C.Foo2308+ ./one/two/c.foo",309 );310 }311 312 /// Glob-based searches (--glob) in combination with full path searches (--full-path)3 unmodified lines316 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);317 318 te.assert_output(319 &["--glob", "--full-path", "**/one/**/*.foo"],320- "one/b.foo321- one/two/c.foo322- one/two/three/d.foo",320+ "./one/b.foo321+ ./one/two/c.foo322+ ./one/two/three/d.foo",323 );324 325 te.assert_output(326 &["--glob", "--full-path", "**/one/*/*.foo"],327- " one/two/c.foo",327+ " ./one/two/c.foo",328 );329 330 te.assert_output(331 &["--glob", "--full-path", "**/one/*/*/*.foo"],332- " one/two/three/d.foo",332+ " ./one/two/three/d.foo",333 );334 }335 336 #[test]1 unmodified line338 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);339 340 te.assert_output(341 &["--glob", "c.foo*"],342- "one/two/C.Foo2343- one/two/c.foo",342+ "./one/two/C.Foo2343+ ./one/two/c.foo",344 );345 346- te.assert_output(&["--glob", "C.Foo*"], "one/two/C.Foo2");346+ te.assert_output(&["--glob", "C.Foo*"], "./one/two/C.Foo2");347 }348 349 /// Glob-based searches (--glob) in combination with --case-sensitive350 #[test]351 fn test_case_sensitive_glob_searches() {352 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);353 354- te.assert_output(&["--glob", "--case-sensitive", "c.foo*"], "one/two/c.foo");354+ te.assert_output(&["--glob", "--case-sensitive", "c.foo*"], "./one/two/c.foo");355 }356 357 /// Glob-based searches (--glob) in combination with --extension358 #[test]1 unmodified line360 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);361 362 te.assert_output(363 &["--glob", "--extension", "foo2", "[a-z].*"],364- "one/two/C.Foo2",364+ "./one/two/C.Foo2",365 );366 }367 368 /// Make sure that --regex overrides --glob369 #[test]370 fn test_regex_overrides_glob() {371 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);372 373- te.assert_output(&["--glob", "--regex", "Foo2$"], "one/two/C.Foo2");373+ te.assert_output(&["--glob", "--regex", "Foo2$"], "./one/two/C.Foo2");374 }375 376 /// Full path search (--full-path)377 #[test]7 unmodified lines385 &[386 "--full-path",387 &format!("^{prefix}.*three.*foo$", prefix = prefix),388 ],389- "one/two/three/d.foo390- one/two/three/directory_foo",389+ "./one/two/three/d.foo390+ ./one/two/three/directory_foo",391 );392 }393 394 /// Hidden files (--hidden)2 unmodified lines397 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);398 399 te.assert_output(400 &["--hidden", "foo"],401- ".hidden.foo402- a.foo403- one/b.foo404- one/two/c.foo405- one/two/C.Foo2406- one/two/three/d.foo407- one/two/three/directory_foo",401+ "./.hidden.foo402+ ./a.foo403+ ./one/b.foo404+ ./one/two/c.foo405+ ./one/two/C.Foo2406+ ./one/two/three/d.foo407+ ./one/two/three/directory_foo",408 );409 }410 411 /// Hidden file attribute on Windows13 unmodified lines425 .attributes(FILE_ATTRIBUTE_HIDDEN)426 .open(te.test_root().join("hidden-file.txt"))427 .unwrap();428 429- te.assert_output(&["--hidden", "hidden-file.txt"], "hidden-file.txt");429+ te.assert_output(&["--hidden", "hidden-file.txt"], "./hidden-file.txt");430 te.assert_output(&["hidden-file.txt"], "");431 }432 433 /// Ignored files (--no-ignore)2 unmodified lines436 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);437 438 te.assert_output(439 &["--no-ignore", "foo"],440- "a.foo441- fdignored.foo442- gitignored.foo443- one/b.foo444- one/two/c.foo445- one/two/C.Foo2446- one/two/three/d.foo447- one/two/three/directory_foo",440+ "./a.foo441+ ./fdignored.foo442+ ./gitignored.foo443+ ./one/b.foo444+ ./one/two/c.foo445+ ./one/two/C.Foo2446+ ./one/two/three/d.foo447+ ./one/two/three/directory_foo",448 );449 450 te.assert_output(451 &["--hidden", "--no-ignore", "foo"],452- ".hidden.foo453- a.foo454- fdignored.foo455- gitignored.foo456- one/b.foo457- one/two/c.foo458- one/two/C.Foo2459- one/two/three/d.foo460- one/two/three/directory_foo",452+ "./.hidden.foo453+ ./a.foo454+ ./fdignored.foo455+ ./gitignored.foo456+ ./one/b.foo457+ ./one/two/c.foo458+ ./one/two/C.Foo2459+ ./one/two/three/d.foo460+ ./one/two/three/directory_foo",461 );462 }463 464 /// .gitignore and .fdignore16 unmodified lines481 .unwrap()482 .write_all(b"ignored-by-gitignore\nignored-by-both")483 .unwrap();484 485- te.assert_output(&["ignored"], "ignored-by-nothing");485+ te.assert_output(&["ignored"], "./ignored-by-nothing");486 487 te.assert_output(488 &["--no-ignore-vcs", "ignored"],489- "ignored-by-nothing490- ignored-by-gitignore",489+ "./ignored-by-nothing490+ ./ignored-by-gitignore",491 );492 493 te.assert_output(494 &["--no-ignore", "ignored"],495- "ignored-by-nothing496- ignored-by-fdignore497- ignored-by-gitignore498- ignored-by-both",495+ "./ignored-by-nothing496+ ./ignored-by-fdignore497+ ./ignored-by-gitignore498+ ./ignored-by-both",499 );500 }501 502 /// Ignore parent ignore files (--no-ignore-parent)17 unmodified lines520 .unwrap()521 .write_all(b"child-ignored")522 .unwrap();523 524- te.assert_output_subdirectory("inner", &[], "not-ignored");524+ te.assert_output_subdirectory("inner", &[], "./not-ignored");525 526 te.assert_output_subdirectory(527 "inner",528 &["--no-ignore-parent"],529- "parent-ignored530- not-ignored",529+ "./parent-ignored530+ ./not-ignored",531 );532 }533 534 /// Ignore parent ignore files (--no-ignore-parent) with an inner git repo23 unmodified lines558 559 te.assert_output_subdirectory(560 "inner",561 &[],562- "not-ignored563- parent-ignored",562+ "./not-ignored563+ ./parent-ignored",564 );565 566 te.assert_output_subdirectory(567 "inner",568 &["--no-ignore-parent"],569- "not-ignored570- parent-ignored",569+ "./not-ignored570+ ./parent-ignored",571 );572 }573 574 /// Precedence of .fdignore files14 unmodified lines589 .unwrap()590 .write_all(b"!foo")591 .unwrap();592 593- te.assert_output(&["foo"], "inner/foo");593+ te.assert_output(&["foo"], "./inner/foo");594 595- te.assert_output(&["--no-ignore-vcs", "foo"], "inner/foo");595+ te.assert_output(&["--no-ignore-vcs", "foo"], "./inner/foo");596 597- te.assert_output(&["--no-ignore", "foo"], "inner/foo");597+ te.assert_output(&["--no-ignore", "foo"], "./inner/foo");598 }599 600 /// VCS ignored files (--no-ignore-vcs)601 #[test]1 unmodified line603 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);604 605 te.assert_output(606 &["--no-ignore-vcs", "foo"],607- "a.foo608- gitignored.foo609- one/b.foo610- one/two/c.foo611- one/two/C.Foo2612- one/two/three/d.foo613- one/two/three/directory_foo",607+ "./a.foo608+ ./gitignored.foo609+ ./one/b.foo610+ ./one/two/c.foo611+ ./one/two/C.Foo2612+ ./one/two/three/d.foo613+ ./one/two/three/directory_foo",614 );615 }616 617 /// Custom ignore files (--ignore-file)8 unmodified lines626 .unwrap();627 628 te.assert_output(629 &["--ignore-file", "custom.ignore", "foo"],630- "a.foo631- one/b.foo632- one/two/c.foo",630+ "./a.foo631+ ./one/b.foo632+ ./one/two/c.foo",633 );634 }635 636 /// Ignored files with ripgrep aliases (-u / -uu)2 unmodified lines639 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);640 641 te.assert_output(642 &["-u", "foo"],643- "a.foo644- fdignored.foo645- gitignored.foo646- one/b.foo647- one/two/c.foo648- one/two/C.Foo2649- one/two/three/d.foo650- one/two/three/directory_foo",643+ "./a.foo644+ ./fdignored.foo645+ ./gitignored.foo646+ ./one/b.foo647+ ./one/two/c.foo648+ ./one/two/C.Foo2649+ ./one/two/three/d.foo650+ ./one/two/three/directory_foo",651 );652 653 te.assert_output(654 &["-uu", "foo"],655- ".hidden.foo656- a.foo657- fdignored.foo658- gitignored.foo659- one/b.foo660- one/two/c.foo661- one/two/C.Foo2662- one/two/three/d.foo663- one/two/three/directory_foo",655+ "./.hidden.foo656+ ./a.foo657+ ./fdignored.foo658+ ./gitignored.foo659+ ./one/b.foo660+ ./one/two/c.foo661+ ./one/two/C.Foo2662+ ./one/two/three/d.foo663+ ./one/two/three/directory_foo",664 );665 }666 667 /// Symlinks (--follow)2 unmodified lines670 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);671 672 te.assert_output(673 &["--follow", "c.foo"],674- "one/two/c.foo675- one/two/C.Foo2676- symlink/c.foo677- symlink/C.Foo2",674+ "./one/two/c.foo675+ ./one/two/C.Foo2676+ ./symlink/c.foo677+ ./symlink/C.Foo2",678 );679 }680 681 // File system boundaries (--one-file-system)46 unmodified lines728 .expect("Failed to create broken symlink.");729 730 te.assert_output(731 &["symlink"],732- "broken_symlink733- symlink",732+ "./broken_symlink733+ ./symlink",734 );735 te.assert_output(736 &["--type", "symlink", "symlink"],737- "broken_symlink738- symlink",737+ "./broken_symlink738+ ./symlink",739 );740 741 te.assert_output(&["--type", "file", "symlink"], "");742 743 te.assert_output(744 &["--follow", "--type", "symlink", "symlink"],745- "broken_symlink",745+ "./broken_symlink",746 );747 te.assert_output(&["--follow", "--type", "file", "symlink"], "");748 }749 3 unmodified lines753 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);754 755 te.assert_output(756 &["--print0", "foo"],757- "a.fooNULL758- one/b.fooNULL759- one/two/C.Foo2NULL760- one/two/c.fooNULL761- one/two/three/d.fooNULL762- one/two/three/directory_fooNULL",757+ "./a.fooNULL758+ ./one/b.fooNULL759+ ./one/two/C.Foo2NULL760+ ./one/two/c.fooNULL761+ ./one/two/three/d.fooNULL762+ ./one/two/three/directory_fooNULL",763 );764 }765 766 /// Maximum depth (--max-depth)2 unmodified lines769 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);770 771 te.assert_output(772 &["--max-depth", "3"],773- "a.foo774- e1 e2775- one776- one/b.foo777- one/two778- one/two/c.foo779- one/two/C.Foo2780- one/two/three781- symlink",773+ "./a.foo774+ ./e1 e2775+ ./one776+ ./one/b.foo777+ ./one/two778+ ./one/two/c.foo779+ ./one/two/C.Foo2780+ ./one/two/three781+ ./symlink",782 );783 784 te.assert_output(785 &["--max-depth", "2"],786- "a.foo787- e1 e2788- one789- one/b.foo790- one/two791- symlink",786+ "./a.foo787+ ./e1 e2788+ ./one789+ ./one/b.foo790+ ./one/two791+ ./symlink",792 );793 794 te.assert_output(795 &["--max-depth", "1"],796- "a.foo797- e1 e2798- one799- symlink",796+ "./a.foo797+ ./e1 e2798+ ./one799+ ./symlink",800 );801 }802 803 /// Minimum depth (--min-depth)2 unmodified lines806 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);807 808 te.assert_output(809 &["--min-depth", "3"],810- "one/two/c.foo811- one/two/C.Foo2812- one/two/three813- one/two/three/d.foo814- one/two/three/directory_foo",810+ "./one/two/c.foo811+ ./one/two/C.Foo2812+ ./one/two/three813+ ./one/two/three/d.foo814+ ./one/two/three/directory_foo",815 );816 817 te.assert_output(818 &["--min-depth", "4"],819- "one/two/three/d.foo820- one/two/three/directory_foo",819+ "./one/two/three/d.foo820+ ./one/two/three/directory_foo",821 );822 }823 824 /// Exact depth (--exact-depth)2 unmodified lines827 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);828 829 te.assert_output(830 &["--exact-depth", "3"],831- "one/two/c.foo832- one/two/C.Foo2833- one/two/three",831+ "./one/two/c.foo832+ ./one/two/C.Foo2833+ ./one/two/three",834 );835 }836 837 /// Pruning (--prune)838 #[test]839 fn test_prune() {840 let dirs = &["foo/bar", "bar/foo", "baz"];841 let files = &[842- "foo/foo.file",843- "foo/bar/foo.file",844- "bar/foo.file",845- "bar/foo/foo.file",846- "baz/foo.file",842+ "./foo/foo.file",843+ "./foo/bar/foo.file",844+ "./bar/foo.file",845+ "./bar/foo/foo.file",846+ "./baz/foo.file",847 ];848 849 let te = TestEnv::new(dirs, files);850 851 te.assert_output(852 &["foo"],853- "foo854- foo/foo.file855- foo/bar/foo.file856- bar/foo.file857- bar/foo858- bar/foo/foo.file859- baz/foo.file",853+ "./foo854+ ./foo/foo.file855+ ./foo/bar/foo.file856+ ./bar/foo.file857+ ./bar/foo858+ ./bar/foo/foo.file859+ ./baz/foo.file",860 );861 862 te.assert_output(863 &["--prune", "foo"],864- "foo865- bar/foo866- bar/foo.file867- baz/foo.file",864+ "./foo865+ ./bar/foo866+ ./bar/foo.file867+ ./baz/foo.file",868 );869 }870 871 /// Absolute paths (--absolute-path)78 unmodified lines950 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);951 952 te.assert_output(953 &["--type", "f"],954- "a.foo955- e1 e2956- one/b.foo957- one/two/c.foo958- one/two/C.Foo2959- one/two/three/d.foo",954+ "./a.foo955+ ./e1 e2956+ ./one/b.foo957+ ./one/two/c.foo958+ ./one/two/C.Foo2959+ ./one/two/three/d.foo",960 );961 962- te.assert_output(&["--type", "f", "e1"], "e1 e2");962+ te.assert_output(&["--type", "f", "e1"], "./e1 e2");963 964 te.assert_output(965 &["--type", "d"],966- "one967- one/two968- one/two/three969- one/two/three/directory_foo",966+ "./one967+ ./one/two968+ ./one/two/three969+ ./one/two/three/directory_foo",970 );971 972 te.assert_output(973 &["--type", "d", "--type", "l"],974- "one975- one/two976- one/two/three977- one/two/three/directory_foo978- symlink",974+ "./one975+ ./one/two976+ ./one/two/three977+ ./one/two/three/directory_foo978+ ./symlink",979 );980 981- te.assert_output(&["--type", "l"], "symlink");981+ te.assert_output(&["--type", "l"], "./symlink");982 }983 984 /// Test `--type executable`985 #[cfg(unix)]9 unmodified lines995 .mode(0o777)996 .open(te.test_root().join("executable-file.sh"))997 .unwrap();998 999- te.assert_output(&["--type", "executable"], "executable-file.sh");999+ te.assert_output(&["--type", "executable"], "./executable-file.sh");1000 1001 te.assert_output(1002 &["--type", "executable", "--type", "directory"],1003- "executable-file.sh1004- one1005- one/two1006- one/two/three1007- one/two/three/directory_foo",1003+ "./executable-file.sh1004+ ./one1005+ ./one/two1006+ ./one/two/three1007+ ./one/two/three/directory_foo",1008 );1009 }1010 1011 /// Test `--type empty`7 unmodified lines1019 create_file_with_size(te.test_root().join("dir_nonempty").join("2_bytes.foo"), 2);1020 1021 te.assert_output(1022 &["--type", "empty"],1023- "0_bytes.foo1024- dir_empty",1023+ "./0_bytes.foo1024+ ./dir_empty",1025 );1026 1027 te.assert_output(1028 &["--type", "empty", "--type", "file", "--type", "directory"],1029- "0_bytes.foo1030- dir_empty",1029+ "./0_bytes.foo1030+ ./dir_empty",1031 );1032 1033- te.assert_output(&["--type", "empty", "--type", "file"], "0_bytes.foo");1033+ te.assert_output(&["--type", "empty", "--type", "file"], "./0_bytes.foo");1034 1035- te.assert_output(&["--type", "empty", "--type", "directory"], "dir_empty");1035+ te.assert_output(&["--type", "empty", "--type", "directory"], "./dir_empty");1036 }1037 1038 /// File extension (--extension)1039 #[test]1 unmodified line1041 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);1042 1043 te.assert_output(1044 &["--extension", "foo"],1045- "a.foo1046- one/b.foo1047- one/two/c.foo1048- one/two/three/d.foo",1045+ "./a.foo1046+ ./one/b.foo1047+ ./one/two/c.foo1048+ ./one/two/three/d.foo",1049 );1050 1051 te.assert_output(1052 &["--extension", ".foo"],1053- "a.foo1054- one/b.foo1055- one/two/c.foo1056- one/two/three/d.foo",1053+ "./a.foo1054+ ./one/b.foo1055+ ./one/two/c.foo1056+ ./one/two/three/d.foo",1057 );1058 1059 te.assert_output(1060 &["--extension", ".foo", "--extension", "foo2"],1061- "a.foo1062- one/b.foo1063- one/two/c.foo1064- one/two/three/d.foo1065- one/two/C.Foo2",1061+ "./a.foo1062+ ./one/b.foo1063+ ./one/two/c.foo1064+ ./one/two/three/d.foo1065+ ./one/two/C.Foo2",1066 );1067 1068- te.assert_output(&["--extension", ".foo", "a"], "a.foo");1068+ te.assert_output(&["--extension", ".foo", "a"], "./a.foo");1069 1070- te.assert_output(&["--extension", "foo2"], "one/two/C.Foo2");1070+ te.assert_output(&["--extension", "foo2"], "./one/two/C.Foo2");1071 1072 let te2 = TestEnv::new(&[], &["spam.bar.baz", "egg.bar.baz", "yolk.bar.baz.sig"]);1073 1074 te2.assert_output(1075 &["--extension", ".bar.baz"],1076- "spam.bar.baz1077- egg.bar.baz",1076+ "./spam.bar.baz1077+ ./egg.bar.baz",1078 );1079 1080- te2.assert_output(&["--extension", "sig"], "yolk.bar.baz.sig");1080+ te2.assert_output(&["--extension", "sig"], "./yolk.bar.baz.sig");1081 1082- te2.assert_output(&["--extension", "bar.baz.sig"], "yolk.bar.baz.sig");1082+ te2.assert_output(&["--extension", "bar.baz.sig"], "./yolk.bar.baz.sig");1083 1084 let te3 = TestEnv::new(&[], &["latin1.e\u{301}xt", "smiley.☻"]);1085 1086- te3.assert_output(&["--extension", "☻"], "smiley.☻");1086+ te3.assert_output(&["--extension", "☻"], "./smiley.☻");1087 1088- te3.assert_output(&["--extension", ".e\u{301}xt"], "latin1.e\u{301}xt");1088+ te3.assert_output(&["--extension", ".e\u{301}xt"], "./latin1.e\u{301}xt");1089 1090 let te4 = TestEnv::new(&[], &[".hidden", "test.hidden"]);1091 1092- te4.assert_output(&["--hidden", "--extension", ".hidden"], "test.hidden");1092+ te4.assert_output(&["--hidden", "--extension", ".hidden"], "./test.hidden");1093 }1094 1095 /// No file extension (test for the pattern provided in the --help text)1096 #[test]4 unmodified lines1101 );1102 1103 te.assert_output(1104 &["^[^.]+$"],1105- "aa1106- one1107- one/bb1108- one/two1109- one/two/three1110- one/two/three/d1111- one/two/three/directory_foo1112- symlink",1105+ "./aa1106+ ./one1107+ ./one/bb1108+ ./one/two1109+ ./one/two/three1110+ ./one/two/three/d1111+ ./one/two/three/directory_foo1112+ ./symlink",1113 );1114 1115 te.assert_output(1116 &["^[^.]+$", "--type", "file"],1117- "aa1118- one/bb1119- one/two/three/d",1117+ "./aa1118+ ./one/bb1119+ ./one/two/three/d",1120 );1121 }1122 1123 /// Symlink as search directory126 unmodified lines1250 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);1251 1252 te.assert_output(1253 &["--exclude", "*.foo"],1254- "one1255- one/two1256- one/two/C.Foo21257- one/two/three1258- one/two/three/directory_foo1259- e1 e21260- symlink",1254+ "./one1255+ ./one/two1256+ ./one/two/C.Foo21257+ ./one/two/three1258+ ./one/two/three/directory_foo1259+ ./e1 e21260+ ./symlink",1261 );1262 1263 te.assert_output(1264 &["--exclude", "*.foo", "--exclude", "*.Foo2"],1265- "one1266- one/two1267- one/two/three1268- one/two/three/directory_foo1269- e1 e21270- symlink",1265+ "./one1266+ ./one/two1267+ ./one/two/three1268+ ./one/two/three/directory_foo1269+ ./e1 e21270+ ./symlink",1271 );1272 1273 te.assert_output(1274 &["--exclude", "*.foo", "--exclude", "*.Foo2", "foo"],1275- "one/two/three/directory_foo",1275+ "./one/two/three/directory_foo",1276 );1277 1278 te.assert_output(1279 &["--exclude", "one/two", "foo"],1280- "a.foo1281- one/b.foo",1280+ "./a.foo1281+ ./one/b.foo",1282 );1283 1284 te.assert_output(1285 &["--exclude", "one/**/*.foo"],1286- "a.foo1287- e1 e21288- one1289- one/two1290- one/two/C.Foo21291- one/two/three1292- one/two/three/directory_foo1293- symlink",1286+ "./a.foo1287+ ./e1 e21288+ ./one1289+ ./one/two1290+ ./one/two/C.Foo21291+ ./one/two/three1292+ ./one/two/three/directory_foo1293+ ./symlink",1294 );1295 }1296 1297 /// Shell script execution (--exec)16 unmodified lines1314 );1315 1316 te.assert_output(1317 &["foo", "--exec", "echo", "{}"],1318- "a.foo1319- one/b.foo1320- one/two/C.Foo21321- one/two/c.foo1322- one/two/three/d.foo1323- one/two/three/directory_foo",1318+ "./a.foo1319+ ./one/b.foo1320+ ./one/two/C.Foo21321+ ./one/two/c.foo1322+ ./one/two/three/d.foo1323+ ./one/two/three/directory_foo",1324 );1325 1326 te.assert_output(1327 &["foo", "--exec", "echo", "{.}"],27 unmodified lines1355 1356 te.assert_output(1357 &["foo", "--exec", "echo", "{//}"],1358 ".1359- one1360- one/two1361- one/two1362- one/two/three1363- one/two/three",1359+ ./one1360+ ./one/two1361+ ./one/two1362+ ./one/two/three1363+ ./one/two/three",1364 );1365 1366- te.assert_output(&["e1", "--exec", "printf", "%s.%s\n"], "e1 e2.");1366+ te.assert_output(&["e1", "--exec", "printf", "%s.%s\n"], "./e1 e2.");1367 }1368 }1369 1370 #[test]12 unmodified lines1383 );1384 1385 te.assert_output(1386 &["foo", "--exec-batch", "echo", "{}"],1387- "a.foo one/b.foo one/two/C.Foo2 one/two/c.foo one/two/three/d.foo one/two/three/directory_foo",1387+ "./a.foo ./one/b.foo ./one/two/C.Foo2 ./one/two/c.foo ./one/two/three/d.foo ./one/two/three/directory_foo",1388 );1389 1390 te.assert_output(1391 &["foo", "--exec-batch", "echo", "{/}"],37 unmodified lines1429 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",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 ".",12 unmodified lines1450 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"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 21 unmodified lines1485 );1486 1487 te.assert_output(1488 &["--path-separator=#", "foo", "--exec", "echo", "{}"],1489- "a.foo1490- one#b.foo1491- one#two#C.Foo21492- one#two#c.foo1493- one#two#three#d.foo1494- one#two#three#directory_foo",1489+ ".#a.foo1490+ .#one#b.foo1491+ .#one#two#C.Foo21492+ .#one#two#c.foo1493+ .#one#two#three#d.foo1494+ .#one#two#three#directory_foo",1495 );1496 1497 te.assert_output(1498 &["--path-separator=#", "foo", "--exec", "echo", "{.}"],27 unmodified lines1526 1527 te.assert_output(1528 &["--path-separator=#", "foo", "--exec", "echo", "{//}"],1529 ".1530- one1531- one#two1532- one#two1533- one#two#three1534- one#two#three",1530+ .#one1531+ .#one#two1532+ .#one#two1533+ .#one#two#three1534+ .#one#two#three",1535 );1536 1537 te.assert_output(1538 &["--path-separator=#", "e1", "--exec", "printf", "%s.%s\n"],1539- "e1 e2.",1539+ ".#e1 e2.",1540 );1541 }1542 1543 /// Non-zero exit code (--quiet)18 unmodified lines1562 1563 // Regex search, dot is treated as "any character"1564 te.assert_output(1565 &["a.foo"],1566- "test1/a.foo1567- test1/a_foo",1566+ "./test1/a.foo1567+ ./test1/a_foo",1568 );1569 1570 // Literal search, dot is treated as character1571- te.assert_output(&["--fixed-strings", "a.foo"], "test1/a.foo");1571+ te.assert_output(&["--fixed-strings", "a.foo"], "./test1/a.foo");1572 1573 // Regex search, parens are treated as group1574 te.assert_output(&["download (1)"], "");1575 1576 // Literal search, parens are treated as characters1577 te.assert_output(1578 &["--fixed-strings", "download (1)"],1579- "test2/Download (1).tar.gz",1579+ "./test2/Download (1).tar.gz",1580 );1581 1582 // Combine with --case-sensitive1583 te.assert_output(&["--fixed-strings", "--case-sensitive", "download (1)"], "");37 unmodified lines1621 1622 // Zero and non-zero sized files.1623 te.assert_output(1624 &["", "--size", "+0B"],1625- "0_bytes.foo1626- 11_bytes.foo1627- 30_bytes.foo1628- 3_kilobytes.foo1629- 4_kibibytes.foo",1625+ "./0_bytes.foo1626+ ./11_bytes.foo1627+ ./30_bytes.foo1628+ ./3_kilobytes.foo1629+ ./4_kibibytes.foo",1630 );1631 1632 // Zero sized files.1633- te.assert_output(&["", "--size", "-0B"], "0_bytes.foo");1634- te.assert_output(&["", "--size", "0B"], "0_bytes.foo");1635- te.assert_output(&["", "--size=0B"], "0_bytes.foo");1636- te.assert_output(&["", "-S", "0B"], "0_bytes.foo");1633+ te.assert_output(&["", "--size", "-0B"], "./0_bytes.foo");1634+ te.assert_output(&["", "--size", "0B"], "./0_bytes.foo");1635+ te.assert_output(&["", "--size=0B"], "./0_bytes.foo");1636+ te.assert_output(&["", "-S", "0B"], "./0_bytes.foo");1637 1638 // Files with 2 bytes or more.1639 te.assert_output(1640 &["", "--size", "+2B"],1641- "11_bytes.foo1642- 30_bytes.foo1643- 3_kilobytes.foo1644- 4_kibibytes.foo",1641+ "./11_bytes.foo1642+ ./30_bytes.foo1643+ ./3_kilobytes.foo1644+ ./4_kibibytes.foo",1645 );1646 1647 // Files with 2 bytes or less.1648- te.assert_output(&["", "--size", "-2B"], "0_bytes.foo");1648+ te.assert_output(&["", "--size", "-2B"], "./0_bytes.foo");1649 1650 // Files with size between 1 byte and 11 bytes.1651- te.assert_output(&["", "--size", "+1B", "--size", "-11B"], "11_bytes.foo");1651+ te.assert_output(&["", "--size", "+1B", "--size", "-11B"], "./11_bytes.foo");1652 1653 // Files with size equal 11 bytes.1654- te.assert_output(&["", "--size", "11B"], "11_bytes.foo");1654+ te.assert_output(&["", "--size", "11B"], "./11_bytes.foo");1655 1656 // Files with size between 1 byte and 30 bytes.1657 te.assert_output(1658 &["", "--size", "+1B", "--size", "-30B"],1659- "11_bytes.foo1660- 30_bytes.foo",1659+ "./11_bytes.foo1660+ ./30_bytes.foo",1661 );1662 1663 // Combine with a search pattern1664- te.assert_output(&["^11_", "--size", "+1B", "--size", "-30B"], "11_bytes.foo");1664+ te.assert_output(1665+ &["^11_", "--size", "+1B", "--size", "-30B"],1666+ "./11_bytes.foo",1667+ );1668 1669 // Files with size between 12 and 30 bytes.1667- te.assert_output(&["", "--size", "+12B", "--size", "-30B"], "30_bytes.foo");1670+ te.assert_output(&["", "--size", "+12B", "--size", "-30B"], "./30_bytes.foo");1671 1672 // Files with size between 31 and 100 bytes.1673 te.assert_output(&["", "--size", "+31B", "--size", "-100B"], "");1674 1675 // Files with size between 3 kibibytes and 5 kibibytes.1673- te.assert_output(&["", "--size", "+3ki", "--size", "-5ki"], "4_kibibytes.foo");1676+ te.assert_output(1677+ &["", "--size", "+3ki", "--size", "-5ki"],1678+ "./4_kibibytes.foo",1679+ );1680 1681 // Files with size between 3 kilobytes and 5 kilobytes.1682 te.assert_output(1683 &["", "--size", "+3k", "--size", "-5k"],1678- "3_kilobytes.foo1679- 4_kibibytes.foo",1684+ "./3_kilobytes.foo1685+ ./4_kibibytes.foo",1686 );1687 1688 // Files with size greater than 3 kilobytes and less than 3 kibibytes.1683- te.assert_output(&["", "--size", "+3k", "--size", "-3ki"], "3_kilobytes.foo");1689+ te.assert_output(1690+ &["", "--size", "+3k", "--size", "-3ki"],1691+ "./3_kilobytes.foo",1692+ );1693 1694 // Files with size equal 4 kibibytes.1686- te.assert_output(&["", "--size", "+4ki", "--size", "-4ki"], "4_kibibytes.foo");1687- te.assert_output(&["", "--size", "4ki"], "4_kibibytes.foo");1695+ te.assert_output(1696+ &["", "--size", "+4ki", "--size", "-4ki"],1697+ "./4_kibibytes.foo",1698+ );1699+ te.assert_output(&["", "--size", "4ki"], "./4_kibibytes.foo");1700 }1701 1702 #[cfg(test)]1703 fn create_file_with_modified<P: AsRef<Path>>(path: P, duration_in_secs: u64) {27 unmodified lines1731 create_file_with_modified(te.test_root().join("bar_1_day"), 24 * 60 * 60);1732 1733 te.assert_output(1734 &["", "--changed-within", "15min"],1723- "foo_0_now1724- bar_1_min1725- foo_10_min",1735+ "./foo_0_now1736+ ./bar_1_min1737+ ./foo_10_min",1738 );1739 1740 te.assert_output(1741 &["", "--change-older-than", "15min"],1730- "bar_1_h1731- foo_2_h1732- bar_1_day",1742+ "./bar_1_h1743+ ./foo_2_h1744+ ./bar_1_day",1745 );1746 1747 te.assert_output(1748 &["foo", "--changed-within", "12h"],1737- "foo_0_now1738- foo_10_min1739- foo_2_h",1749+ "./foo_0_now1750+ ./foo_10_min1751+ ./foo_2_h",1752 );1753 }1754 1755 #[cfg(test)]11 unmodified lines1767 change_file_modified(te.test_root().join("30dec2017"), "2017-12-30T23:59:00Z");1768 1769 te.assert_output(1770 &["", "--change-newer-than", "2018-01-01 00:00:00"],1759- "15mar2018",1771+ "./15mar2018",1772 );1773 te.assert_output(1774 &["", "--changed-before", "2018-01-01 00:00:00"],1763- "30dec2017",1775+ "./30dec2017",1776 );1777 }1778 1779 #[test]15 unmodified lines1795 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);1796 1797 te.assert_output(1798 &["--base-directory", "one"],1787- "b.foo1788- two1789- two/c.foo1790- two/C.Foo21791- two/three1792- two/three/d.foo1793- two/three/directory_foo",1799+ "./b.foo1800+ ./two1801+ ./two/c.foo1802+ ./two/C.Foo21803+ ./two/three1804+ ./two/three/d.foo1805+ ./two/three/directory_foo",1806 );1807 1808 te.assert_output(1809 &["--base-directory", "one/two", "foo"],1798- "c.foo1799- C.Foo21800- three/d.foo1801- three/directory_foo",1810+ "./c.foo1811+ ./C.Foo21812+ ./three/d.foo1813+ ./three/directory_foo",1814 );1815 1816 // Explicit root path1817 te.assert_output(27 unmodified lines1845 1846 // Unrestricted1847 te.assert_output(1848 &["--max-results=0", "c.foo"],1837- "one/two/C.Foo21838- one/two/c.foo",1849+ "./one/two/C.Foo21850+ ./one/two/c.foo",1851 );1852 1853 // Limited to two results1854 te.assert_output(1855 &["--max-results=2", "c.foo"],1844- "one/two/C.Foo21845- one/two/c.foo",1856+ "./one/two/C.Foo21857+ ./one/two/c.foo",1858 );1859 1860 // Limited to one result. We could find either C.Foo2 or c.foo1861 let assert_just_one_result_with_option = |option| {1862 let output = te.assert_success_and_get_output(".", &[option, "c.foo"]);1863 let stdout = String::from_utf8_lossy(&output.stdout)1864 .trim()1865 .replace(&std::path::MAIN_SEPARATOR.to_string(), "/");1854- assert!(stdout == "one/two/C.Foo2" || stdout == "one/two/c.foo");1866+ assert!(stdout == "./one/two/C.Foo2" || stdout == "./one/two/c.foo");1867 };1868 assert_just_one_result_with_option("--max-results=1");1869 assert_just_one_result_with_option("-1");1870 }104 unmodified lines1975 1976 te.assert_failure(&["^\\.gitignore"]);1977 te.assert_failure(&["--glob", ".gitignore"]);1978 1967- te.assert_output(&["--hidden", "^\\.gitignore"], ".gitignore");1968- te.assert_output(&["--hidden", "--glob", ".gitignore"], ".gitignore");1979+ te.assert_output(&["--hidden", "^\\.gitignore"], "./.gitignore");1980+ te.assert_output(&["--hidden", "--glob", ".gitignore"], "./.gitignore");1981 te.assert_output(&[".gitignore"], "");1982 }1983+1984+#[test]1985+fn test_strip_cwd_prefix() {1986+ let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);1987+1988+ te.assert_output(1989+ &["--strip-cwd-prefix", "."],1990+ "a.foo1991+ e1 e21992+ one1993+ one/b.foo1994+ one/two1995+ one/two/c.foo1996+ one/two/C.Foo21997+ one/two/three1998+ one/two/three/d.foo1999+ one/two/three/directory_foo2000+ symlink",2001+ );2002+}modified:CHANGELOG.md+1 added
16 unmodified lines17 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)22 - Set default path separator to `/` in MSYS, see #537 and #730 (@aswild)23 - fd cannot search files under a RAM disk, see #75224 - fd doesn't show substituted drive on Windows, see #36525 - Properly handle write errors to devices that are full, see #737518 unmodified lines