Skip to content

Commit

Permalink
feat: With a single path provided as root, pretend it's the current w…
Browse files Browse the repository at this point in the history
…orking dir (#110)

This makes it seem like the user started the directory walk directly in the given directory,
which is more intuitive than the previous approach only showed the given directory as
top-level directory.

Note that this change only affects invocations like `dua <dir>` or `dua i <dir>`.
  • Loading branch information
Byron committed Dec 6, 2023
2 parents 72fd6d1 + 74e6d42 commit de4c2b3
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fn main() -> Result<()> {
let res = TerminalApp::initialize(
&mut terminal,
walk_options,
paths_from(input, !opt.stay_on_filesystem)?,
extract_paths_maybe_set_cwd(input, !opt.stay_on_filesystem)?,
Interaction::Full,
)?
.map(|(keys_rx, mut app)| {
Expand Down Expand Up @@ -101,7 +101,7 @@ fn main() -> Result<()> {
walk_options,
!no_total,
!no_sort,
paths_from(input, !opt.stay_on_filesystem)?,
extract_paths_maybe_set_cwd(input, !opt.stay_on_filesystem)?,
)?;
if statistics {
writeln!(io::stderr(), "{:?}", stats).ok();
Expand All @@ -117,7 +117,7 @@ fn main() -> Result<()> {
walk_options,
true,
true,
paths_from(opt.input, !opt.stay_on_filesystem)?,
extract_paths_maybe_set_cwd(opt.input, !opt.stay_on_filesystem)?,
)?
.0
}
Expand All @@ -126,7 +126,14 @@ fn main() -> Result<()> {
process::exit(res.to_exit_code());
}

fn paths_from(paths: Vec<PathBuf>, cross_filesystems: bool) -> Result<Vec<PathBuf>, io::Error> {
fn extract_paths_maybe_set_cwd(
mut paths: Vec<PathBuf>,
cross_filesystems: bool,
) -> Result<Vec<PathBuf>, io::Error> {
if paths.len() == 1 {
std::env::set_current_dir(&paths[0])?;
paths.clear();
}
let device_id = std::env::current_dir()
.ok()
.and_then(|cwd| crossdev::init(&cwd).ok());
Expand Down

0 comments on commit de4c2b3

Please sign in to comment.