diff --git a/CHANGELOG.md b/CHANGELOG.md index f8d8881..d247c4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add support for `--extensionsort` `-X` from [aldhsu](https://github.com/aldhsu) - Add support for `--versionsort` `-v` from [zwpaper](https://github.com/zwpaper) - Add support for config symlink arrow from [zwpaper](https://github.com/zwpaper) [#409](https://github.com/Peltoche/lsd/issues/409) +- Implement `--tree -d`, analogous to `tree -d` from [0jdxt](https://github.com/0jdxt) ### Changed - Use last sort flag for sort field from [meain](https://github.com/meain) ### Fixed diff --git a/src/app.rs b/src/app.rs index 8597c78..90ca9e2 100644 --- a/src/app.rs +++ b/src/app.rs @@ -116,7 +116,6 @@ pub fn build() -> App<'static, 'static> { .conflicts_with("almost-all") .conflicts_with("depth") .conflicts_with("recursive") - .conflicts_with("tree") .help("Display directories themselves, and not their contents"), ) .arg( diff --git a/src/flags/display.rs b/src/flags/display.rs index dd4ff05..143d488 100644 --- a/src/flags/display.rs +++ b/src/flags/display.rs @@ -15,6 +15,7 @@ pub enum Display { AlmostAll, DirectoryItself, DisplayOnlyVisible, + TreeD, } impl Display { @@ -45,7 +46,11 @@ impl Configurable for Display { } else if matches.is_present("almost-all") { Some(Self::AlmostAll) } else if matches.is_present("directory-only") { - Some(Self::DirectoryItself) + if matches.is_present("tree") { + Some(Self::TreeD) + } else { + Some(Self::DirectoryItself) + } } else { None } diff --git a/src/meta/mod.rs b/src/meta/mod.rs index f1569fb..16f6d69 100644 --- a/src/meta/mod.rs +++ b/src/meta/mod.rs @@ -116,6 +116,11 @@ impl Meta { } }; + // skip files for --tree -d + if flags.display == Display::TreeD && !entry_meta.file_type.is_dirlike() { + continue; + } + match entry_meta.recurse_into(depth - 1, &flags) { Ok(content) => entry_meta.content = content, Err(err) => { diff --git a/tests/integration.rs b/tests/integration.rs index 8dbf502..e78da82 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -397,6 +397,24 @@ fn test_bad_utf_8_name() { .stdout(predicate::str::is_match("bad-name\u{fffd}\u{fffd}.ext\n$").unwrap()); } +#[test] +fn test_tree_d() { + let tmp = tempdir(); + tmp.child("one").touch().unwrap(); + tmp.child("two").touch().unwrap(); + tmp.child("one.d").create_dir_all().unwrap(); + tmp.child("one.d/one").touch().unwrap(); + tmp.child("one.d/one.d").create_dir_all().unwrap(); + tmp.child("two.d").create_dir_all().unwrap(); + + cmd() + .arg(tmp.path()) + .arg("--tree") + .arg("-d") + .assert() + .stdout(predicate::str::is_match("├── one.d\n│ └── one.d\n└── two.d\n$").unwrap()); +} + fn cmd() -> Command { Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap() }