Compare commits

..

1 Commits

Author SHA1 Message Date
andy.boot
8be6b2d9cd chore: Retire directories library
Only used in one place (less dependencies = good).
Also directories has been retired as a github project. Easier to replace
with std::env::home() which has all the functionality we need
2025-11-20 23:00:17 +00:00
16 changed files with 324 additions and 335 deletions

View File

@@ -126,11 +126,6 @@ jobs:
target: x86_64-unknown-linux-musl,
use-cross: use-cross,
}
- {
os: deb-latest,
target: x86_64-unknown-linux-musl,
use-cross: use-cross,
}
- { os: macos-latest, target: x86_64-apple-darwin }
- { os: windows-latest, target: i686-pc-windows-gnu }
- { os: windows-latest, target: i686-pc-windows-msvc }

548
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -27,11 +27,11 @@ lto = true
strip = true
[dependencies]
clap = { version = "4", features = ["derive"] }
lscolors = "0.21"
nu-ansi-term = "0.50"
terminal_size = "0.4"
unicode-width = "0.2"
ansi_term = "0.12"
clap = { version = "4.4", features = ["derive"] }
lscolors = "0.13"
terminal_size = "0.2"
unicode-width = "0.1"
rayon = "1"
thousands = "0.2"
stfu8 = "0.2"
@@ -39,8 +39,8 @@ regex = "1"
config-file = "0.2"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
sysinfo = "0.37"
ctrlc = "3"
sysinfo = "0.27"
ctrlc = "3.4"
chrono = "0.4"
[target.'cfg(not(target_has_atomic = "64"))'.dependencies]

View File

@@ -13,17 +13,6 @@ Because I want an easy way to see where my disk is being used.
![Example](media/snap.png)
Study the above picture.
* We see `target` has 1.8G
* `target/debug` is the same size as `target` - so we know nearly all the disk usage of the 1.5G is in this folder
* `target/debug/deps` this is 1.2G - Note the bar jumps down to 70% to indicate that most disk usage is here but not all.
* `target/debug/deps/dust-e78c9f87a17f24f3` - This is the largest file in this folder, but it is only 46M - Note the bar jumps down to 3% to indicate the file is small.
From here we can conclude:
* `target/debug/deps` takes the majority of the space in `target` and that `target/debug/deps` has a large number of relatively small files.
## Install
#### Cargo <a href="https://repology.org/project/du-dust/versions"><img src="https://repology.org/badge/vertical-allrepos/du-dust.svg" alt="Packaging status" align="right"></a>
@@ -80,8 +69,6 @@ Dust will list a slightly-less-than-the-terminal-height number of the biggest su
The different colors on the bars: These represent the combined tree hierarchy & disk usage. The shades of grey are used to indicate which parent folder a subfolder belongs to. For instance, look at the above screenshot. `.steam` is a folder taking 44% of the space. From the `.steam` bar is a light grey line that goes up. All these folders are inside `.steam` so if you delete `.steam` all that stuff will be gone too.
If you are new to the tool I recommend to try tweaking the `-n` parameter. `dust -n 10`, `dust -n 50`.
## Usage
```
@@ -138,14 +125,4 @@ reverse=true
- [dirstat-rs](https://github.com/scullionw/dirstat-rs)
- `du -d 1 -h | sort -h`
## Why to use Dust over the Alternatives
Dust simply Does The Right Thing when handling lots of small files & directories. Dust keeps the output simple by only showing large entries.
Tools like ncdu & baobab, give you a view of directory sizes but you have no idea where the largest files are. For example directory A could have a size larger than directory B, but in fact the largest file is in B and not A. Finding this out via these other tools is not trivial whereas Dust will show the large file clearly in the tree hierarchy
Dust will not count hard links multiple times (unless you want to `-s`).
Typing `dust -n 90` will show you your 90 largest entries. `-n` is not quite like `head -n` or `tail -n`, dust is intelligent and chooses the largest entries
Note: Apparent-size is calculated slightly differently in dust to gdu. In dust each hard link is counted as using file_length space. In gdu only the first entry is counted.

View File

@@ -20,8 +20,8 @@ _dust() {
'-T+[Number of threads to use]:THREADS:_default' \
'--threads=[Number of threads to use]:THREADS:_default' \
'--config=[Specify a config file to use]:FILE:_files' \
'-n+[Display the '\''n'\'' largest entries. (Default is terminal_height)]:NUMBER:_default' \
'--number-of-lines=[Display the '\''n'\'' largest entries. (Default is terminal_height)]:NUMBER:_default' \
'-n+[Number of lines of output to show. (Default is terminal_height - 10)]:NUMBER:_default' \
'--number-of-lines=[Number of lines of output to show. (Default is terminal_height - 10)]:NUMBER:_default' \
'*-X+[Exclude any file or directory with this path]:PATH:_files' \
'*--ignore-directory=[Exclude any file or directory with this path]:PATH:_files' \
'-I+[Exclude any file or directory with a regex matching that listed in this file, the file entries will be added to the ignore regexs provided by --invert_filter]:FILE:_files' \

View File

@@ -26,8 +26,8 @@ Register-ArgumentCompleter -Native -CommandName 'dust' -ScriptBlock {
[CompletionResult]::new('-T', '-T ', [CompletionResultType]::ParameterName, 'Number of threads to use')
[CompletionResult]::new('--threads', '--threads', [CompletionResultType]::ParameterName, 'Number of threads to use')
[CompletionResult]::new('--config', '--config', [CompletionResultType]::ParameterName, 'Specify a config file to use')
[CompletionResult]::new('-n', '-n', [CompletionResultType]::ParameterName, 'Display the ''n'' largest entries. (Default is terminal_height)')
[CompletionResult]::new('--number-of-lines', '--number-of-lines', [CompletionResultType]::ParameterName, 'Display the ''n'' largest entries. (Default is terminal_height)')
[CompletionResult]::new('-n', '-n', [CompletionResultType]::ParameterName, 'Number of lines of output to show. (Default is terminal_height - 10)')
[CompletionResult]::new('--number-of-lines', '--number-of-lines', [CompletionResultType]::ParameterName, 'Number of lines of output to show. (Default is terminal_height - 10)')
[CompletionResult]::new('-X', '-X ', [CompletionResultType]::ParameterName, 'Exclude any file or directory with this path')
[CompletionResult]::new('--ignore-directory', '--ignore-directory', [CompletionResultType]::ParameterName, 'Exclude any file or directory with this path')
[CompletionResult]::new('-I', '-I ', [CompletionResultType]::ParameterName, 'Exclude any file or directory with a regex matching that listed in this file, the file entries will be added to the ignore regexs provided by --invert_filter')

View File

@@ -23,8 +23,8 @@ set edit:completion:arg-completer[dust] = {|@words|
cand -T 'Number of threads to use'
cand --threads 'Number of threads to use'
cand --config 'Specify a config file to use'
cand -n 'Display the ''n'' largest entries. (Default is terminal_height)'
cand --number-of-lines 'Display the ''n'' largest entries. (Default is terminal_height)'
cand -n 'Number of lines of output to show. (Default is terminal_height - 10)'
cand --number-of-lines 'Number of lines of output to show. (Default is terminal_height - 10)'
cand -X 'Exclude any file or directory with this path'
cand --ignore-directory 'Exclude any file or directory with this path'
cand -I 'Exclude any file or directory with a regex matching that listed in this file, the file entries will be added to the ignore regexs provided by --invert_filter'

View File

@@ -1,7 +1,7 @@
complete -c dust -s d -l depth -d 'Depth to show' -r
complete -c dust -s T -l threads -d 'Number of threads to use' -r
complete -c dust -l config -d 'Specify a config file to use' -r -F
complete -c dust -s n -l number-of-lines -d 'Display the \'n\' largest entries. (Default is terminal_height)' -r
complete -c dust -s n -l number-of-lines -d 'Number of lines of output to show. (Default is terminal_height - 10)' -r
complete -c dust -s X -l ignore-directory -d 'Exclude any file or directory with this path' -r -F
complete -c dust -s I -l ignore-all-in-file -d 'Exclude any file or directory with a regex matching that listed in this file, the file entries will be added to the ignore regexs provided by --invert_filter' -r -F
complete -c dust -s z -l min-size -d 'Minimum size file to include in output' -r

View File

@@ -19,7 +19,7 @@ Number of threads to use
Specify a config file to use
.TP
\fB\-n\fR, \fB\-\-number\-of\-lines\fR \fI<NUMBER>\fR
Display the \*(Aqn\*(Aq largest entries. (Default is terminal_height)
Number of lines of output to show. (Default is terminal_height \- 10)
.TP
\fB\-p\fR, \fB\-\-full\-paths\fR
Subdirectories will not have their path shortened

Binary file not shown.

Before

Width:  |  Height:  |  Size: 107 KiB

After

Width:  |  Height:  |  Size: 61 KiB

View File

@@ -21,7 +21,7 @@ pub struct Cli {
#[arg(long, value_name("FILE"), value_hint(ValueHint::FilePath))]
pub config: Option<String>,
/// Display the 'n' largest entries. (Default is terminal_height)
/// Number of lines of output to show. (Default is terminal_height - 10)
#[arg(short, long, value_name("NUMBER"))]
pub number_of_lines: Option<usize>,

View File

@@ -1,8 +1,8 @@
use crate::display_node::DisplayNode;
use crate::node::FileTime;
use ansi_term::Colour::Red;
use lscolors::{LsColors, Style};
use nu_ansi_term::Color::Red;
use unicode_width::UnicodeWidthStr;
@@ -403,7 +403,7 @@ fn get_pretty_name(
.ls_colors
.style_for_path_with_metadata(&node.name, meta_result.as_ref().ok());
let ansi_style = directory_color
.map(Style::to_nu_ansi_term_style)
.map(Style::to_ansi_term_style)
.unwrap_or_default();
let out = ansi_style.paint(name_and_padding);
format!("{out}")

View File

@@ -29,7 +29,7 @@ use std::panic;
use std::process;
use std::sync::Arc;
use std::sync::Mutex;
use sysinfo::System;
use sysinfo::{System, SystemExt};
use utils::canonicalize_absolute_path;
use self::display::draw_it;
@@ -440,10 +440,10 @@ fn init_rayon(stack: &Option<usize>, threads: &Option<usize>) -> rayon::ThreadPo
None
} else {
let large_stack = usize::pow(1024, 3);
let mut sys = System::new_all();
sys.refresh_memory();
let mut s = System::new();
s.refresh_memory();
// Larger stack size if possible to handle cases with lots of nested directories
let available = sys.available_memory();
let available = s.available_memory();
if available > (large_stack * threads.unwrap_or(1)).try_into().unwrap() {
Some(large_stack)
} else {

View File

@@ -1,4 +1,4 @@
use assert_cmd::{Command, cargo_bin_cmd};
use assert_cmd::Command;
use std::ffi::OsStr;
use std::process::Output;
use std::sync::Once;
@@ -61,11 +61,9 @@ fn initialize() {
fn run_cmd<T: AsRef<OsStr>>(command_args: &[T]) -> Output {
initialize();
let mut to_run = cargo_bin_cmd!("dust");
// Hide progress bar
to_run.arg("-P");
let mut to_run = &mut Command::cargo_bin("dust").unwrap();
for p in command_args {
to_run.arg(p);
to_run = to_run.arg(p);
}
to_run.unwrap()
}

View File

@@ -1,4 +1,4 @@
use assert_cmd::cargo_bin_cmd;
use assert_cmd::Command;
use std::ffi::OsStr;
use std::str;
@@ -9,16 +9,17 @@ use std::str;
*/
fn build_command<T: AsRef<OsStr>>(command_args: Vec<T>) -> String {
let mut cmd = cargo_bin_cmd!("dust");
let mut cmd = &mut Command::cargo_bin("dust").unwrap();
// Hide progress bar
cmd.arg("-P");
cmd = cmd.arg("-P");
for p in command_args {
cmd.arg(p);
cmd = cmd.arg(p);
}
let finished = &cmd.unwrap();
assert_eq!(str::from_utf8(&finished.stderr).unwrap(), "");
let stderr = str::from_utf8(&finished.stderr).unwrap();
assert_eq!(stderr, "");
str::from_utf8(&finished.stdout).unwrap().into()
}
@@ -125,7 +126,7 @@ pub fn test_files0_from_flag_file() {
#[test]
pub fn test_files_from_flag_stdin() {
let mut cmd = cargo_bin_cmd!("dust");
let mut cmd = Command::cargo_bin("dust").unwrap();
cmd.arg("-P").arg("--files-from").arg("-");
let input = b"tests/test_dir_files_from/a_file\ntests/test_dir_files_from/hello_file\n";
cmd.write_stdin(input.as_ref());
@@ -139,7 +140,7 @@ pub fn test_files_from_flag_stdin() {
#[test]
pub fn test_files0_from_flag_stdin() {
let mut cmd = cargo_bin_cmd!("dust");
let mut cmd = Command::cargo_bin("dust").unwrap();
cmd.arg("-P").arg("--files0-from").arg("-");
let input = b"tests/test_dir_files_from/a_file\0tests/test_dir_files_from/hello_file\0";
cmd.write_stdin(input.as_ref());
@@ -153,7 +154,7 @@ pub fn test_files0_from_flag_stdin() {
#[test]
pub fn test_with_bad_param() {
let mut cmd = cargo_bin_cmd!("dust");
let mut cmd = Command::cargo_bin("dust").unwrap();
cmd.arg("-P").arg("bad_place");
let output_error = cmd.unwrap_err();
let result = output_error.as_output().unwrap();

View File

@@ -1,4 +1,4 @@
use assert_cmd::{Command, cargo_bin_cmd};
use assert_cmd::Command;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;
@@ -44,7 +44,7 @@ pub fn test_soft_sym_link() {
let b = format!(" ┌── {}", file_path_s);
let a = format!("─┴ {}", dir_s);
let mut cmd = cargo_bin_cmd!("dust");
let mut cmd = Command::cargo_bin("dust").unwrap();
// Mac test runners create long filenames in tmp directories
let output = cmd
.args(["-p", "-c", "-s", "-w", "999", dir_s])
@@ -72,7 +72,7 @@ pub fn test_hard_sym_link() {
let file_output = format!(" ┌── {}", file_path_s);
let dirs_output = format!("─┴ {}", dir_s);
let mut cmd = cargo_bin_cmd!("dust");
let mut cmd = Command::cargo_bin("dust").unwrap();
// Mac test runners create long filenames in tmp directories
let output = cmd.args(["-p", "-c", "-w", "999", dir_s]).unwrap().stdout;
@@ -96,7 +96,7 @@ pub fn test_hard_sym_link_no_dup_multi_arg() {
let link_name = dir_link.path().join("the_link");
let link_name_s = link_it(link_name, file_path_s, false);
let mut cmd = cargo_bin_cmd!("dust");
let mut cmd = Command::cargo_bin("dust").unwrap();
// Mac test runners create long filenames in tmp directories
let output = cmd
@@ -123,7 +123,7 @@ pub fn test_recursive_sym_link() {
let a = format!("─┬ {}", dir_s);
let b = format!(" └── {}", link_name_s);
let mut cmd = cargo_bin_cmd!("dust");
let mut cmd = Command::cargo_bin("dust").unwrap();
let output = cmd
.arg("-p")
.arg("-c")