diff --git a/CHANGELOG.md b/CHANGELOG.md index d48c317..d77d85d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ - Add new `--no-ignore-parent` flag, see #787 (@will459) +- Add new `-N, --no-strip` flag, see #760 (@jcaplan) + ## Bugfixes - Set default path separator to `/` in MSYS, see #537 and #730 (@aswild) diff --git a/src/app.rs b/src/app.rs index b26593b..f8556b6 100644 --- a/src/app.rs +++ b/src/app.rs @@ -615,6 +615,17 @@ pub fn build_app() -> App<'static, 'static> { argument. Changes the usage to `fd [FLAGS/OPTIONS] --search-path \ --search-path []`", ), + ) + .arg( + Arg::with_name("no-strip") + .long("no-strip") + .short("N") + .conflicts_with_all(&["absolute-path", "list-details"]) + .help("Show all non-absolute paths with './' prefix") + .long_help( + "Show all non-absolute paths with './' prefix. This flag only affects \ + the output when no search path is provided.") + ); if cfg!(unix) { diff --git a/src/config.rs b/src/config.rs index a053e6e..9719f72 100644 --- a/src/config.rs +++ b/src/config.rs @@ -109,4 +109,7 @@ pub struct Config { /// The maximum number of search results pub max_results: Option, + + /// Whether to prefix each relative path with "./" + pub no_strip: bool, } diff --git a/src/main.rs b/src/main.rs index da5fcd9..a23bc90 100644 --- a/src/main.rs +++ b/src/main.rs @@ -375,6 +375,7 @@ fn construct_config(matches: clap::ArgMatches, pattern_regex: &str) -> Result, ) { - let path = if entry.is_absolute() { + let path = if entry.is_absolute() || config.no_strip { entry } else { strip_current_dir(entry) diff --git a/tests/tests.rs b/tests/tests.rs index a7c04f4..b7f8414 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -1901,3 +1901,40 @@ fn test_error_if_hidden_not_set_and_pattern_starts_with_dot() { te.assert_output(&["--hidden", "--glob", ".gitignore"], ".gitignore"); te.assert_output(&[".gitignore"], ""); } + +/// Show "./" prefix if the --no-strip flag is provided +#[test] +fn test_no_strip() { + let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES); + te.assert_output( + &["--no-strip"], + "./a.foo + ./e1 e2 + ./one + ./one/b.foo + ./one/two + ./one/two/c.foo + ./one/two/C.Foo2 + ./one/two/three + ./one/two/three/d.foo + ./one/two/three/directory_foo + ./symlink" + ); + + te.assert_output( + &["--no-strip", "foo", "./one"], + "./one/b.foo + ./one/two/c.foo + ./one/two/C.Foo2 + ./one/two/three/d.foo + ./one/two/three/directory_foo" + ); + te.assert_output( + &["--no-strip", "foo", "one"], + "one/b.foo + one/two/c.foo + one/two/C.Foo2 + one/two/three/d.foo + one/two/three/directory_foo" + ); +}