diff options
author | DIRE <hsnks100@gmail.com> | 2022-09-30 11:32:46 +0900 |
---|---|---|
committer | andy.boot <bootandy@gmail.com> | 2022-10-05 23:26:10 +0100 |
commit | 2ca717744649587f1fe86bd49bd28892979ae70e (patch) | |
tree | 2f42f735703560f518ee577b5328ae52ad5dad48 | |
parent | e858f9e97608c8c368a80c778a463838e39a55a9 (diff) |
FEATURE: support only directories will be displayed. Flag -D
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | completions/_dust | 2 | ||||
-rw-r--r-- | completions/_dust.ps1 | 2 | ||||
-rw-r--r-- | completions/dust.bash | 2 | ||||
-rw-r--r-- | completions/dust.elv | 2 | ||||
-rw-r--r-- | completions/dust.fish | 1 | ||||
-rw-r--r-- | src/cli.rs | 6 | ||||
-rw-r--r-- | src/config.rs | 4 | ||||
-rw-r--r-- | src/filter.rs | 20 | ||||
-rw-r--r-- | src/main.rs | 1 |
10 files changed, 34 insertions, 7 deletions
@@ -59,6 +59,7 @@ Usage: dust -p (full-path - Show fullpath of the subdirectories) Usage: dust -s (apparent-size - shows the length of the file as opposed to the amount of disk space it uses) Usage: dust -n 30 (Shows 30 directories instead of the default [default is terminal height]) Usage: dust -d 3 (Shows 3 levels of subdirectories) +Usage: dust -D (Show only directories (eg dust -D)) Usage: dust -r (reverse order of output) Usage: dust -H (si print sizes in powers of 1000 instead of 1024) Usage: dust -X ignore (ignore all files and directories with the name 'ignore') diff --git a/completions/_dust b/completions/_dust index 2391d2d..f9cf659 100644 --- a/completions/_dust +++ b/completions/_dust @@ -54,6 +54,8 @@ _dust() { '(-d --depth)--file_types[show only these file types]' \ '-H[print sizes in powers of 1000 (e.g., 1.1G)]' \ '--si[print sizes in powers of 1000 (e.g., 1.1G)]' \ +'-D[Only directories will be displayed.]' \ +'--only-dir[Only directories will be displayed.]' \ '*::inputs:' \ && ret=0 } diff --git a/completions/_dust.ps1 b/completions/_dust.ps1 index 18e3037..33c7fb2 100644 --- a/completions/_dust.ps1 +++ b/completions/_dust.ps1 @@ -60,6 +60,8 @@ Register-ArgumentCompleter -Native -CommandName 'dust' -ScriptBlock { [CompletionResult]::new('--file_types', 'file_types', [CompletionResultType]::ParameterName, 'show only these file types') [CompletionResult]::new('-H', 'H', [CompletionResultType]::ParameterName, 'print sizes in powers of 1000 (e.g., 1.1G)') [CompletionResult]::new('--si', 'si', [CompletionResultType]::ParameterName, 'print sizes in powers of 1000 (e.g., 1.1G)') + [CompletionResult]::new('-D', 'D', [CompletionResultType]::ParameterName, 'Only directories will be displayed.') + [CompletionResult]::new('--only-dir', 'only-dir', [CompletionResultType]::ParameterName, 'Only directories will be displayed.') break } }) diff --git a/completions/dust.bash b/completions/dust.bash index f261db5..92d0a87 100644 --- a/completions/dust.bash +++ b/completions/dust.bash @@ -19,7 +19,7 @@ _dust() { case "${cmd}" in dust) - opts="-h -V -d -n -p -X -x -s -r -c -b -z -f -i -v -e -t -w -H --help --version --depth --number-of-lines --full-paths --ignore-directory --limit-filesystem --apparent-size --reverse --no-colors --no-percent-bars --min-size --skip-total --filecount --ignore_hidden --invert-filter --filter --file_types --terminal_width --si <inputs>..." + opts="-h -V -d -n -p -X -x -s -r -c -b -z -f -i -v -e -t -w -H -D --help --version --depth --number-of-lines --full-paths --ignore-directory --limit-filesystem --apparent-size --reverse --no-colors --no-percent-bars --min-size --skip-total --filecount --ignore_hidden --invert-filter --filter --file_types --terminal_width --si --only-dir <inputs>..." if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 diff --git a/completions/dust.elv b/completions/dust.elv index e0ddc2a..a5429b1 100644 --- a/completions/dust.elv +++ b/completions/dust.elv @@ -57,6 +57,8 @@ set edit:completion:arg-completer[dust] = {|@words| cand --file_types 'show only these file types' cand -H 'print sizes in powers of 1000 (e.g., 1.1G)' cand --si 'print sizes in powers of 1000 (e.g., 1.1G)' + cand -D 'Only directories will be displayed.' + cand --only-dir 'Only directories will be displayed.' } ] $completions[$command] diff --git a/completions/dust.fish b/completions/dust.fish index 1c2ccb3..457e539 100644 --- a/completions/dust.fish +++ b/completions/dust.fish @@ -18,3 +18,4 @@ complete -c dust -s f -l filecount -d 'Directory \'size\' is number of child fil complete -c dust -s i -l ignore_hidden -d 'Do not display hidden files' complete -c dust -s t -l file_types -d 'show only these file types' complete -c dust -s H -l si -d 'print sizes in powers of 1000 (e.g., 1.1G)' +complete -c dust -s D -l only-dir -d 'Only directories will be displayed.' @@ -132,4 +132,10 @@ pub fn build_cli() -> Command<'static> { .help("print sizes in powers of 1000 (e.g., 1.1G)") ) .arg(Arg::new("inputs").multiple_occurrences(true)) + .arg( + Arg::new("only_dir") + .short('D') + .long("only-dir") + .help("Only directories will be displayed."), + ) } diff --git a/src/config.rs b/src/config.rs index 80c2216..6b54a7f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -19,6 +19,7 @@ pub struct Config { pub ignore_hidden: Option<bool>, pub iso: Option<bool>, pub min_size: Option<String>, + pub only_dir: Option<bool>, } impl Config { @@ -61,6 +62,9 @@ impl Config { size_from_param } } + pub fn get_only_dir(&self, options: &ArgMatches) -> bool { + Some(true) == self.only_dir || options.is_present("only_dir") + } } fn convert_min_size(input: &str, iso: bool) -> Option<usize> { diff --git a/src/filter.rs b/src/filter.rs index 8f1d7b3..1eadbf2 100644 --- a/src/filter.rs +++ b/src/filter.rs @@ -8,6 +8,7 @@ use std::path::PathBuf; pub fn get_biggest( top_level_nodes: Vec<Node>, min_size: Option<usize>, + only_dir: bool, n: usize, depth: usize, using_a_filter: bool, @@ -23,14 +24,14 @@ pub fn get_biggest( let mut allowed_nodes = HashSet::new(); allowed_nodes.insert(root.name.as_path()); - heap = add_children(using_a_filter, min_size, &root, depth, heap); + heap = add_children(using_a_filter, min_size, only_dir, &root, depth, heap); for _ in number_top_level_nodes..n { let line = heap.pop(); match line { Some(line) => { allowed_nodes.insert(line.name.as_path()); - heap = add_children(using_a_filter, min_size, line, depth, heap); + heap = add_children(using_a_filter, min_size, only_dir, line, depth, heap); } None => break, } @@ -41,15 +42,22 @@ pub fn get_biggest( fn add_children<'a>( using_a_filter: bool, min_size: Option<usize>, + only_dir: bool, file_or_folder: &'a Node, depth: usize, mut heap: BinaryHeap<&'a Node>, ) -> BinaryHeap<&'a Node> { if depth > file_or_folder.depth { - heap.extend(file_or_folder.children.iter().filter(|c| match min_size { - Some(ms) => c.size > ms as u64, - None => !using_a_filter || c.name.is_file() || c.size > 0, - })) + heap.extend( + file_or_folder + .children + .iter() + .filter(|c| match min_size { + Some(ms) => c.size > ms as u64, + None => !using_a_filter || c.name.is_file() || c.size > 0, + }) + .filter(|c| if only_dir { c.name.is_dir() } else { true }), + ) } heap } diff --git a/src/main.rs b/src/main.rs index 8381524..78a2a06 100644 --- a/src/main.rs +++ b/src/main.rs @@ -181,6 +181,7 @@ fn main() { false => get_biggest( top_level_nodes, config.get_min_size(&options, iso), + config.get_only_dir(&options), number_of_lines, depth, options.values_of("filter").is_some() || options.value_of("invert_filter").is_some(), |