Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ trash-move = ["trash"]

[dependencies]
clap = { version = "4.0.29", features = ["derive"] }
clap_complete = "4.5.54"
jwalk = "0.8.1"
byte-unit = "4"
atty = "0.2.11"
Expand Down
14 changes: 8 additions & 6 deletions src/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,14 @@ fn output_colored_path(
let size_width = byte_format.width();
let path = path.as_ref().display();

let errors = (num_errors != 0)
.then(|| {
let plural_s = if num_errors > 1 { "s" } else { "" };
format!(" <{num_errors} IO Error{plural_s}>")
})
.unwrap_or_default();
let errors = if num_errors != 0 {
format!(
" <{num_errors} IO Error{plural_s}>",
plural_s = if num_errors > 1 { "s" } else { "" }
)
} else {
"".into()
};

if let Some(color) = path_color {
writeln!(out, "{size:>size_width$} {}{errors}", path.color(color))
Expand Down
3 changes: 1 addition & 2 deletions src/interactive/widgets/mark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,7 @@ impl MarkPane {

pub fn calculate_size_and_count(marked: &EntryMarkMap) -> (u128, u64) {
let entries: Vec<&EntryMark> = marked
.iter()
.map(|(_k, v)| v)
.values()
.sorted_by(|a, b| Ord::cmp(&a.path, &b.path))
.collect();

Expand Down
8 changes: 7 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![forbid(rust_2018_idioms, unsafe_code)]
use anyhow::Result;
use clap::Parser;
use clap::{CommandFactory as _, Parser};
use dua::{canonicalize_ignore_dirs, TraversalSorting};
use log::info;
use simplelog::{Config, LevelFilter, WriteLogger};
Expand Down Expand Up @@ -141,6 +141,12 @@ fn main() -> Result<()> {
}
res
}
Some(Completions { shell }) => {
let mut cmd = options::Args::command();
let dua = cmd.get_name().to_string();
clap_complete::generate(shell, &mut cmd, dua, &mut io::stdout());
return Ok(());
}
None => {
let stdout = io::stdout();
let stdout_locked = stdout.lock();
Expand Down
6 changes: 6 additions & 0 deletions src/options.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use clap_complete::Shell;
use dua::ByteFormat as LibraryByteFormat;
use std::path::PathBuf;

Expand Down Expand Up @@ -123,4 +124,9 @@ pub enum Command {
#[clap(value_parser)]
input: Vec<PathBuf>,
},
/// Generate shell completions
Completions {
/// The shell to generate a completions-script for
shell: Shell,
},
}
Loading