mirror of
https://github.com/bootandy/dust.git
synced 2025-12-06 04:41:09 -08:00
Compare commits
91 Commits
fix_error_
...
v1.0.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
082f15a0e2 | ||
|
|
25c016f98a | ||
|
|
69c4c63357 | ||
|
|
fbd34ec4c2 | ||
|
|
7c75c1b0a9 | ||
|
|
b54a215805 | ||
|
|
0364cf781e | ||
|
|
a8bf76cb22 | ||
|
|
4df4eeaa38 | ||
|
|
ebb3b8cceb | ||
|
|
e9bacdf875 | ||
|
|
a4b5d8573b | ||
|
|
4a2778b6ea | ||
|
|
7ee744207b | ||
|
|
96068518f6 | ||
|
|
10168e0a47 | ||
|
|
6768df9a7b | ||
|
|
e80892a9e7 | ||
|
|
cd53fc7494 | ||
|
|
e8c7990a17 | ||
|
|
c8b61d2f46 | ||
|
|
6e0505bfd7 | ||
|
|
24bdbf036e | ||
|
|
29085686e1 | ||
|
|
8b1632dde8 | ||
|
|
f3275cd59c | ||
|
|
939ed89ebb | ||
|
|
a58e5f48f6 | ||
|
|
3f9014d8c7 | ||
|
|
7c54d41ace | ||
|
|
2fa14ca19c | ||
|
|
211d89e634 | ||
|
|
0038cb24b4 | ||
|
|
658f8d2e2b | ||
|
|
2c23336794 | ||
|
|
a4ae013459 | ||
|
|
c259d3b566 | ||
|
|
bdfd3c01a5 | ||
|
|
2fe91806c7 | ||
|
|
514bb2799c | ||
|
|
e17a1af476 | ||
|
|
2f7c197cd7 | ||
|
|
7d13fe972c | ||
|
|
5a3e15d0ce | ||
|
|
6db013a601 | ||
|
|
49a21b1121 | ||
|
|
7efdf63fbc | ||
|
|
184d1ec5e8 | ||
|
|
1e87a0661b | ||
|
|
187b8be2fa | ||
|
|
1495251ebc | ||
|
|
520c439edc | ||
|
|
712acc67fe | ||
|
|
fdbed14334 | ||
|
|
810cc8b604 | ||
|
|
83ef2525aa | ||
|
|
af9f0b5125 | ||
|
|
9ff28b3456 | ||
|
|
4242363f40 | ||
|
|
3fd78490e6 | ||
|
|
b903f58cea | ||
|
|
0f72ca328a | ||
|
|
6c130adb6c | ||
|
|
9f0f366187 | ||
|
|
81ad921e25 | ||
|
|
3708edc2d3 | ||
|
|
414bc9e5a7 | ||
|
|
66ad504848 | ||
|
|
5bfa44ec77 | ||
|
|
03a8d643c5 | ||
|
|
29957c1f2c | ||
|
|
400ff513f4 | ||
|
|
31eb650fbe | ||
|
|
f3c074759d | ||
|
|
ea3cc537ea | ||
|
|
c012567c38 | ||
|
|
26bc26277d | ||
|
|
abcc46c5ea | ||
|
|
a3ab5bfe0f | ||
|
|
04c4963a02 | ||
|
|
40a6f098ae | ||
|
|
5e607cf210 | ||
|
|
f546dbbede | ||
|
|
a91aa62060 | ||
|
|
a7b82f32d7 | ||
|
|
72b811c278 | ||
|
|
b478534b22 | ||
|
|
2ca7177446 | ||
|
|
e858f9e976 | ||
|
|
0a67191054 | ||
|
|
c363e5ff8b |
9
.github/workflows/CICD.yml
vendored
9
.github/workflows/CICD.yml
vendored
@@ -96,6 +96,11 @@ jobs:
|
||||
target: arm-unknown-linux-gnueabihf,
|
||||
use-cross: use-cross,
|
||||
}
|
||||
- {
|
||||
os: ubuntu-latest,
|
||||
target: arm-unknown-linux-musleabi,
|
||||
use-cross: use-cross,
|
||||
}
|
||||
- {
|
||||
os: ubuntu-latest,
|
||||
target: i686-unknown-linux-gnu,
|
||||
@@ -205,7 +210,9 @@ jobs:
|
||||
echo set-output name=CARGO_TEST_OPTIONS::${CARGO_TEST_OPTIONS}
|
||||
echo ::set-output name=CARGO_TEST_OPTIONS::${CARGO_TEST_OPTIONS}
|
||||
# * strip executable?
|
||||
STRIP="strip" ; case ${{ matrix.job.target }} in arm-unknown-linux-gnueabihf) STRIP="arm-linux-gnueabihf-strip" ;; *-pc-windows-msvc) STRIP="" ;; aarch64-unknown-linux-gnu) STRIP="aarch64-linux-gnu-strip" ;; aarch64-unknown-linux-musl) STRIP="" ;;esac;
|
||||
STRIP="strip" ; case ${{ matrix.job.target }} in arm-unknown-linux-gnueabihf) STRIP="arm-linux-gnueabihf-strip" ;; *-pc-windows-msvc) STRIP="" ;; aarch64-unknown-linux-gnu) STRIP="aarch64-linux-gnu-strip" ;; aarch64-unknown-linux-musl) STRIP="" ;; armv7-unknown-linux-musleabi) STRIP="" ;; arm-unknown-linux-musleabi) STRIP="" ;; esac;
|
||||
|
||||
|
||||
echo set-output name=STRIP::${STRIP}
|
||||
echo ::set-output name=STRIP::${STRIP}
|
||||
- name: Create all needed build/work directories
|
||||
|
||||
5
.gitignore
vendored
5
.gitignore
vendored
@@ -6,4 +6,7 @@
|
||||
**/*.rs.bk
|
||||
*.swp
|
||||
.vscode/*
|
||||
*.idea/*
|
||||
*.idea/*
|
||||
|
||||
#ignore macos files
|
||||
.DS_Store
|
||||
685
Cargo.lock
generated
685
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
22
Cargo.toml
22
Cargo.toml
@@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "du-dust"
|
||||
description = "A more intuitive version of du"
|
||||
version = "0.8.2"
|
||||
version = "1.0.0"
|
||||
authors = ["bootandy <bootandy@gmail.com>", "nebkor <code@ardent.nebcorp.com>"]
|
||||
edition = "2021"
|
||||
readme = "README.md"
|
||||
@@ -28,9 +28,9 @@ strip = true
|
||||
|
||||
[dependencies]
|
||||
ansi_term = "0.12"
|
||||
clap = "3.2.17"
|
||||
lscolors = "0.7"
|
||||
terminal_size = "0.1"
|
||||
clap = "4.4"
|
||||
lscolors = "0.13"
|
||||
terminal_size = "0.2"
|
||||
unicode-width = "0.1"
|
||||
rayon = "1"
|
||||
thousands = "0.2"
|
||||
@@ -39,22 +39,30 @@ regex = "1"
|
||||
config-file = "0.2"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
directories = "4"
|
||||
sysinfo = "0.27"
|
||||
ctrlc = "3.4"
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
winapi-util = "0.1"
|
||||
filesize = "0.2.0"
|
||||
|
||||
[dev-dependencies]
|
||||
assert_cmd = "1"
|
||||
assert_cmd = "2"
|
||||
tempfile = "=3"
|
||||
|
||||
[build-dependencies]
|
||||
clap = "3.2.17"
|
||||
clap_complete = "3.2.4"
|
||||
clap = "4.4"
|
||||
clap_complete = "4.4"
|
||||
clap_mangen = "0.2"
|
||||
|
||||
[[test]]
|
||||
name = "integration"
|
||||
path = "tests/tests.rs"
|
||||
|
||||
[package.metadata.binstall]
|
||||
pkg-url = "{ repo }/releases/download/v{ version }/dust-v{ version }-{ target }{ archive-suffix }"
|
||||
bin-dir = "dust-v{ version }-{ target }/{ bin }{ binary-ext }"
|
||||
|
||||
[package.metadata.deb]
|
||||
section = "utils"
|
||||
assets = [
|
||||
|
||||
2
LICENSE
2
LICENSE
@@ -186,7 +186,7 @@
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
Copyright [2023] [andrew boot]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
34
README.md
34
README.md
@@ -1,4 +1,5 @@
|
||||
[](https://travis-ci.org/bootandy/dust)
|
||||
[](https://github.com/bootandy/dust/actions)
|
||||
|
||||
|
||||
# Dust
|
||||
|
||||
@@ -24,14 +25,23 @@ Because I want an easy way to see where my disk is being used.
|
||||
|
||||
#### 🍺 Homebrew (Linux)
|
||||
|
||||
- `brew tap tgotwig/linux-dust && brew install dust`
|
||||
- `brew install dust`
|
||||
|
||||
#### [Pacstall](https://github.com/pacstall/pacstall) (Debian/Ubuntu)
|
||||
|
||||
- `pacstall -I dust-bin`
|
||||
|
||||
### Anaconda (conda-forge)
|
||||
|
||||
- `conda install -c conda-forge dust`
|
||||
|
||||
#### [deb-get](https://github.com/wimpysworld/deb-get) (Debian/Ubuntu)
|
||||
|
||||
- `deb-get install du-dust`
|
||||
|
||||
#### Windows:
|
||||
|
||||
- `scoop install dust`
|
||||
- Windows GNU version - works
|
||||
- Windows MSVC - requires: [VCRUNTIME140.dll](https://docs.microsoft.com/en-gb/cpp/windows/latest-supported-vc-redist?view=msvc-170)
|
||||
|
||||
@@ -59,19 +69,37 @@ 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 -F (Show only files - finds your largest files)
|
||||
Usage: dust -r (reverse order of output)
|
||||
Usage: dust -H (si print sizes in powers of 1000 instead of 1024)
|
||||
Usage: dust -o si/b/kb/kib/mb/mib/gb/gib (si - prints sizes in powers of 1000. Others print size in that format).
|
||||
Usage: dust -X ignore (ignore all files and directories with the name 'ignore')
|
||||
Usage: dust -x (Only show directories on the same filesystem)
|
||||
Usage: dust -b (Do not show percentages or draw ASCII bars)
|
||||
Usage: dust -B (--bars-on-right - Percent bars moved to right side of screen)
|
||||
Usage: dust -i (Do not show hidden files)
|
||||
Usage: dust -c (No colors [monochrome])
|
||||
Usage: dust -C (Force colors)
|
||||
Usage: dust -f (Count files instead of diskspace)
|
||||
Usage: dust -t (Group by filetype)
|
||||
Usage: dust -z 10M (min-size, Only include files larger than 10M)
|
||||
Usage: dust -e regex (Only include files matching this regex (eg dust -e "\.png$" would match png files))
|
||||
Usage: dust -v regex (Exclude files matching this regex (eg dust -v "\.png$" would ignore png files))
|
||||
Usage: dust -L (dereference-links - Treat sym links as directories and go into them)
|
||||
Usage: dust -P (Disable the progress indicator)
|
||||
Usage: dust -R (For screen readers. Removes bars/symbols. Adds new column: depth level. (May want to use -p for full path too))
|
||||
Usage: dust -S (Custom Stack size - Use if you see: 'fatal runtime error: stack overflow' (default allocation: low memory=1048576, high memory=1073741824)"),
|
||||
Usage: dust --skip-total (No total row will be displayed)
|
||||
Usage: dust -z 40000/30MB/20kib (Exclude output files/directories below size 40000 bytes / 30MB / 20KiB)
|
||||
```
|
||||
|
||||
## Config file
|
||||
|
||||
Dust has a config file where the above options can be set.
|
||||
Either: `~/.config/dust/config.toml` or `~/.dust.toml`
|
||||
```
|
||||
$ cat ~/.config/dust/config.toml
|
||||
reverse=true
|
||||
```
|
||||
|
||||
## Alternatives
|
||||
|
||||
9
build.rs
9
build.rs
@@ -1,5 +1,8 @@
|
||||
use clap_complete::{generate_to, shells::*};
|
||||
use clap_mangen::Man;
|
||||
use std::fs::File;
|
||||
use std::io::Error;
|
||||
use std::path::Path;
|
||||
|
||||
include!("src/cli.rs");
|
||||
|
||||
@@ -14,5 +17,11 @@ fn main() -> Result<(), Error> {
|
||||
generate_to(PowerShell, &mut cmd, app_name, outdir)?;
|
||||
generate_to(Elvish, &mut cmd, app_name, outdir)?;
|
||||
|
||||
let file = Path::new("man-page").join("dust.1");
|
||||
std::fs::create_dir_all("man-page")?;
|
||||
let mut file = File::create(file)?;
|
||||
|
||||
Man::new(cmd).render(&mut file)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
# ----------- To do a release ---------
|
||||
# Compare times of runs to check no drastic slow down:
|
||||
# time target/release/dust ~/dev
|
||||
# time dust ~dev
|
||||
|
||||
# edit version in cargo.toml
|
||||
# tag a commit and push (increment version in Cargo.toml first):
|
||||
# git tag v0.4.5
|
||||
|
||||
@@ -21,40 +21,58 @@ _dust() {
|
||||
'--number-of-lines=[Number of lines of output to show. (Default is terminal_height - 10)]: : ' \
|
||||
'*-X+[Exclude any file or directory with this name]: : ' \
|
||||
'*--ignore-directory=[Exclude any file or directory with this name]: : ' \
|
||||
'-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]: : ' \
|
||||
'--ignore-all-in-file=[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]: : ' \
|
||||
'-z+[Minimum size file to include in output]: : ' \
|
||||
'--min-size=[Minimum size file to include in output]: : ' \
|
||||
'(-e --filter -t --file_types)*-v+[Exclude filepaths matching this regex. To ignore png files type: -v "\\.png$" ]: : ' \
|
||||
'(-e --filter -t --file_types)*--invert-filter=[Exclude filepaths matching this regex. To ignore png files type: -v "\\.png$" ]: : ' \
|
||||
'(-t --file_types)*-e+[Only include filepaths matching this regex. For png files type: -e "\\.png$" ]: : ' \
|
||||
'(-t --file_types)*--filter=[Only include filepaths matching this regex. For png files type: -e "\\.png$" ]: : ' \
|
||||
'(-e --filter -t --file_types)*-v+[Exclude filepaths matching this regex. To ignore png files type\: -v "\\.png\$" ]: : ' \
|
||||
'(-e --filter -t --file_types)*--invert-filter=[Exclude filepaths matching this regex. To ignore png files type\: -v "\\.png\$" ]: : ' \
|
||||
'(-t --file_types)*-e+[Only include filepaths matching this regex. For png files type\: -e "\\.png\$" ]: : ' \
|
||||
'(-t --file_types)*--filter=[Only include filepaths matching this regex. For png files type\: -e "\\.png\$" ]: : ' \
|
||||
'-w+[Specify width of output overriding the auto detection of terminal width]: : ' \
|
||||
'--terminal_width=[Specify width of output overriding the auto detection of terminal width]: : ' \
|
||||
'-h[Print help information]' \
|
||||
'--help[Print help information]' \
|
||||
'-V[Print version information]' \
|
||||
'--version[Print version information]' \
|
||||
'-o+[Changes output display size. si will print sizes in powers of 1000. b/bytes kb kib mb mib gb gib will print the whole tree in that size]: : ' \
|
||||
'--output-format=[Changes output display size. si will print sizes in powers of 1000. b/bytes kb kib mb mib gb gib will print the whole tree in that size]: : ' \
|
||||
'-S+[Specify memory to use as stack size - use if you see\: '\''fatal runtime error\: stack overflow'\'' (default low memory=1048576, high memory=1073741824)]: : ' \
|
||||
'--stack-size=[Specify memory to use as stack size - use if you see\: '\''fatal runtime error\: stack overflow'\'' (default low memory=1048576, high memory=1073741824)]: : ' \
|
||||
'-p[Subdirectories will not have their path shortened]' \
|
||||
'--full-paths[Subdirectories will not have their path shortened]' \
|
||||
'-L[dereference sym links - Treat sym links as directories and go into them]' \
|
||||
'--dereference-links[dereference sym links - Treat sym links as directories and go into them]' \
|
||||
'-x[Only count the files and directories on the same filesystem as the supplied directory]' \
|
||||
'--limit-filesystem[Only count the files and directories on the same filesystem as the supplied directory]' \
|
||||
'-s[Use file length instead of blocks]' \
|
||||
'--apparent-size[Use file length instead of blocks]' \
|
||||
'-r[Print tree upside down (biggest highest)]' \
|
||||
'--reverse[Print tree upside down (biggest highest)]' \
|
||||
'-c[No colors will be printed (Useful for commands like: watch)]' \
|
||||
'--no-colors[No colors will be printed (Useful for commands like: watch)]' \
|
||||
'-c[No colors will be printed (Useful for commands like\: watch)]' \
|
||||
'--no-colors[No colors will be printed (Useful for commands like\: watch)]' \
|
||||
'-C[Force colors print]' \
|
||||
'--force-colors[Force colors print]' \
|
||||
'-b[No percent bars or percentages will be displayed]' \
|
||||
'--no-percent-bars[No percent bars or percentages will be displayed]' \
|
||||
'-B[percent bars moved to right side of screen]' \
|
||||
'--bars-on-right[percent bars moved to right side of screen]' \
|
||||
'-R[For screen readers. Removes bars. Adds new column\: depth level (May want to use -p too for full path)]' \
|
||||
'--screen-reader[For screen readers. Removes bars. Adds new column\: depth level (May want to use -p too for full path)]' \
|
||||
'--skip-total[No total row will be displayed]' \
|
||||
'-f[Directory '\''size'\'' is number of child files/dirs not disk size]' \
|
||||
'--filecount[Directory '\''size'\'' is number of child files/dirs not disk size]' \
|
||||
'-f[Directory '\''size'\'' is number of child files instead of disk size]' \
|
||||
'--filecount[Directory '\''size'\'' is number of child files instead of disk size]' \
|
||||
'-i[Do not display hidden files]' \
|
||||
'--ignore_hidden[Do not display hidden files]' \
|
||||
'(-d --depth)-t[show only these file types]' \
|
||||
'(-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)]' \
|
||||
'*::inputs:' \
|
||||
'(-d --depth -D --only-dir)-t[show only these file types]' \
|
||||
'(-d --depth -D --only-dir)--file_types[show only these file types]' \
|
||||
'-P[Disable the progress indication.]' \
|
||||
'--no-progress[Disable the progress indication.]' \
|
||||
'(-F --only-file -t --file_types)-D[Only directories will be displayed.]' \
|
||||
'(-F --only-file -t --file_types)--only-dir[Only directories will be displayed.]' \
|
||||
'(-D --only-dir)-F[Only files will be displayed. (Finds your largest files)]' \
|
||||
'(-D --only-dir)--only-file[Only files will be displayed. (Finds your largest files)]' \
|
||||
'-h[Print help]' \
|
||||
'--help[Print help]' \
|
||||
'-V[Print version]' \
|
||||
'--version[Print version]' \
|
||||
'*::params:' \
|
||||
&& ret=0
|
||||
}
|
||||
|
||||
@@ -64,4 +82,8 @@ _dust_commands() {
|
||||
_describe -t commands 'dust commands' commands "$@"
|
||||
}
|
||||
|
||||
_dust "$@"
|
||||
if [ "$funcstack[1]" = "_dust" ]; then
|
||||
_dust "$@"
|
||||
else
|
||||
compdef _dust dust
|
||||
fi
|
||||
|
||||
@@ -25,8 +25,10 @@ Register-ArgumentCompleter -Native -CommandName 'dust' -ScriptBlock {
|
||||
[CompletionResult]::new('--depth', 'depth', [CompletionResultType]::ParameterName, 'Depth to show')
|
||||
[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 name')
|
||||
[CompletionResult]::new('-X', 'X ', [CompletionResultType]::ParameterName, 'Exclude any file or directory with this name')
|
||||
[CompletionResult]::new('--ignore-directory', 'ignore-directory', [CompletionResultType]::ParameterName, 'Exclude any file or directory with this name')
|
||||
[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')
|
||||
[CompletionResult]::new('--ignore-all-in-file', 'ignore-all-in-file', [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')
|
||||
[CompletionResult]::new('-z', 'z', [CompletionResultType]::ParameterName, 'Minimum size file to include in output')
|
||||
[CompletionResult]::new('--min-size', 'min-size', [CompletionResultType]::ParameterName, 'Minimum size file to include in output')
|
||||
[CompletionResult]::new('-v', 'v', [CompletionResultType]::ParameterName, 'Exclude filepaths matching this regex. To ignore png files type: -v "\.png$" ')
|
||||
@@ -35,12 +37,14 @@ Register-ArgumentCompleter -Native -CommandName 'dust' -ScriptBlock {
|
||||
[CompletionResult]::new('--filter', 'filter', [CompletionResultType]::ParameterName, 'Only include filepaths matching this regex. For png files type: -e "\.png$" ')
|
||||
[CompletionResult]::new('-w', 'w', [CompletionResultType]::ParameterName, 'Specify width of output overriding the auto detection of terminal width')
|
||||
[CompletionResult]::new('--terminal_width', 'terminal_width', [CompletionResultType]::ParameterName, 'Specify width of output overriding the auto detection of terminal width')
|
||||
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help information')
|
||||
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help information')
|
||||
[CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Print version information')
|
||||
[CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version information')
|
||||
[CompletionResult]::new('-o', 'o', [CompletionResultType]::ParameterName, 'Changes output display size. si will print sizes in powers of 1000. b/bytes kb kib mb mib gb gib will print the whole tree in that size')
|
||||
[CompletionResult]::new('--output-format', 'output-format', [CompletionResultType]::ParameterName, 'Changes output display size. si will print sizes in powers of 1000. b/bytes kb kib mb mib gb gib will print the whole tree in that size')
|
||||
[CompletionResult]::new('-S', 'S ', [CompletionResultType]::ParameterName, 'Specify memory to use as stack size - use if you see: ''fatal runtime error: stack overflow'' (default low memory=1048576, high memory=1073741824)')
|
||||
[CompletionResult]::new('--stack-size', 'stack-size', [CompletionResultType]::ParameterName, 'Specify memory to use as stack size - use if you see: ''fatal runtime error: stack overflow'' (default low memory=1048576, high memory=1073741824)')
|
||||
[CompletionResult]::new('-p', 'p', [CompletionResultType]::ParameterName, 'Subdirectories will not have their path shortened')
|
||||
[CompletionResult]::new('--full-paths', 'full-paths', [CompletionResultType]::ParameterName, 'Subdirectories will not have their path shortened')
|
||||
[CompletionResult]::new('-L', 'L ', [CompletionResultType]::ParameterName, 'dereference sym links - Treat sym links as directories and go into them')
|
||||
[CompletionResult]::new('--dereference-links', 'dereference-links', [CompletionResultType]::ParameterName, 'dereference sym links - Treat sym links as directories and go into them')
|
||||
[CompletionResult]::new('-x', 'x', [CompletionResultType]::ParameterName, 'Only count the files and directories on the same filesystem as the supplied directory')
|
||||
[CompletionResult]::new('--limit-filesystem', 'limit-filesystem', [CompletionResultType]::ParameterName, 'Only count the files and directories on the same filesystem as the supplied directory')
|
||||
[CompletionResult]::new('-s', 's', [CompletionResultType]::ParameterName, 'Use file length instead of blocks')
|
||||
@@ -49,17 +53,31 @@ Register-ArgumentCompleter -Native -CommandName 'dust' -ScriptBlock {
|
||||
[CompletionResult]::new('--reverse', 'reverse', [CompletionResultType]::ParameterName, 'Print tree upside down (biggest highest)')
|
||||
[CompletionResult]::new('-c', 'c', [CompletionResultType]::ParameterName, 'No colors will be printed (Useful for commands like: watch)')
|
||||
[CompletionResult]::new('--no-colors', 'no-colors', [CompletionResultType]::ParameterName, 'No colors will be printed (Useful for commands like: watch)')
|
||||
[CompletionResult]::new('-C', 'C ', [CompletionResultType]::ParameterName, 'Force colors print')
|
||||
[CompletionResult]::new('--force-colors', 'force-colors', [CompletionResultType]::ParameterName, 'Force colors print')
|
||||
[CompletionResult]::new('-b', 'b', [CompletionResultType]::ParameterName, 'No percent bars or percentages will be displayed')
|
||||
[CompletionResult]::new('--no-percent-bars', 'no-percent-bars', [CompletionResultType]::ParameterName, 'No percent bars or percentages will be displayed')
|
||||
[CompletionResult]::new('-B', 'B ', [CompletionResultType]::ParameterName, 'percent bars moved to right side of screen')
|
||||
[CompletionResult]::new('--bars-on-right', 'bars-on-right', [CompletionResultType]::ParameterName, 'percent bars moved to right side of screen')
|
||||
[CompletionResult]::new('-R', 'R ', [CompletionResultType]::ParameterName, 'For screen readers. Removes bars. Adds new column: depth level (May want to use -p too for full path)')
|
||||
[CompletionResult]::new('--screen-reader', 'screen-reader', [CompletionResultType]::ParameterName, 'For screen readers. Removes bars. Adds new column: depth level (May want to use -p too for full path)')
|
||||
[CompletionResult]::new('--skip-total', 'skip-total', [CompletionResultType]::ParameterName, 'No total row will be displayed')
|
||||
[CompletionResult]::new('-f', 'f', [CompletionResultType]::ParameterName, 'Directory ''size'' is number of child files/dirs not disk size')
|
||||
[CompletionResult]::new('--filecount', 'filecount', [CompletionResultType]::ParameterName, 'Directory ''size'' is number of child files/dirs not disk size')
|
||||
[CompletionResult]::new('-f', 'f', [CompletionResultType]::ParameterName, 'Directory ''size'' is number of child files instead of disk size')
|
||||
[CompletionResult]::new('--filecount', 'filecount', [CompletionResultType]::ParameterName, 'Directory ''size'' is number of child files instead of disk size')
|
||||
[CompletionResult]::new('-i', 'i', [CompletionResultType]::ParameterName, 'Do not display hidden files')
|
||||
[CompletionResult]::new('--ignore_hidden', 'ignore_hidden', [CompletionResultType]::ParameterName, 'Do not display hidden files')
|
||||
[CompletionResult]::new('-t', 't', [CompletionResultType]::ParameterName, 'show only these file types')
|
||||
[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('-P', 'P ', [CompletionResultType]::ParameterName, 'Disable the progress indication.')
|
||||
[CompletionResult]::new('--no-progress', 'no-progress', [CompletionResultType]::ParameterName, 'Disable the progress indication.')
|
||||
[CompletionResult]::new('-D', 'D ', [CompletionResultType]::ParameterName, 'Only directories will be displayed.')
|
||||
[CompletionResult]::new('--only-dir', 'only-dir', [CompletionResultType]::ParameterName, 'Only directories will be displayed.')
|
||||
[CompletionResult]::new('-F', 'F ', [CompletionResultType]::ParameterName, 'Only files will be displayed. (Finds your largest files)')
|
||||
[CompletionResult]::new('--only-file', 'only-file', [CompletionResultType]::ParameterName, 'Only files will be displayed. (Finds your largest files)')
|
||||
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help')
|
||||
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help')
|
||||
[CompletionResult]::new('-V', 'V ', [CompletionResultType]::ParameterName, 'Print version')
|
||||
[CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version')
|
||||
break
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
_dust() {
|
||||
local i cur prev opts cmds
|
||||
local i cur prev opts cmd
|
||||
COMPREPLY=()
|
||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||
@@ -8,8 +8,8 @@ _dust() {
|
||||
|
||||
for i in ${COMP_WORDS[@]}
|
||||
do
|
||||
case "${i}" in
|
||||
"$1")
|
||||
case "${cmd},${i}" in
|
||||
",$1")
|
||||
cmd="dust"
|
||||
;;
|
||||
*)
|
||||
@@ -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="-d -n -p -X -I -L -x -s -r -c -C -b -B -z -R -f -i -v -e -t -w -P -D -F -o -S -h -V --depth --number-of-lines --full-paths --ignore-directory --ignore-all-in-file --dereference-links --limit-filesystem --apparent-size --reverse --no-colors --force-colors --no-percent-bars --bars-on-right --min-size --screen-reader --skip-total --filecount --ignore_hidden --invert-filter --filter --file_types --terminal_width --no-progress --only-dir --only-file --output-format --stack-size --help --version [params]..."
|
||||
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
@@ -49,6 +49,14 @@ _dust() {
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--ignore-all-in-file)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
-I)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--min-size)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
@@ -81,6 +89,22 @@ _dust() {
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--output-format)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
-o)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--stack-size)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
-S)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
*)
|
||||
COMPREPLY=()
|
||||
;;
|
||||
@@ -91,4 +115,8 @@ _dust() {
|
||||
esac
|
||||
}
|
||||
|
||||
complete -F _dust -o bashdefault -o default dust
|
||||
if [[ "${BASH_VERSINFO[0]}" -eq 4 && "${BASH_VERSINFO[1]}" -ge 4 || "${BASH_VERSINFO[0]}" -gt 4 ]]; then
|
||||
complete -F _dust -o nosort -o bashdefault -o default dust
|
||||
else
|
||||
complete -F _dust -o bashdefault -o default dust
|
||||
fi
|
||||
|
||||
@@ -24,6 +24,8 @@ set edit:completion:arg-completer[dust] = {|@words|
|
||||
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 name'
|
||||
cand --ignore-directory 'Exclude any file or directory with this name'
|
||||
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'
|
||||
cand --ignore-all-in-file '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'
|
||||
cand -z 'Minimum size file to include in output'
|
||||
cand --min-size 'Minimum size file to include in output'
|
||||
cand -v 'Exclude filepaths matching this regex. To ignore png files type: -v "\.png$" '
|
||||
@@ -32,12 +34,14 @@ set edit:completion:arg-completer[dust] = {|@words|
|
||||
cand --filter 'Only include filepaths matching this regex. For png files type: -e "\.png$" '
|
||||
cand -w 'Specify width of output overriding the auto detection of terminal width'
|
||||
cand --terminal_width 'Specify width of output overriding the auto detection of terminal width'
|
||||
cand -h 'Print help information'
|
||||
cand --help 'Print help information'
|
||||
cand -V 'Print version information'
|
||||
cand --version 'Print version information'
|
||||
cand -o 'Changes output display size. si will print sizes in powers of 1000. b/bytes kb kib mb mib gb gib will print the whole tree in that size'
|
||||
cand --output-format 'Changes output display size. si will print sizes in powers of 1000. b/bytes kb kib mb mib gb gib will print the whole tree in that size'
|
||||
cand -S 'Specify memory to use as stack size - use if you see: ''fatal runtime error: stack overflow'' (default low memory=1048576, high memory=1073741824)'
|
||||
cand --stack-size 'Specify memory to use as stack size - use if you see: ''fatal runtime error: stack overflow'' (default low memory=1048576, high memory=1073741824)'
|
||||
cand -p 'Subdirectories will not have their path shortened'
|
||||
cand --full-paths 'Subdirectories will not have their path shortened'
|
||||
cand -L 'dereference sym links - Treat sym links as directories and go into them'
|
||||
cand --dereference-links 'dereference sym links - Treat sym links as directories and go into them'
|
||||
cand -x 'Only count the files and directories on the same filesystem as the supplied directory'
|
||||
cand --limit-filesystem 'Only count the files and directories on the same filesystem as the supplied directory'
|
||||
cand -s 'Use file length instead of blocks'
|
||||
@@ -46,17 +50,31 @@ set edit:completion:arg-completer[dust] = {|@words|
|
||||
cand --reverse 'Print tree upside down (biggest highest)'
|
||||
cand -c 'No colors will be printed (Useful for commands like: watch)'
|
||||
cand --no-colors 'No colors will be printed (Useful for commands like: watch)'
|
||||
cand -C 'Force colors print'
|
||||
cand --force-colors 'Force colors print'
|
||||
cand -b 'No percent bars or percentages will be displayed'
|
||||
cand --no-percent-bars 'No percent bars or percentages will be displayed'
|
||||
cand -B 'percent bars moved to right side of screen'
|
||||
cand --bars-on-right 'percent bars moved to right side of screen'
|
||||
cand -R 'For screen readers. Removes bars. Adds new column: depth level (May want to use -p too for full path)'
|
||||
cand --screen-reader 'For screen readers. Removes bars. Adds new column: depth level (May want to use -p too for full path)'
|
||||
cand --skip-total 'No total row will be displayed'
|
||||
cand -f 'Directory ''size'' is number of child files/dirs not disk size'
|
||||
cand --filecount 'Directory ''size'' is number of child files/dirs not disk size'
|
||||
cand -f 'Directory ''size'' is number of child files instead of disk size'
|
||||
cand --filecount 'Directory ''size'' is number of child files instead of disk size'
|
||||
cand -i 'Do not display hidden files'
|
||||
cand --ignore_hidden 'Do not display hidden files'
|
||||
cand -t 'show only these file types'
|
||||
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 -P 'Disable the progress indication.'
|
||||
cand --no-progress 'Disable the progress indication.'
|
||||
cand -D 'Only directories will be displayed.'
|
||||
cand --only-dir 'Only directories will be displayed.'
|
||||
cand -F 'Only files will be displayed. (Finds your largest files)'
|
||||
cand --only-file 'Only files will be displayed. (Finds your largest files)'
|
||||
cand -h 'Print help'
|
||||
cand --help 'Print help'
|
||||
cand -V 'Print version'
|
||||
cand --version 'Print version'
|
||||
}
|
||||
]
|
||||
$completions[$command]
|
||||
|
||||
@@ -1,20 +1,29 @@
|
||||
complete -c dust -s d -l depth -d 'Depth to show' -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 name' -r
|
||||
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
|
||||
complete -c dust -s z -l min-size -d 'Minimum size file to include in output' -r
|
||||
complete -c dust -s v -l invert-filter -d 'Exclude filepaths matching this regex. To ignore png files type: -v "\\.png$" ' -r
|
||||
complete -c dust -s e -l filter -d 'Only include filepaths matching this regex. For png files type: -e "\\.png$" ' -r
|
||||
complete -c dust -s w -l terminal_width -d 'Specify width of output overriding the auto detection of terminal width' -r
|
||||
complete -c dust -s h -l help -d 'Print help information'
|
||||
complete -c dust -s V -l version -d 'Print version information'
|
||||
complete -c dust -s o -l output-format -d 'Changes output display size. si will print sizes in powers of 1000. b/bytes kb kib mb mib gb gib will print the whole tree in that size' -r
|
||||
complete -c dust -s S -l stack-size -d 'Specify memory to use as stack size - use if you see: \'fatal runtime error: stack overflow\' (default low memory=1048576, high memory=1073741824)' -r
|
||||
complete -c dust -s p -l full-paths -d 'Subdirectories will not have their path shortened'
|
||||
complete -c dust -s L -l dereference-links -d 'dereference sym links - Treat sym links as directories and go into them'
|
||||
complete -c dust -s x -l limit-filesystem -d 'Only count the files and directories on the same filesystem as the supplied directory'
|
||||
complete -c dust -s s -l apparent-size -d 'Use file length instead of blocks'
|
||||
complete -c dust -s r -l reverse -d 'Print tree upside down (biggest highest)'
|
||||
complete -c dust -s c -l no-colors -d 'No colors will be printed (Useful for commands like: watch)'
|
||||
complete -c dust -s C -l force-colors -d 'Force colors print'
|
||||
complete -c dust -s b -l no-percent-bars -d 'No percent bars or percentages will be displayed'
|
||||
complete -c dust -s B -l bars-on-right -d 'percent bars moved to right side of screen'
|
||||
complete -c dust -s R -l screen-reader -d 'For screen readers. Removes bars. Adds new column: depth level (May want to use -p too for full path)'
|
||||
complete -c dust -l skip-total -d 'No total row will be displayed'
|
||||
complete -c dust -s f -l filecount -d 'Directory \'size\' is number of child files/dirs not disk size'
|
||||
complete -c dust -s f -l filecount -d 'Directory \'size\' is number of child files instead of disk size'
|
||||
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 P -l no-progress -d 'Disable the progress indication.'
|
||||
complete -c dust -s D -l only-dir -d 'Only directories will be displayed.'
|
||||
complete -c dust -s F -l only-file -d 'Only files will be displayed. (Finds your largest files)'
|
||||
complete -c dust -s h -l help -d 'Print help'
|
||||
complete -c dust -s V -l version -d 'Print version'
|
||||
|
||||
@@ -3,11 +3,26 @@
|
||||
# ~/.config/dust/config.toml
|
||||
# ~/.dust.toml
|
||||
|
||||
# Print tree upside down (biggest highest)
|
||||
reverse=true
|
||||
|
||||
# Subdirectories will not have their path shortened
|
||||
display-full-paths=true
|
||||
|
||||
# Use file length instead of blocks
|
||||
display-apparent-size=true
|
||||
|
||||
# No colors will be printed
|
||||
no-colors=true
|
||||
|
||||
# No percent bars or percentages will be displayed
|
||||
no-bars=true
|
||||
|
||||
# No total row will be displayed
|
||||
skip-total=true
|
||||
|
||||
# Do not display hidden files
|
||||
ignore-hidden=true
|
||||
|
||||
# print sizes in powers of 1000 (e.g., 1.1G)
|
||||
iso=true
|
||||
|
||||
102
man-page/dust.1
Normal file
102
man-page/dust.1
Normal file
@@ -0,0 +1,102 @@
|
||||
.ie \n(.g .ds Aq \(aq
|
||||
.el .ds Aq '
|
||||
.TH Dust 1 "Dust 1.0.0"
|
||||
.SH NAME
|
||||
Dust \- Like du but more intuitive
|
||||
.SH SYNOPSIS
|
||||
\fBdust\fR [\fB\-d\fR|\fB\-\-depth\fR] [\fB\-n\fR|\fB\-\-number\-of\-lines\fR] [\fB\-p\fR|\fB\-\-full\-paths\fR] [\fB\-X\fR|\fB\-\-ignore\-directory\fR] [\fB\-I\fR|\fB\-\-ignore\-all\-in\-file\fR] [\fB\-L\fR|\fB\-\-dereference\-links\fR] [\fB\-x\fR|\fB\-\-limit\-filesystem\fR] [\fB\-s\fR|\fB\-\-apparent\-size\fR] [\fB\-r\fR|\fB\-\-reverse\fR] [\fB\-c\fR|\fB\-\-no\-colors\fR] [\fB\-C\fR|\fB\-\-force\-colors\fR] [\fB\-b\fR|\fB\-\-no\-percent\-bars\fR] [\fB\-B\fR|\fB\-\-bars\-on\-right\fR] [\fB\-z\fR|\fB\-\-min\-size\fR] [\fB\-R\fR|\fB\-\-screen\-reader\fR] [\fB\-\-skip\-total\fR] [\fB\-f\fR|\fB\-\-filecount\fR] [\fB\-i\fR|\fB\-\-ignore_hidden\fR] [\fB\-v\fR|\fB\-\-invert\-filter\fR] [\fB\-e\fR|\fB\-\-filter\fR] [\fB\-t\fR|\fB\-\-file_types\fR] [\fB\-w\fR|\fB\-\-terminal_width\fR] [\fB\-P\fR|\fB\-\-no\-progress\fR] [\fB\-D\fR|\fB\-\-only\-dir\fR] [\fB\-F\fR|\fB\-\-only\-file\fR] [\fB\-o\fR|\fB\-\-output\-format\fR] [\fB\-S\fR|\fB\-\-stack\-size\fR] [\fB\-h\fR|\fB\-\-help\fR] [\fB\-V\fR|\fB\-\-version\fR] [\fIparams\fR]
|
||||
.SH DESCRIPTION
|
||||
Like du but more intuitive
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
\fB\-d\fR, \fB\-\-depth\fR
|
||||
Depth to show
|
||||
.TP
|
||||
\fB\-n\fR, \fB\-\-number\-of\-lines\fR
|
||||
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
|
||||
.TP
|
||||
\fB\-X\fR, \fB\-\-ignore\-directory\fR
|
||||
Exclude any file or directory with this name
|
||||
.TP
|
||||
\fB\-I\fR, \fB\-\-ignore\-all\-in\-file\fR
|
||||
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
|
||||
.TP
|
||||
\fB\-L\fR, \fB\-\-dereference\-links\fR
|
||||
dereference sym links \- Treat sym links as directories and go into them
|
||||
.TP
|
||||
\fB\-x\fR, \fB\-\-limit\-filesystem\fR
|
||||
Only count the files and directories on the same filesystem as the supplied directory
|
||||
.TP
|
||||
\fB\-s\fR, \fB\-\-apparent\-size\fR
|
||||
Use file length instead of blocks
|
||||
.TP
|
||||
\fB\-r\fR, \fB\-\-reverse\fR
|
||||
Print tree upside down (biggest highest)
|
||||
.TP
|
||||
\fB\-c\fR, \fB\-\-no\-colors\fR
|
||||
No colors will be printed (Useful for commands like: watch)
|
||||
.TP
|
||||
\fB\-C\fR, \fB\-\-force\-colors\fR
|
||||
Force colors print
|
||||
.TP
|
||||
\fB\-b\fR, \fB\-\-no\-percent\-bars\fR
|
||||
No percent bars or percentages will be displayed
|
||||
.TP
|
||||
\fB\-B\fR, \fB\-\-bars\-on\-right\fR
|
||||
percent bars moved to right side of screen
|
||||
.TP
|
||||
\fB\-z\fR, \fB\-\-min\-size\fR
|
||||
Minimum size file to include in output
|
||||
.TP
|
||||
\fB\-R\fR, \fB\-\-screen\-reader\fR
|
||||
For screen readers. Removes bars. Adds new column: depth level (May want to use \-p too for full path)
|
||||
.TP
|
||||
\fB\-\-skip\-total\fR
|
||||
No total row will be displayed
|
||||
.TP
|
||||
\fB\-f\fR, \fB\-\-filecount\fR
|
||||
Directory \*(Aqsize\*(Aq is number of child files instead of disk size
|
||||
.TP
|
||||
\fB\-i\fR, \fB\-\-ignore_hidden\fR
|
||||
Do not display hidden files
|
||||
.TP
|
||||
\fB\-v\fR, \fB\-\-invert\-filter\fR
|
||||
Exclude filepaths matching this regex. To ignore png files type: \-v "\\.png$"
|
||||
.TP
|
||||
\fB\-e\fR, \fB\-\-filter\fR
|
||||
Only include filepaths matching this regex. For png files type: \-e "\\.png$"
|
||||
.TP
|
||||
\fB\-t\fR, \fB\-\-file_types\fR
|
||||
show only these file types
|
||||
.TP
|
||||
\fB\-w\fR, \fB\-\-terminal_width\fR
|
||||
Specify width of output overriding the auto detection of terminal width
|
||||
.TP
|
||||
\fB\-P\fR, \fB\-\-no\-progress\fR
|
||||
Disable the progress indication.
|
||||
.TP
|
||||
\fB\-D\fR, \fB\-\-only\-dir\fR
|
||||
Only directories will be displayed.
|
||||
.TP
|
||||
\fB\-F\fR, \fB\-\-only\-file\fR
|
||||
Only files will be displayed. (Finds your largest files)
|
||||
.TP
|
||||
\fB\-o\fR, \fB\-\-output\-format\fR
|
||||
Changes output display size. si will print sizes in powers of 1000. b/bytes kb kib mb mib gb gib will print the whole tree in that size
|
||||
.TP
|
||||
\fB\-S\fR, \fB\-\-stack\-size\fR
|
||||
Specify memory to use as stack size \- use if you see: \*(Aqfatal runtime error: stack overflow\*(Aq (default low memory=1048576, high memory=1073741824)
|
||||
.TP
|
||||
\fB\-h\fR, \fB\-\-help\fR
|
||||
Print help
|
||||
.TP
|
||||
\fB\-V\fR, \fB\-\-version\fR
|
||||
Print version
|
||||
.TP
|
||||
[\fIparams\fR]
|
||||
|
||||
.SH VERSION
|
||||
v1.0.0
|
||||
124
src/cli.rs
124
src/cli.rs
@@ -1,6 +1,9 @@
|
||||
use clap::{Arg, Command};
|
||||
use clap::{value_parser, Arg, Command};
|
||||
|
||||
pub fn build_cli() -> Command<'static> {
|
||||
// For single thread mode set this variable on your command line:
|
||||
// export RAYON_NUM_THREADS=1
|
||||
|
||||
pub fn build_cli() -> Command {
|
||||
Command::new("Dust")
|
||||
.about("Like du but more intuitive")
|
||||
.version(env!("CARGO_PKG_VERSION"))
|
||||
@@ -9,93 +12,134 @@ pub fn build_cli() -> Command<'static> {
|
||||
Arg::new("depth")
|
||||
.short('d')
|
||||
.long("depth")
|
||||
.value_parser(value_parser!(usize))
|
||||
.help("Depth to show")
|
||||
.takes_value(true)
|
||||
.num_args(1)
|
||||
)
|
||||
.arg(
|
||||
Arg::new("number_of_lines")
|
||||
.short('n')
|
||||
.long("number-of-lines")
|
||||
.value_parser(value_parser!(usize))
|
||||
.help("Number of lines of output to show. (Default is terminal_height - 10)")
|
||||
.takes_value(true)
|
||||
.num_args(1)
|
||||
)
|
||||
.arg(
|
||||
Arg::new("display_full_paths")
|
||||
.short('p')
|
||||
.long("full-paths")
|
||||
.action(clap::ArgAction::SetTrue)
|
||||
.help("Subdirectories will not have their path shortened"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("ignore_directory")
|
||||
.short('X')
|
||||
.long("ignore-directory")
|
||||
.takes_value(true)
|
||||
.number_of_values(1)
|
||||
.multiple_occurrences(true)
|
||||
.action(clap::ArgAction::Append)
|
||||
.help("Exclude any file or directory with this name"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("ignore_all_in_file")
|
||||
.short('I')
|
||||
.long("ignore-all-in-file")
|
||||
.value_parser(value_parser!(String))
|
||||
.help("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"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("dereference_links")
|
||||
.short('L')
|
||||
.long("dereference-links")
|
||||
.action(clap::ArgAction::SetTrue)
|
||||
.help("dereference sym links - Treat sym links as directories and go into them"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("limit_filesystem")
|
||||
.short('x')
|
||||
.long("limit-filesystem")
|
||||
.action(clap::ArgAction::SetTrue)
|
||||
.help("Only count the files and directories on the same filesystem as the supplied directory"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("display_apparent_size")
|
||||
.short('s')
|
||||
.long("apparent-size")
|
||||
.action(clap::ArgAction::SetTrue)
|
||||
.help("Use file length instead of blocks"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("reverse")
|
||||
.short('r')
|
||||
.long("reverse")
|
||||
.action(clap::ArgAction::SetTrue)
|
||||
.help("Print tree upside down (biggest highest)"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("no_colors")
|
||||
.short('c')
|
||||
.long("no-colors")
|
||||
.action(clap::ArgAction::SetTrue)
|
||||
.help("No colors will be printed (Useful for commands like: watch)"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("force_colors")
|
||||
.short('C')
|
||||
.long("force-colors")
|
||||
.action(clap::ArgAction::SetTrue)
|
||||
.help("Force colors print"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("no_bars")
|
||||
.short('b')
|
||||
.long("no-percent-bars")
|
||||
.action(clap::ArgAction::SetTrue)
|
||||
.help("No percent bars or percentages will be displayed"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("bars_on_right")
|
||||
.short('B')
|
||||
.long("bars-on-right")
|
||||
.action(clap::ArgAction::SetTrue)
|
||||
.help("percent bars moved to right side of screen"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("min_size")
|
||||
.short('z')
|
||||
.long("min-size")
|
||||
.takes_value(true)
|
||||
.number_of_values(1)
|
||||
.num_args(1)
|
||||
.help("Minimum size file to include in output"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("screen_reader")
|
||||
.short('R')
|
||||
.long("screen-reader")
|
||||
.action(clap::ArgAction::SetTrue)
|
||||
.help("For screen readers. Removes bars. Adds new column: depth level (May want to use -p too for full path)"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("skip_total")
|
||||
.long("skip-total")
|
||||
.action(clap::ArgAction::SetTrue)
|
||||
.help("No total row will be displayed"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("by_filecount")
|
||||
.short('f')
|
||||
.long("filecount")
|
||||
.help("Directory 'size' is number of child files/dirs not disk size"),
|
||||
.action(clap::ArgAction::SetTrue)
|
||||
.help("Directory 'size' is number of child files instead of disk size"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("ignore_hidden")
|
||||
.short('i') // Do not use 'h' this is used by 'help'
|
||||
.long("ignore_hidden")
|
||||
.action(clap::ArgAction::SetTrue)
|
||||
.help("Do not display hidden files"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("invert_filter")
|
||||
.short('v')
|
||||
.long("invert-filter")
|
||||
.takes_value(true)
|
||||
.number_of_values(1)
|
||||
.multiple_occurrences(true)
|
||||
.action(clap::ArgAction::Append)
|
||||
.conflicts_with("filter")
|
||||
.conflicts_with("types")
|
||||
.help("Exclude filepaths matching this regex. To ignore png files type: -v \"\\.png$\" "),
|
||||
@@ -104,9 +148,7 @@ pub fn build_cli() -> Command<'static> {
|
||||
Arg::new("filter")
|
||||
.short('e')
|
||||
.long("filter")
|
||||
.takes_value(true)
|
||||
.number_of_values(1)
|
||||
.multiple_occurrences(true)
|
||||
.action(clap::ArgAction::Append)
|
||||
.conflicts_with("types")
|
||||
.help("Only include filepaths matching this regex. For png files type: -e \"\\.png$\" "),
|
||||
)
|
||||
@@ -115,21 +157,57 @@ pub fn build_cli() -> Command<'static> {
|
||||
.short('t')
|
||||
.long("file_types")
|
||||
.conflicts_with("depth")
|
||||
.conflicts_with("only_dir")
|
||||
.action(clap::ArgAction::SetTrue)
|
||||
.help("show only these file types"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("width")
|
||||
.short('w')
|
||||
.long("terminal_width")
|
||||
.takes_value(true)
|
||||
.number_of_values(1)
|
||||
.num_args(1)
|
||||
.value_parser(value_parser!(usize))
|
||||
.help("Specify width of output overriding the auto detection of terminal width"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("iso")
|
||||
.short('H')
|
||||
.long("si")
|
||||
.help("print sizes in powers of 1000 (e.g., 1.1G)")
|
||||
Arg::new("disable_progress")
|
||||
.short('P')
|
||||
.long("no-progress")
|
||||
.action(clap::ArgAction::SetTrue)
|
||||
.help("Disable the progress indication."),
|
||||
)
|
||||
.arg(Arg::new("inputs").multiple_occurrences(true).default_value("."))
|
||||
.arg(
|
||||
Arg::new("only_dir")
|
||||
.short('D')
|
||||
.long("only-dir")
|
||||
.conflicts_with("only_file")
|
||||
.conflicts_with("types")
|
||||
.action(clap::ArgAction::SetTrue)
|
||||
.help("Only directories will be displayed."),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("only_file")
|
||||
.short('F')
|
||||
.long("only-file")
|
||||
.conflicts_with("only_dir")
|
||||
.action(clap::ArgAction::SetTrue)
|
||||
.help("Only files will be displayed. (Finds your largest files)"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("output_format")
|
||||
.short('o')
|
||||
.long("output-format")
|
||||
.value_parser(value_parser!(String))
|
||||
.help("Changes output display size. si will print sizes in powers of 1000. b/bytes kb kib mb mib gb gib will print the whole tree in that size")
|
||||
)
|
||||
.arg(
|
||||
Arg::new("stack_size")
|
||||
.short('S')
|
||||
.long("stack-size")
|
||||
.num_args(1)
|
||||
.value_parser(value_parser!(usize))
|
||||
.help("Specify memory to use as stack size - use if you see: 'fatal runtime error: stack overflow' (default low memory=1048576, high memory=1073741824)"),
|
||||
)
|
||||
.arg(Arg::new("params").num_args(1..)
|
||||
.value_parser(value_parser!(String)))
|
||||
}
|
||||
|
||||
200
src/config.rs
200
src/config.rs
@@ -1,10 +1,12 @@
|
||||
use clap::ArgMatches;
|
||||
use config_file::FromConfigFile;
|
||||
use regex::Regex;
|
||||
use serde::Deserialize;
|
||||
use std::io::IsTerminal;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crate::display::UNITS;
|
||||
use crate::display::get_number_format;
|
||||
|
||||
#[derive(Deserialize, Default)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
@@ -14,85 +16,137 @@ pub struct Config {
|
||||
pub display_apparent_size: Option<bool>,
|
||||
pub reverse: Option<bool>,
|
||||
pub no_colors: Option<bool>,
|
||||
pub force_colors: Option<bool>,
|
||||
pub no_bars: Option<bool>,
|
||||
pub skip_total: Option<bool>,
|
||||
pub screen_reader: Option<bool>,
|
||||
pub ignore_hidden: Option<bool>,
|
||||
pub iso: Option<bool>,
|
||||
pub output_format: Option<String>,
|
||||
pub min_size: Option<String>,
|
||||
pub only_dir: Option<bool>,
|
||||
pub only_file: Option<bool>,
|
||||
pub disable_progress: Option<bool>,
|
||||
pub depth: Option<usize>,
|
||||
pub bars_on_right: Option<bool>,
|
||||
pub stack_size: Option<usize>,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn get_no_colors(&self, options: &ArgMatches) -> bool {
|
||||
Some(true) == self.no_colors || options.is_present("no_colors")
|
||||
Some(true) == self.no_colors || options.get_flag("no_colors")
|
||||
}
|
||||
pub fn get_force_colors(&self, options: &ArgMatches) -> bool {
|
||||
Some(true) == self.force_colors || options.get_flag("force_colors")
|
||||
}
|
||||
pub fn get_disable_progress(&self, options: &ArgMatches) -> bool {
|
||||
Some(true) == self.disable_progress
|
||||
|| options.get_flag("disable_progress")
|
||||
|| !std::io::stdout().is_terminal()
|
||||
}
|
||||
pub fn get_apparent_size(&self, options: &ArgMatches) -> bool {
|
||||
Some(true) == self.display_apparent_size || options.is_present("display_apparent_size")
|
||||
Some(true) == self.display_apparent_size || options.get_flag("display_apparent_size")
|
||||
}
|
||||
pub fn get_ignore_hidden(&self, options: &ArgMatches) -> bool {
|
||||
Some(true) == self.ignore_hidden || options.is_present("ignore_hidden")
|
||||
Some(true) == self.ignore_hidden || options.get_flag("ignore_hidden")
|
||||
}
|
||||
pub fn get_full_paths(&self, options: &ArgMatches) -> bool {
|
||||
Some(true) == self.display_full_paths || options.is_present("display_full_paths")
|
||||
// If we are only showing files, always show full paths
|
||||
Some(true) == self.display_full_paths
|
||||
|| options.get_flag("display_full_paths")
|
||||
|| self.get_only_file(options)
|
||||
}
|
||||
pub fn get_reverse(&self, options: &ArgMatches) -> bool {
|
||||
Some(true) == self.reverse || options.is_present("reverse")
|
||||
Some(true) == self.reverse || options.get_flag("reverse")
|
||||
}
|
||||
pub fn get_no_bars(&self, options: &ArgMatches) -> bool {
|
||||
Some(true) == self.no_bars || options.is_present("no_bars")
|
||||
Some(true) == self.no_bars || options.get_flag("no_bars")
|
||||
}
|
||||
pub fn get_iso(&self, options: &ArgMatches) -> bool {
|
||||
Some(true) == self.iso || options.is_present("iso")
|
||||
pub fn get_output_format(&self, options: &ArgMatches) -> String {
|
||||
let out_fmt = options.get_one::<String>("output_format");
|
||||
(match out_fmt {
|
||||
None => match &self.output_format {
|
||||
None => "".to_string(),
|
||||
Some(x) => x.to_string(),
|
||||
},
|
||||
Some(x) => x.into(),
|
||||
})
|
||||
.to_lowercase()
|
||||
}
|
||||
pub fn get_skip_total(&self, options: &ArgMatches) -> bool {
|
||||
Some(true) == self.skip_total || options.is_present("skip_total")
|
||||
Some(true) == self.skip_total || options.get_flag("skip_total")
|
||||
}
|
||||
pub fn get_min_size(&self, options: &ArgMatches, iso: bool) -> Option<usize> {
|
||||
let size_from_param = options.value_of("min_size");
|
||||
self._get_min_size(size_from_param, iso)
|
||||
pub fn get_screen_reader(&self, options: &ArgMatches) -> bool {
|
||||
Some(true) == self.screen_reader || options.get_flag("screen_reader")
|
||||
}
|
||||
fn _get_min_size(&self, min_size: Option<&str>, iso: bool) -> Option<usize> {
|
||||
let size_from_param = min_size.and_then(|a| convert_min_size(a, iso));
|
||||
pub fn get_depth(&self, options: &ArgMatches) -> usize {
|
||||
if let Some(v) = options.get_one::<usize>("depth") {
|
||||
return *v;
|
||||
}
|
||||
|
||||
self.depth.unwrap_or(usize::MAX)
|
||||
}
|
||||
pub fn get_min_size(&self, options: &ArgMatches) -> Option<usize> {
|
||||
let size_from_param = options.get_one::<String>("min_size");
|
||||
self._get_min_size(size_from_param)
|
||||
}
|
||||
fn _get_min_size(&self, min_size: Option<&String>) -> Option<usize> {
|
||||
let size_from_param = min_size.and_then(|a| convert_min_size(a));
|
||||
|
||||
if size_from_param.is_none() {
|
||||
self.min_size
|
||||
.as_ref()
|
||||
.and_then(|a| convert_min_size(a.as_ref(), iso))
|
||||
.and_then(|a| convert_min_size(a.as_ref()))
|
||||
} else {
|
||||
size_from_param
|
||||
}
|
||||
}
|
||||
pub fn get_only_dir(&self, options: &ArgMatches) -> bool {
|
||||
Some(true) == self.only_dir || options.get_flag("only_dir")
|
||||
}
|
||||
pub fn get_only_file(&self, options: &ArgMatches) -> bool {
|
||||
Some(true) == self.only_file || options.get_flag("only_file")
|
||||
}
|
||||
pub fn get_bars_on_right(&self, options: &ArgMatches) -> bool {
|
||||
Some(true) == self.bars_on_right || options.get_flag("bars_on_right")
|
||||
}
|
||||
pub fn get_custom_stack_size(&self, options: &ArgMatches) -> Option<usize> {
|
||||
let from_cmd_line = options.get_one::<usize>("stack_size");
|
||||
if from_cmd_line.is_none() {
|
||||
self.stack_size
|
||||
} else {
|
||||
from_cmd_line.copied()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn convert_min_size(input: &str, iso: bool) -> Option<usize> {
|
||||
let chars_as_vec: Vec<char> = input.chars().collect();
|
||||
match chars_as_vec.split_last() {
|
||||
Some((last, start)) => {
|
||||
let mut starts: String = start.iter().collect::<String>();
|
||||
fn convert_min_size(input: &str) -> Option<usize> {
|
||||
let re = Regex::new(r"([0-9]+)(\w*)").unwrap();
|
||||
|
||||
for (i, u) in UNITS.iter().rev().enumerate() {
|
||||
if Some(*u) == last.to_uppercase().next() {
|
||||
return match starts.parse::<usize>() {
|
||||
Ok(pure) => {
|
||||
let num: usize = if iso { 1000 } else { 1024 };
|
||||
let marker = pure * num.pow((i + 1) as u32);
|
||||
Some(marker)
|
||||
}
|
||||
Err(_) => {
|
||||
eprintln!("Ignoring invalid min-size: {}", input);
|
||||
if let Some(cap) = re.captures(input) {
|
||||
let (_, [digits, letters]) = cap.extract();
|
||||
|
||||
// Failure to parse should be impossible due to regex match
|
||||
let digits_as_usize: Option<usize> = digits.parse().ok();
|
||||
|
||||
match digits_as_usize {
|
||||
Some(parsed_digits) => {
|
||||
let number_format = get_number_format(&letters.to_lowercase());
|
||||
match number_format {
|
||||
Some((multiple, _)) => Some(parsed_digits * (multiple as usize)),
|
||||
None => {
|
||||
if letters.eq("") {
|
||||
Some(parsed_digits)
|
||||
} else {
|
||||
eprintln!("Ignoring invalid min-size: {input}");
|
||||
None
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
starts.push(*last);
|
||||
starts
|
||||
.parse()
|
||||
.map_err(|_| {
|
||||
eprintln!("Ignoring invalid min-size: {}", input);
|
||||
})
|
||||
.ok()
|
||||
None => None,
|
||||
}
|
||||
None => None,
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,19 +172,21 @@ pub fn get_config() -> Config {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[allow(unused_imports)]
|
||||
use super::*;
|
||||
use clap::{value_parser, Arg, ArgMatches, Command};
|
||||
|
||||
#[test]
|
||||
fn test_conversion() {
|
||||
assert_eq!(convert_min_size("55", false), Some(55));
|
||||
assert_eq!(convert_min_size("12344321", false), Some(12344321));
|
||||
assert_eq!(convert_min_size("95RUBBISH", false), None);
|
||||
assert_eq!(convert_min_size("10K", false), Some(10 * 1024));
|
||||
assert_eq!(convert_min_size("10M", false), Some(10 * 1024usize.pow(2)));
|
||||
assert_eq!(convert_min_size("10M", true), Some(10 * 1000usize.pow(2)));
|
||||
assert_eq!(convert_min_size("2G", false), Some(2 * 1024usize.pow(3)));
|
||||
assert_eq!(convert_min_size("55"), Some(55));
|
||||
assert_eq!(convert_min_size("12344321"), Some(12344321));
|
||||
assert_eq!(convert_min_size("95RUBBISH"), None);
|
||||
assert_eq!(convert_min_size("10K"), Some(10 * 1024));
|
||||
assert_eq!(convert_min_size("10M"), Some(10 * 1024usize.pow(2)));
|
||||
assert_eq!(convert_min_size("10MiB"), Some(10 * 1000usize.pow(2)));
|
||||
assert_eq!(convert_min_size("2G"), Some(2 * 1024usize.pow(3)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -139,10 +195,50 @@ mod tests {
|
||||
min_size: Some("1K".to_owned()),
|
||||
..Default::default()
|
||||
};
|
||||
assert_eq!(c._get_min_size(None, false), Some(1024));
|
||||
assert_eq!(c._get_min_size(Some("2K"), false), Some(2048));
|
||||
assert_eq!(c._get_min_size(None), Some(1024));
|
||||
assert_eq!(c._get_min_size(Some(&"2K".into())), Some(2048));
|
||||
|
||||
assert_eq!(c._get_min_size(None, true), Some(1000));
|
||||
assert_eq!(c._get_min_size(Some("2K"), true), Some(2000));
|
||||
assert_eq!(c._get_min_size(Some(&"1kib".into())), Some(1000));
|
||||
assert_eq!(c._get_min_size(Some(&"2KiB".into())), Some(2000));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_depth() {
|
||||
// No config and no flag.
|
||||
let c = Config::default();
|
||||
let args = get_args(vec![]);
|
||||
assert_eq!(c.get_depth(&args), usize::MAX);
|
||||
|
||||
// Config is not defined and flag is defined.
|
||||
let c = Config::default();
|
||||
let args = get_args(vec!["dust", "--depth", "5"]);
|
||||
assert_eq!(c.get_depth(&args), 5);
|
||||
|
||||
// Config is defined and flag is not defined.
|
||||
let c = Config {
|
||||
depth: Some(3),
|
||||
..Default::default()
|
||||
};
|
||||
let args = get_args(vec![]);
|
||||
assert_eq!(c.get_depth(&args), 3);
|
||||
|
||||
// Both config and flag are defined.
|
||||
let c = Config {
|
||||
depth: Some(3),
|
||||
..Default::default()
|
||||
};
|
||||
let args = get_args(vec!["dust", "--depth", "5"]);
|
||||
assert_eq!(c.get_depth(&args), 5);
|
||||
}
|
||||
|
||||
fn get_args(args: Vec<&str>) -> ArgMatches {
|
||||
Command::new("Dust")
|
||||
.arg(
|
||||
Arg::new("depth")
|
||||
.long("depth")
|
||||
.num_args(1)
|
||||
.value_parser(value_parser!(usize)),
|
||||
)
|
||||
.get_matches_from(args)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
use std::fs;
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
|
||||
use crate::node::Node;
|
||||
use crate::progress::Operation;
|
||||
use crate::progress::PAtomicInfo;
|
||||
use crate::progress::RuntimeErrors;
|
||||
use crate::progress::ORDERING;
|
||||
use crate::utils::is_filtered_out_due_to_invert_regex;
|
||||
use crate::utils::is_filtered_out_due_to_regex;
|
||||
use rayon::iter::ParallelBridge;
|
||||
@@ -8,16 +14,12 @@ use rayon::prelude::ParallelIterator;
|
||||
use regex::Regex;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use std::sync::atomic;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
|
||||
use std::collections::HashSet;
|
||||
|
||||
use crate::node::build_node;
|
||||
use std::fs::DirEntry;
|
||||
|
||||
use crate::platform::get_metadata;
|
||||
|
||||
pub struct WalkData<'a> {
|
||||
pub ignore_directories: HashSet<PathBuf>,
|
||||
pub filter_regex: &'a [Regex],
|
||||
@@ -26,22 +28,26 @@ pub struct WalkData<'a> {
|
||||
pub use_apparent_size: bool,
|
||||
pub by_filecount: bool,
|
||||
pub ignore_hidden: bool,
|
||||
pub follow_links: bool,
|
||||
pub progress_data: Arc<PAtomicInfo>,
|
||||
pub errors: Arc<Mutex<RuntimeErrors>>,
|
||||
}
|
||||
|
||||
pub fn walk_it(dirs: HashSet<PathBuf>, walk_data: WalkData) -> (Vec<Node>, bool) {
|
||||
let permissions_flag = AtomicBool::new(false);
|
||||
|
||||
pub fn walk_it(dirs: HashSet<PathBuf>, walk_data: &WalkData) -> Vec<Node> {
|
||||
let mut inodes = HashSet::new();
|
||||
let top_level_nodes: Vec<_> = dirs
|
||||
.into_iter()
|
||||
.filter_map(|d| {
|
||||
clean_inodes(
|
||||
walk(d, &permissions_flag, &walk_data, 0)?,
|
||||
&mut HashSet::new(),
|
||||
walk_data.use_apparent_size,
|
||||
)
|
||||
let prog_data = &walk_data.progress_data;
|
||||
prog_data.clear_state(&d);
|
||||
let node = walk(d, walk_data, 0)?;
|
||||
|
||||
prog_data.state.store(Operation::PREPARING, ORDERING);
|
||||
|
||||
clean_inodes(node, &mut inodes, walk_data.use_apparent_size)
|
||||
})
|
||||
.collect();
|
||||
(top_level_nodes, permissions_flag.into_inner())
|
||||
top_level_nodes
|
||||
}
|
||||
|
||||
// Remove files which have the same inode, we don't want to double count them.
|
||||
@@ -121,57 +127,88 @@ fn ignore_file(entry: &DirEntry, walk_data: &WalkData) -> bool {
|
||||
(is_dot_file && walk_data.ignore_hidden) || is_ignored_path
|
||||
}
|
||||
|
||||
fn walk(
|
||||
dir: PathBuf,
|
||||
permissions_flag: &AtomicBool,
|
||||
walk_data: &WalkData,
|
||||
depth: usize,
|
||||
) -> Option<Node> {
|
||||
let mut children = vec![];
|
||||
|
||||
if let Ok(entries) = fs::read_dir(&dir) {
|
||||
children = entries
|
||||
.into_iter()
|
||||
.par_bridge()
|
||||
.filter_map(|entry| {
|
||||
if let Ok(ref entry) = entry {
|
||||
// uncommenting the below line gives simpler code but
|
||||
// rayon doesn't parallelize as well giving a 3X performance drop
|
||||
// hence we unravel the recursion a bit
|
||||
|
||||
// return walk(entry.path(), permissions_flag, ignore_directories, allowed_filesystems, use_apparent_size, by_filecount, ignore_hidden);
|
||||
|
||||
if !ignore_file(entry, walk_data) {
|
||||
if let Ok(data) = entry.file_type() {
|
||||
return if data.is_dir() && !data.is_symlink() {
|
||||
walk(entry.path(), permissions_flag, walk_data, depth + 1)
|
||||
} else {
|
||||
build_node(
|
||||
entry.path(),
|
||||
vec![],
|
||||
walk_data.filter_regex,
|
||||
walk_data.invert_filter_regex,
|
||||
walk_data.use_apparent_size,
|
||||
data.is_symlink(),
|
||||
data.is_file(),
|
||||
walk_data.by_filecount,
|
||||
depth,
|
||||
)
|
||||
};
|
||||
}
|
||||
}
|
||||
} else {
|
||||
permissions_flag.store(true, atomic::Ordering::Relaxed);
|
||||
}
|
||||
None
|
||||
})
|
||||
.collect();
|
||||
} else {
|
||||
// Handle edge case where dust is called with a file instead of a directory
|
||||
if !dir.exists() {
|
||||
permissions_flag.store(true, atomic::Ordering::Relaxed);
|
||||
}
|
||||
fn walk(dir: PathBuf, walk_data: &WalkData, depth: usize) -> Option<Node> {
|
||||
let prog_data = &walk_data.progress_data;
|
||||
let errors = &walk_data.errors;
|
||||
if errors.lock().unwrap().abort {
|
||||
return None;
|
||||
}
|
||||
|
||||
let children = if dir.is_dir() {
|
||||
let read_dir = fs::read_dir(&dir);
|
||||
match read_dir {
|
||||
Ok(entries) => {
|
||||
entries
|
||||
.into_iter()
|
||||
.par_bridge()
|
||||
.filter_map(|entry| {
|
||||
if let Ok(ref entry) = entry {
|
||||
// uncommenting the below line gives simpler code but
|
||||
// rayon doesn't parallelize as well giving a 3X performance drop
|
||||
// hence we unravel the recursion a bit
|
||||
|
||||
// return walk(entry.path(), walk_data, depth)
|
||||
|
||||
if !ignore_file(entry, walk_data) {
|
||||
if let Ok(data) = entry.file_type() {
|
||||
if data.is_dir()
|
||||
|| (walk_data.follow_links && data.is_symlink())
|
||||
{
|
||||
return walk(entry.path(), walk_data, depth + 1);
|
||||
}
|
||||
|
||||
let node = build_node(
|
||||
entry.path(),
|
||||
vec![],
|
||||
walk_data.filter_regex,
|
||||
walk_data.invert_filter_regex,
|
||||
walk_data.use_apparent_size,
|
||||
data.is_symlink(),
|
||||
data.is_file(),
|
||||
walk_data.by_filecount,
|
||||
depth,
|
||||
);
|
||||
|
||||
prog_data.num_files.fetch_add(1, ORDERING);
|
||||
if let Some(ref file) = node {
|
||||
prog_data.total_file_size.fetch_add(file.size, ORDERING);
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let mut editable_error = errors.lock().unwrap();
|
||||
editable_error.no_permissions = true
|
||||
}
|
||||
None
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
Err(failed) => {
|
||||
let mut editable_error = errors.lock().unwrap();
|
||||
match failed.kind() {
|
||||
std::io::ErrorKind::PermissionDenied => {
|
||||
editable_error.no_permissions = true;
|
||||
}
|
||||
std::io::ErrorKind::NotFound => {
|
||||
editable_error.file_not_found.insert(failed.to_string());
|
||||
}
|
||||
_ => {
|
||||
editable_error.unknown_error.insert(failed.to_string());
|
||||
}
|
||||
}
|
||||
vec![]
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if !dir.is_file() {
|
||||
let mut editable_error = errors.lock().unwrap();
|
||||
let bad_file = dir.as_os_str().to_string_lossy().into();
|
||||
editable_error.file_not_found.insert(bad_file);
|
||||
}
|
||||
vec![]
|
||||
};
|
||||
build_node(
|
||||
dir,
|
||||
children,
|
||||
|
||||
335
src/display.rs
335
src/display.rs
@@ -17,21 +17,27 @@ use thousands::Separable;
|
||||
pub static UNITS: [char; 4] = ['T', 'G', 'M', 'K'];
|
||||
static BLOCKS: [char; 5] = ['█', '▓', '▒', '░', ' '];
|
||||
|
||||
pub struct DisplayData {
|
||||
pub struct InitialDisplayData {
|
||||
pub short_paths: bool,
|
||||
pub is_reversed: bool,
|
||||
pub colors_on: bool,
|
||||
pub by_filecount: bool,
|
||||
pub is_screen_reader: bool,
|
||||
pub output_format: String,
|
||||
pub bars_on_right: bool,
|
||||
}
|
||||
|
||||
pub struct DisplayData {
|
||||
pub initial: InitialDisplayData,
|
||||
pub num_chars_needed_on_left_most: usize,
|
||||
pub base_size: u64,
|
||||
pub longest_string_length: usize,
|
||||
pub ls_colors: LsColors,
|
||||
pub iso: bool,
|
||||
}
|
||||
|
||||
impl DisplayData {
|
||||
fn get_tree_chars(&self, was_i_last: bool, has_children: bool) -> &'static str {
|
||||
match (self.is_reversed, was_i_last, has_children) {
|
||||
match (self.initial.is_reversed, was_i_last, has_children) {
|
||||
(true, true, true) => "┌─┴",
|
||||
(true, true, false) => "┌──",
|
||||
(true, false, true) => "├─┴",
|
||||
@@ -44,7 +50,7 @@ impl DisplayData {
|
||||
}
|
||||
|
||||
fn is_biggest(&self, num_siblings: usize, max_siblings: u64) -> bool {
|
||||
if self.is_reversed {
|
||||
if self.initial.is_reversed {
|
||||
num_siblings == (max_siblings - 1) as usize
|
||||
} else {
|
||||
num_siblings == 0
|
||||
@@ -52,7 +58,7 @@ impl DisplayData {
|
||||
}
|
||||
|
||||
fn is_last(&self, num_siblings: usize, max_siblings: u64) -> bool {
|
||||
if self.is_reversed {
|
||||
if self.initial.is_reversed {
|
||||
num_siblings == 0
|
||||
} else {
|
||||
num_siblings == (max_siblings - 1) as usize
|
||||
@@ -83,14 +89,23 @@ impl DrawData<'_> {
|
||||
|
||||
// TODO: can we test this?
|
||||
fn generate_bar(&self, node: &DisplayNode, level: usize) -> String {
|
||||
if self.display_data.initial.is_screen_reader {
|
||||
return level.to_string();
|
||||
}
|
||||
let chars_in_bar = self.percent_bar.chars().count();
|
||||
let num_bars = chars_in_bar as f32 * self.display_data.percent_size(node);
|
||||
let mut num_not_my_bar = (chars_in_bar as i32) - num_bars as i32;
|
||||
|
||||
let mut new_bar = "".to_string();
|
||||
let idx = 5 - min(4, max(1, level));
|
||||
let idx = 5 - level.clamp(1, 4);
|
||||
|
||||
for c in self.percent_bar.chars() {
|
||||
let itr: Box<dyn Iterator<Item = char>> = if self.display_data.initial.bars_on_right {
|
||||
Box::new(self.percent_bar.chars())
|
||||
} else {
|
||||
Box::new(self.percent_bar.chars().rev())
|
||||
};
|
||||
|
||||
for c in itr {
|
||||
num_not_my_bar -= 1;
|
||||
if num_not_my_bar <= 0 {
|
||||
new_bar.push(BLOCKS[0]);
|
||||
@@ -100,20 +115,19 @@ impl DrawData<'_> {
|
||||
new_bar.push(c);
|
||||
}
|
||||
}
|
||||
new_bar
|
||||
if self.display_data.initial.bars_on_right {
|
||||
new_bar
|
||||
} else {
|
||||
new_bar.chars().rev().collect()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn draw_it(
|
||||
use_full_path: bool,
|
||||
is_reversed: bool,
|
||||
no_colors: bool,
|
||||
idd: InitialDisplayData,
|
||||
no_percent_bars: bool,
|
||||
terminal_width: usize,
|
||||
by_filecount: bool,
|
||||
root_node: &DisplayNode,
|
||||
iso: bool,
|
||||
skip_total: bool,
|
||||
) {
|
||||
let biggest = match skip_total {
|
||||
@@ -124,11 +138,11 @@ pub fn draw_it(
|
||||
.unwrap_or(root_node),
|
||||
};
|
||||
|
||||
let num_chars_needed_on_left_most = if by_filecount {
|
||||
let num_chars_needed_on_left_most = if idd.by_filecount {
|
||||
let max_size = biggest.size;
|
||||
max_size.separate_with_commas().chars().count()
|
||||
} else {
|
||||
find_biggest_size_str(root_node, iso)
|
||||
find_biggest_size_str(root_node, &idd.output_format)
|
||||
};
|
||||
|
||||
assert!(
|
||||
@@ -139,26 +153,22 @@ pub fn draw_it(
|
||||
let allowed_width = terminal_width - num_chars_needed_on_left_most - 2;
|
||||
let num_indent_chars = 3;
|
||||
let longest_string_length =
|
||||
find_longest_dir_name(root_node, num_indent_chars, allowed_width, !use_full_path);
|
||||
find_longest_dir_name(root_node, num_indent_chars, allowed_width, &idd);
|
||||
|
||||
let max_bar_length = if no_percent_bars || longest_string_length + 7 >= allowed_width as usize {
|
||||
let max_bar_length = if no_percent_bars || longest_string_length + 7 >= allowed_width {
|
||||
0
|
||||
} else {
|
||||
allowed_width as usize - longest_string_length - 7
|
||||
allowed_width - longest_string_length - 7
|
||||
};
|
||||
|
||||
let first_size_bar = repeat(BLOCKS[0]).take(max_bar_length).collect();
|
||||
|
||||
let display_data = DisplayData {
|
||||
short_paths: !use_full_path,
|
||||
is_reversed,
|
||||
colors_on: !no_colors,
|
||||
by_filecount,
|
||||
initial: idd,
|
||||
num_chars_needed_on_left_most,
|
||||
base_size: biggest.size,
|
||||
longest_string_length,
|
||||
ls_colors: LsColors::from_env().unwrap_or_default(),
|
||||
iso,
|
||||
};
|
||||
let draw_data = DrawData {
|
||||
indent: "".to_string(),
|
||||
@@ -170,7 +180,7 @@ pub fn draw_it(
|
||||
display_node(root_node, &draw_data, true, true);
|
||||
} else {
|
||||
for (count, c) in root_node
|
||||
.get_children_from_node(draw_data.display_data.is_reversed)
|
||||
.get_children_from_node(draw_data.display_data.initial.is_reversed)
|
||||
.enumerate()
|
||||
{
|
||||
let is_biggest = display_data.is_biggest(count, root_node.num_siblings());
|
||||
@@ -180,10 +190,12 @@ pub fn draw_it(
|
||||
}
|
||||
}
|
||||
|
||||
fn find_biggest_size_str(node: &DisplayNode, iso: bool) -> usize {
|
||||
let mut mx = human_readable_number(node.size, iso).chars().count();
|
||||
fn find_biggest_size_str(node: &DisplayNode, output_format: &str) -> usize {
|
||||
let mut mx = human_readable_number(node.size, output_format)
|
||||
.chars()
|
||||
.count();
|
||||
for n in node.children.iter() {
|
||||
mx = max(mx, find_biggest_size_str(n, iso));
|
||||
mx = max(mx, find_biggest_size_str(n, output_format));
|
||||
}
|
||||
mx
|
||||
}
|
||||
@@ -192,18 +204,23 @@ fn find_longest_dir_name(
|
||||
node: &DisplayNode,
|
||||
indent: usize,
|
||||
terminal: usize,
|
||||
long_paths: bool,
|
||||
idd: &InitialDisplayData,
|
||||
) -> usize {
|
||||
let printable_name = get_printable_name(&node.name, long_paths);
|
||||
let longest = min(
|
||||
UnicodeWidthStr::width(&*printable_name) + 1 + indent,
|
||||
terminal,
|
||||
);
|
||||
let printable_name = get_printable_name(&node.name, idd.short_paths);
|
||||
|
||||
let longest = if idd.is_screen_reader {
|
||||
UnicodeWidthStr::width(&*printable_name) + 1
|
||||
} else {
|
||||
min(
|
||||
UnicodeWidthStr::width(&*printable_name) + 1 + indent,
|
||||
terminal,
|
||||
)
|
||||
};
|
||||
|
||||
// each none root tree drawing is 2 more chars, hence we increment indent by 2
|
||||
node.children
|
||||
.iter()
|
||||
.map(|c| find_longest_dir_name(c, indent + 2, terminal, long_paths))
|
||||
.map(|c| find_longest_dir_name(c, indent + 2, terminal, idd))
|
||||
.fold(longest, max)
|
||||
}
|
||||
|
||||
@@ -215,8 +232,8 @@ fn display_node(node: &DisplayNode, draw_data: &DrawData, is_biggest: bool, is_l
|
||||
|
||||
let to_print = format_string(node, &indent, &bar_text, is_biggest, draw_data.display_data);
|
||||
|
||||
if !draw_data.display_data.is_reversed {
|
||||
println!("{}", to_print)
|
||||
if !draw_data.display_data.initial.is_reversed {
|
||||
println!("{to_print}")
|
||||
}
|
||||
|
||||
let dd = DrawData {
|
||||
@@ -228,7 +245,7 @@ fn display_node(node: &DisplayNode, draw_data: &DrawData, is_biggest: bool, is_l
|
||||
let num_siblings = node.num_siblings();
|
||||
|
||||
for (count, c) in node
|
||||
.get_children_from_node(draw_data.display_data.is_reversed)
|
||||
.get_children_from_node(draw_data.display_data.initial.is_reversed)
|
||||
.enumerate()
|
||||
{
|
||||
let is_biggest = dd.display_data.is_biggest(count, num_siblings);
|
||||
@@ -236,8 +253,8 @@ fn display_node(node: &DisplayNode, draw_data: &DrawData, is_biggest: bool, is_l
|
||||
display_node(c, &dd, is_biggest, was_i_last);
|
||||
}
|
||||
|
||||
if draw_data.display_data.is_reversed {
|
||||
println!("{}", to_print)
|
||||
if draw_data.display_data.initial.is_reversed {
|
||||
println!("{to_print}")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -258,10 +275,10 @@ fn clean_indentation_string(s: &str) -> String {
|
||||
is
|
||||
}
|
||||
|
||||
fn get_printable_name<P: AsRef<Path>>(dir_name: &P, long_paths: bool) -> String {
|
||||
fn get_printable_name<P: AsRef<Path>>(dir_name: &P, short_paths: bool) -> String {
|
||||
let dir_name = dir_name.as_ref();
|
||||
let printable_name = {
|
||||
if long_paths {
|
||||
if short_paths {
|
||||
match dir_name.parent() {
|
||||
Some(prefix) => match dir_name.strip_prefix(prefix) {
|
||||
Ok(base) => base,
|
||||
@@ -277,8 +294,8 @@ fn get_printable_name<P: AsRef<Path>>(dir_name: &P, long_paths: bool) -> String
|
||||
}
|
||||
|
||||
fn pad_or_trim_filename(node: &DisplayNode, indent: &str, display_data: &DisplayData) -> String {
|
||||
let name = get_printable_name(&node.name, display_data.short_paths);
|
||||
let indent_and_name = format!("{} {}", indent, name);
|
||||
let name = get_printable_name(&node.name, display_data.initial.short_paths);
|
||||
let indent_and_name = format!("{indent} {name}");
|
||||
let width = UnicodeWidthStr::width(&*indent_and_name);
|
||||
|
||||
assert!(
|
||||
@@ -314,14 +331,20 @@ fn maybe_trim_filename(name_in: String, indent: &str, display_data: &DisplayData
|
||||
pub fn format_string(
|
||||
node: &DisplayNode,
|
||||
indent: &str,
|
||||
percent_bar: &str,
|
||||
bars: &str,
|
||||
is_biggest: bool,
|
||||
display_data: &DisplayData,
|
||||
) -> String {
|
||||
let (percents, name_and_padding) = get_name_percent(node, indent, percent_bar, display_data);
|
||||
let (percent, name_and_padding) = get_name_percent(node, indent, bars, display_data);
|
||||
let pretty_size = get_pretty_size(node, is_biggest, display_data);
|
||||
let pretty_name = get_pretty_name(node, name_and_padding, display_data);
|
||||
format!("{} {} {}{}", pretty_size, indent, pretty_name, percents)
|
||||
// we can clean this and the method below somehow, not sure yet
|
||||
if display_data.initial.is_screen_reader {
|
||||
// if screen_reader then bars is 'depth'
|
||||
format!("{pretty_name} {bars} {pretty_size}{percent}")
|
||||
} else {
|
||||
format!("{pretty_size} {indent} {pretty_name}{percent}")
|
||||
}
|
||||
}
|
||||
|
||||
fn get_name_percent(
|
||||
@@ -330,28 +353,36 @@ fn get_name_percent(
|
||||
bar_chart: &str,
|
||||
display_data: &DisplayData,
|
||||
) -> (String, String) {
|
||||
if !bar_chart.is_empty() {
|
||||
let percent_size_str = format!("{:.0}%", display_data.percent_size(node) * 100.0);
|
||||
let percents = format!("│{} │ {:>4}", bar_chart, percent_size_str);
|
||||
if display_data.initial.is_screen_reader {
|
||||
let percent = display_data.percent_size(node) * 100.0;
|
||||
let percent_size_str = format!("{percent:.0}%");
|
||||
let percents = format!(" {percent_size_str:>4}",);
|
||||
let name = pad_or_trim_filename(node, "", display_data);
|
||||
(percents, name)
|
||||
// Bar chart being empty may come from either config or the screen not being wide enough
|
||||
} else if !bar_chart.is_empty() {
|
||||
let percent = display_data.percent_size(node) * 100.0;
|
||||
let percent_size_str = format!("{percent:.0}%");
|
||||
let percents = format!("│{bar_chart} │ {percent_size_str:>4}");
|
||||
let name_and_padding = pad_or_trim_filename(node, indent, display_data);
|
||||
(percents, name_and_padding)
|
||||
} else {
|
||||
let n = get_printable_name(&node.name, display_data.short_paths);
|
||||
let n = get_printable_name(&node.name, display_data.initial.short_paths);
|
||||
let name = maybe_trim_filename(n, indent, display_data);
|
||||
("".into(), name)
|
||||
}
|
||||
}
|
||||
|
||||
fn get_pretty_size(node: &DisplayNode, is_biggest: bool, display_data: &DisplayData) -> String {
|
||||
let output = if display_data.by_filecount {
|
||||
let output = if display_data.initial.by_filecount {
|
||||
node.size.separate_with_commas()
|
||||
} else {
|
||||
human_readable_number(node.size, display_data.iso)
|
||||
human_readable_number(node.size, &display_data.initial.output_format)
|
||||
};
|
||||
let spaces_to_add = display_data.num_chars_needed_on_left_most - output.chars().count();
|
||||
let output = " ".repeat(spaces_to_add) + output.as_str();
|
||||
|
||||
if is_biggest && display_data.colors_on {
|
||||
if is_biggest && display_data.initial.colors_on {
|
||||
format!("{}", Red.paint(output))
|
||||
} else {
|
||||
output
|
||||
@@ -363,7 +394,7 @@ fn get_pretty_name(
|
||||
name_and_padding: String,
|
||||
display_data: &DisplayData,
|
||||
) -> String {
|
||||
if display_data.colors_on {
|
||||
if display_data.initial.colors_on {
|
||||
let meta_result = fs::metadata(&node.name);
|
||||
let directory_color = display_data
|
||||
.ls_colors
|
||||
@@ -371,25 +402,55 @@ fn get_pretty_name(
|
||||
let ansi_style = directory_color
|
||||
.map(Style::to_ansi_term_style)
|
||||
.unwrap_or_default();
|
||||
format!("{}", ansi_style.paint(name_and_padding))
|
||||
let out = ansi_style.paint(name_and_padding);
|
||||
format!("{out}")
|
||||
} else {
|
||||
name_and_padding
|
||||
}
|
||||
}
|
||||
|
||||
fn human_readable_number(size: u64, iso: bool) -> String {
|
||||
// If we are working with SI units or not
|
||||
pub fn get_type_of_thousand(output_str: &str) -> u64 {
|
||||
let is_si = output_str.contains('i'); // si, KiB, MiB, etc
|
||||
if is_si {
|
||||
1000
|
||||
} else {
|
||||
1024
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_number_format(output_str: &str) -> Option<(u64, char)> {
|
||||
if output_str.starts_with('b') {
|
||||
return Some((1, 'B'));
|
||||
}
|
||||
for (i, u) in UNITS.iter().enumerate() {
|
||||
let num: u64 = if iso { 1000 } else { 1024 };
|
||||
let marker = num.pow((UNITS.len() - i) as u32);
|
||||
if size >= marker {
|
||||
if size / marker < 10 {
|
||||
return format!("{:.1}{}", (size as f32 / marker as f32), u);
|
||||
} else {
|
||||
return format!("{}{}", (size / marker), u);
|
||||
}
|
||||
if output_str.starts_with((*u).to_ascii_lowercase()) {
|
||||
let marker = get_type_of_thousand(output_str).pow((UNITS.len() - i) as u32);
|
||||
return Some((marker, *u));
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
pub fn human_readable_number(size: u64, output_str: &str) -> String {
|
||||
match get_number_format(output_str) {
|
||||
Some((x, u)) => {
|
||||
format!("{}{}", (size / x), u)
|
||||
}
|
||||
None => {
|
||||
for (i, u) in UNITS.iter().enumerate() {
|
||||
let marker = get_type_of_thousand(output_str).pow((UNITS.len() - i) as u32);
|
||||
if size >= marker {
|
||||
if size / marker < 10 {
|
||||
return format!("{:.1}{}", (size as f32 / marker as f32), u);
|
||||
} else {
|
||||
return format!("{}{}", (size / marker), u);
|
||||
}
|
||||
}
|
||||
}
|
||||
format!("{size}B")
|
||||
}
|
||||
}
|
||||
format!("{}B", size)
|
||||
}
|
||||
|
||||
mod tests {
|
||||
@@ -400,16 +461,21 @@ mod tests {
|
||||
|
||||
#[cfg(test)]
|
||||
fn get_fake_display_data(longest_string_length: usize) -> DisplayData {
|
||||
DisplayData {
|
||||
let initial = InitialDisplayData {
|
||||
short_paths: true,
|
||||
is_reversed: false,
|
||||
colors_on: false,
|
||||
by_filecount: false,
|
||||
is_screen_reader: false,
|
||||
output_format: "".into(),
|
||||
bars_on_right: false,
|
||||
};
|
||||
DisplayData {
|
||||
initial,
|
||||
num_chars_needed_on_left_most: 5,
|
||||
base_size: 1,
|
||||
base_size: 2_u64.pow(12), // 4.0K
|
||||
longest_string_length,
|
||||
ls_colors: LsColors::from_env().unwrap_or_default(),
|
||||
iso: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -423,14 +489,9 @@ mod tests {
|
||||
let indent = "┌─┴";
|
||||
let percent_bar = "";
|
||||
let is_biggest = false;
|
||||
let data = get_fake_display_data(20);
|
||||
|
||||
let s = format_string(
|
||||
&n,
|
||||
indent,
|
||||
percent_bar,
|
||||
is_biggest,
|
||||
&get_fake_display_data(20),
|
||||
);
|
||||
let s = format_string(&n, indent, percent_bar, is_biggest, &data);
|
||||
assert_eq!(s, " 4.0K ┌─┴ short");
|
||||
}
|
||||
|
||||
@@ -446,31 +507,117 @@ mod tests {
|
||||
let percent_bar = "";
|
||||
let is_biggest = false;
|
||||
|
||||
let dd = get_fake_display_data(64);
|
||||
let s = format_string(&n, indent, percent_bar, is_biggest, &dd);
|
||||
let data = get_fake_display_data(64);
|
||||
let s = format_string(&n, indent, percent_bar, is_biggest, &data);
|
||||
assert_eq!(
|
||||
s,
|
||||
" 4.0K ┌─┴ very_long_name_longer_than_the_eighty_character_limit_very_.."
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_str_screen_reader() {
|
||||
let n = DisplayNode {
|
||||
name: PathBuf::from("/short"),
|
||||
size: 2_u64.pow(12), // This is 4.0K
|
||||
children: vec![],
|
||||
};
|
||||
let indent = "";
|
||||
let percent_bar = "3";
|
||||
let is_biggest = false;
|
||||
let mut data = get_fake_display_data(20);
|
||||
data.initial.is_screen_reader = true;
|
||||
|
||||
let s = format_string(&n, indent, percent_bar, is_biggest, &data);
|
||||
assert_eq!(s, "short 3 4.0K 100%");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_human_readable_number() {
|
||||
assert_eq!(human_readable_number(1, false), "1B");
|
||||
assert_eq!(human_readable_number(956, false), "956B");
|
||||
assert_eq!(human_readable_number(1004, false), "1004B");
|
||||
assert_eq!(human_readable_number(1024, false), "1.0K");
|
||||
assert_eq!(human_readable_number(1536, false), "1.5K");
|
||||
assert_eq!(human_readable_number(1024 * 512, false), "512K");
|
||||
assert_eq!(human_readable_number(1024 * 1024, false), "1.0M");
|
||||
assert_eq!(
|
||||
human_readable_number(1024 * 1024 * 1024 - 1, false),
|
||||
"1023M"
|
||||
);
|
||||
assert_eq!(human_readable_number(1024 * 1024 * 1024 * 20, false), "20G");
|
||||
assert_eq!(
|
||||
human_readable_number(1024 * 1024 * 1024 * 1024, false),
|
||||
"1.0T"
|
||||
);
|
||||
assert_eq!(human_readable_number(1, ""), "1B");
|
||||
assert_eq!(human_readable_number(956, ""), "956B");
|
||||
assert_eq!(human_readable_number(1004, ""), "1004B");
|
||||
assert_eq!(human_readable_number(1024, ""), "1.0K");
|
||||
assert_eq!(human_readable_number(1536, ""), "1.5K");
|
||||
assert_eq!(human_readable_number(1024 * 512, ""), "512K");
|
||||
assert_eq!(human_readable_number(1024 * 1024, ""), "1.0M");
|
||||
assert_eq!(human_readable_number(1024 * 1024 * 1024 - 1, ""), "1023M");
|
||||
assert_eq!(human_readable_number(1024 * 1024 * 1024 * 20, ""), "20G");
|
||||
assert_eq!(human_readable_number(1024 * 1024 * 1024 * 1024, ""), "1.0T");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_human_readable_number_si() {
|
||||
assert_eq!(human_readable_number(1024 * 100, ""), "100K");
|
||||
assert_eq!(human_readable_number(1024 * 100, "si"), "102K");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_human_readable_number_kb() {
|
||||
let hrn = human_readable_number;
|
||||
assert_eq!(hrn(1023, "b"), "1023B");
|
||||
assert_eq!(hrn(1000 * 1000, "bytes"), "1000000B");
|
||||
assert_eq!(hrn(1023, "kb"), "0K");
|
||||
assert_eq!(hrn(1023, "kib"), "1K");
|
||||
assert_eq!(hrn(1024, "kb"), "1K");
|
||||
assert_eq!(hrn(1024 * 512, "kb"), "512K");
|
||||
assert_eq!(hrn(1024 * 1024, "kb"), "1024K");
|
||||
assert_eq!(hrn(1024 * 1000 * 1000 * 20, "kb"), "20000000K");
|
||||
assert_eq!(hrn(1024 * 1024 * 1000 * 20, "mb"), "20000M");
|
||||
assert_eq!(hrn(1024 * 1024 * 1024 * 20, "gb"), "20G");
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn build_draw_data<'a>(disp: &'a DisplayData, size: u32) -> (DrawData<'a>, DisplayNode) {
|
||||
let n = DisplayNode {
|
||||
name: PathBuf::from("/short"),
|
||||
size: 2_u64.pow(size),
|
||||
children: vec![],
|
||||
};
|
||||
let first_size_bar = repeat(BLOCKS[0]).take(13).collect();
|
||||
let dd = DrawData {
|
||||
indent: "".into(),
|
||||
percent_bar: first_size_bar,
|
||||
display_data: disp,
|
||||
};
|
||||
(dd, n)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_draw_data() {
|
||||
let disp = &get_fake_display_data(20);
|
||||
let (dd, n) = build_draw_data(disp, 12);
|
||||
let bar = dd.generate_bar(&n, 1);
|
||||
assert_eq!(bar, "█████████████");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_draw_data2() {
|
||||
let disp = &get_fake_display_data(20);
|
||||
let (dd, n) = build_draw_data(disp, 11);
|
||||
let bar = dd.generate_bar(&n, 2);
|
||||
assert_eq!(bar, "███████░░░░░░");
|
||||
}
|
||||
#[test]
|
||||
fn test_draw_data3() {
|
||||
let mut disp = get_fake_display_data(20);
|
||||
let (dd, n) = build_draw_data(&disp, 11);
|
||||
let bar = dd.generate_bar(&n, 3);
|
||||
assert_eq!(bar, "███████▒▒▒▒▒▒");
|
||||
|
||||
disp.initial.bars_on_right = true;
|
||||
let (dd, n) = build_draw_data(&disp, 11);
|
||||
let bar = dd.generate_bar(&n, 3);
|
||||
assert_eq!(bar, "▒▒▒▒▒▒███████")
|
||||
}
|
||||
#[test]
|
||||
fn test_draw_data4() {
|
||||
let disp = &get_fake_display_data(20);
|
||||
let (dd, n) = build_draw_data(disp, 10);
|
||||
// After 4 we have no more levels of shading so 4+ is the same
|
||||
let bar = dd.generate_bar(&n, 4);
|
||||
assert_eq!(bar, "████▓▓▓▓▓▓▓▓▓");
|
||||
let bar = dd.generate_bar(&n, 5);
|
||||
assert_eq!(bar, "████▓▓▓▓▓▓▓▓▓");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ use std::path::PathBuf;
|
||||
pub struct DisplayNode {
|
||||
// Note: the order of fields in important here, for PartialEq and PartialOrd
|
||||
pub size: u64,
|
||||
pub name: PathBuf, //todo: consider moving to a string?
|
||||
pub name: PathBuf,
|
||||
pub children: Vec<DisplayNode>,
|
||||
}
|
||||
|
||||
|
||||
163
src/filter.rs
163
src/filter.rs
@@ -1,87 +1,140 @@
|
||||
use crate::display_node::DisplayNode;
|
||||
use crate::node::Node;
|
||||
use std::collections::BinaryHeap;
|
||||
use std::collections::HashSet;
|
||||
use std::collections::HashMap;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub fn get_biggest(
|
||||
top_level_nodes: Vec<Node>,
|
||||
min_size: Option<usize>,
|
||||
n: usize,
|
||||
depth: usize,
|
||||
using_a_filter: bool,
|
||||
) -> Option<DisplayNode> {
|
||||
pub struct AggregateData {
|
||||
pub min_size: Option<usize>,
|
||||
pub only_dir: bool,
|
||||
pub only_file: bool,
|
||||
pub number_of_lines: usize,
|
||||
pub depth: usize,
|
||||
pub using_a_filter: bool,
|
||||
}
|
||||
|
||||
pub fn get_biggest(top_level_nodes: Vec<Node>, display_data: AggregateData) -> Option<DisplayNode> {
|
||||
if top_level_nodes.is_empty() {
|
||||
// perhaps change this, bring back Error object?
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut heap = BinaryHeap::new();
|
||||
let number_top_level_nodes = top_level_nodes.len();
|
||||
let root = get_new_root(top_level_nodes);
|
||||
let mut allowed_nodes = HashSet::new();
|
||||
let root;
|
||||
|
||||
allowed_nodes.insert(root.name.as_path());
|
||||
heap = add_children(using_a_filter, min_size, &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);
|
||||
}
|
||||
None => break,
|
||||
}
|
||||
}
|
||||
recursive_rebuilder(&allowed_nodes, &root)
|
||||
}
|
||||
|
||||
fn add_children<'a>(
|
||||
using_a_filter: bool,
|
||||
min_size: Option<usize>,
|
||||
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
|
||||
}
|
||||
|
||||
fn get_new_root(top_level_nodes: Vec<Node>) -> Node {
|
||||
if top_level_nodes.len() != 1 {
|
||||
if number_top_level_nodes > 1 {
|
||||
let size = top_level_nodes.iter().map(|node| node.size).sum();
|
||||
Node {
|
||||
root = Node {
|
||||
name: PathBuf::from("(total)"),
|
||||
size,
|
||||
children: top_level_nodes,
|
||||
inode_device: None,
|
||||
depth: 0,
|
||||
}
|
||||
};
|
||||
// Always include the base nodes if we add a 'parent' (total) node
|
||||
heap = always_add_children(&display_data, &root, heap);
|
||||
} else {
|
||||
top_level_nodes.into_iter().next().unwrap()
|
||||
root = top_level_nodes.into_iter().next().unwrap();
|
||||
heap = add_children(&display_data, &root, heap);
|
||||
}
|
||||
|
||||
Some(fill_remaining_lines(heap, &root, display_data))
|
||||
}
|
||||
|
||||
pub fn fill_remaining_lines<'a>(
|
||||
mut heap: BinaryHeap<&'a Node>,
|
||||
root: &'a Node,
|
||||
display_data: AggregateData,
|
||||
) -> DisplayNode {
|
||||
let mut allowed_nodes = HashMap::new();
|
||||
|
||||
while allowed_nodes.len() < display_data.number_of_lines {
|
||||
let line = heap.pop();
|
||||
match line {
|
||||
Some(line) => {
|
||||
if !display_data.only_file || line.children.is_empty() {
|
||||
allowed_nodes.insert(line.name.as_path(), line);
|
||||
}
|
||||
heap = add_children(&display_data, line, heap);
|
||||
}
|
||||
None => break,
|
||||
}
|
||||
}
|
||||
|
||||
if display_data.only_file {
|
||||
flat_rebuilder(allowed_nodes, root)
|
||||
} else {
|
||||
recursive_rebuilder(&allowed_nodes, root)
|
||||
}
|
||||
}
|
||||
|
||||
fn recursive_rebuilder(allowed_nodes: &HashSet<&Path>, current: &Node) -> Option<DisplayNode> {
|
||||
let mut new_children: Vec<_> = current
|
||||
fn add_children<'a>(
|
||||
display_data: &AggregateData,
|
||||
file_or_folder: &'a Node,
|
||||
heap: BinaryHeap<&'a Node>,
|
||||
) -> BinaryHeap<&'a Node> {
|
||||
if display_data.depth > file_or_folder.depth {
|
||||
always_add_children(display_data, file_or_folder, heap)
|
||||
} else {
|
||||
heap
|
||||
}
|
||||
}
|
||||
|
||||
fn always_add_children<'a>(
|
||||
display_data: &AggregateData,
|
||||
file_or_folder: &'a Node,
|
||||
mut heap: BinaryHeap<&'a Node>,
|
||||
) -> BinaryHeap<&'a Node> {
|
||||
heap.extend(
|
||||
file_or_folder
|
||||
.children
|
||||
.iter()
|
||||
.filter(|c| match display_data.min_size {
|
||||
Some(ms) => c.size > ms as u64,
|
||||
None => !display_data.using_a_filter || c.name.is_file() || c.size > 0,
|
||||
})
|
||||
.filter(|c| {
|
||||
if display_data.only_dir {
|
||||
c.name.is_dir()
|
||||
} else {
|
||||
true
|
||||
}
|
||||
}),
|
||||
);
|
||||
heap
|
||||
}
|
||||
|
||||
// Finds children of current, if in allowed_nodes adds them as children to new DisplayNode
|
||||
fn recursive_rebuilder(allowed_nodes: &HashMap<&Path, &Node>, current: &Node) -> DisplayNode {
|
||||
let new_children: Vec<_> = current
|
||||
.children
|
||||
.iter()
|
||||
.filter(|c| allowed_nodes.contains(c.name.as_path()))
|
||||
.filter_map(|c| recursive_rebuilder(allowed_nodes, c))
|
||||
.filter(|c| allowed_nodes.contains_key(c.name.as_path()))
|
||||
.map(|c| recursive_rebuilder(allowed_nodes, c))
|
||||
.collect();
|
||||
|
||||
new_children.sort_by(|lhs, rhs| lhs.cmp(rhs).reverse());
|
||||
build_node(new_children, current)
|
||||
}
|
||||
|
||||
Some(DisplayNode {
|
||||
// Applies all allowed nodes as children to current node
|
||||
fn flat_rebuilder(allowed_nodes: HashMap<&Path, &Node>, current: &Node) -> DisplayNode {
|
||||
let new_children: Vec<DisplayNode> = allowed_nodes
|
||||
.into_values()
|
||||
.map(|v| DisplayNode {
|
||||
name: v.name.clone(),
|
||||
size: v.size,
|
||||
children: vec![],
|
||||
})
|
||||
.collect::<Vec<DisplayNode>>();
|
||||
build_node(new_children, current)
|
||||
}
|
||||
|
||||
fn build_node(mut new_children: Vec<DisplayNode>, current: &Node) -> DisplayNode {
|
||||
new_children.sort_by(|lhs, rhs| lhs.cmp(rhs).reverse());
|
||||
DisplayNode {
|
||||
name: current.name.clone(),
|
||||
size: current.size,
|
||||
children: new_children,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
276
src/main.rs
276
src/main.rs
@@ -7,16 +7,29 @@ mod filter;
|
||||
mod filter_type;
|
||||
mod node;
|
||||
mod platform;
|
||||
mod progress;
|
||||
mod utils;
|
||||
|
||||
use crate::cli::build_cli;
|
||||
use crate::progress::RuntimeErrors;
|
||||
use clap::parser::ValuesRef;
|
||||
use dir_walker::WalkData;
|
||||
use display::InitialDisplayData;
|
||||
use filter::AggregateData;
|
||||
use progress::PIndicator;
|
||||
use regex::Error;
|
||||
use std::collections::HashSet;
|
||||
use std::env;
|
||||
use std::fs::read_to_string;
|
||||
use std::panic;
|
||||
use std::process;
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
use sysinfo::{System, SystemExt};
|
||||
|
||||
use self::display::draw_it;
|
||||
use clap::Values;
|
||||
use config::get_config;
|
||||
use dir_walker::{walk_it, WalkData};
|
||||
use dir_walker::walk_it;
|
||||
use filter::get_biggest;
|
||||
use filter_type::get_all_file_types;
|
||||
use regex::Regex;
|
||||
@@ -29,29 +42,38 @@ use utils::simplify_dir_names;
|
||||
static DEFAULT_NUMBER_OF_LINES: usize = 30;
|
||||
static DEFAULT_TERMINAL_WIDTH: usize = 80;
|
||||
|
||||
fn init_color(no_color: bool) -> bool {
|
||||
fn should_init_color(no_color: bool, force_color: bool) -> bool {
|
||||
if force_color {
|
||||
return true;
|
||||
}
|
||||
if no_color {
|
||||
return false;
|
||||
}
|
||||
// check if NO_COLOR is set
|
||||
// https://no-color.org/
|
||||
if env::var_os("NO_COLOR").is_some() {
|
||||
return false;
|
||||
}
|
||||
if terminal_size().is_none() {
|
||||
// we are not in a terminal, color may not be needed
|
||||
return false;
|
||||
}
|
||||
// we are in a terminal
|
||||
#[cfg(windows)]
|
||||
{
|
||||
// If no color is already set do not print a warning message
|
||||
if no_color {
|
||||
true
|
||||
} else {
|
||||
// Required for windows 10
|
||||
// Fails to resolve for windows 8 so disable color
|
||||
match ansi_term::enable_ansi_support() {
|
||||
Ok(_) => no_color,
|
||||
Err(_) => {
|
||||
eprintln!(
|
||||
"This version of Windows does not support ANSI colors, setting no_color flag"
|
||||
);
|
||||
true
|
||||
}
|
||||
// Required for windows 10
|
||||
// Fails to resolve for windows 8 so disable color
|
||||
match ansi_term::enable_ansi_support() {
|
||||
Ok(_) => true,
|
||||
Err(_) => {
|
||||
eprintln!("This version of Windows does not support ANSI colors");
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
#[cfg(not(windows))]
|
||||
{
|
||||
no_color
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,12 +99,12 @@ fn get_width_of_terminal() -> usize {
|
||||
.unwrap_or(DEFAULT_TERMINAL_WIDTH)
|
||||
}
|
||||
|
||||
fn get_regex_value(maybe_value: Option<Values>) -> Vec<Regex> {
|
||||
fn get_regex_value(maybe_value: Option<ValuesRef<String>>) -> Vec<Regex> {
|
||||
maybe_value
|
||||
.unwrap_or_default()
|
||||
.map(|reg| {
|
||||
Regex::new(reg).unwrap_or_else(|err| {
|
||||
eprintln!("Ignoring bad value for regex {:?}", err);
|
||||
eprintln!("Ignoring bad value for regex {err:?}");
|
||||
process::exit(1)
|
||||
})
|
||||
})
|
||||
@@ -93,48 +115,82 @@ fn main() {
|
||||
let options = build_cli().get_matches();
|
||||
let config = get_config();
|
||||
|
||||
let target_dirs = options
|
||||
.values_of("inputs")
|
||||
.expect("Should be a default value here")
|
||||
.collect();
|
||||
let errors = RuntimeErrors::default();
|
||||
let error_listen_for_ctrlc = Arc::new(Mutex::new(errors));
|
||||
let errors_for_rayon = error_listen_for_ctrlc.clone();
|
||||
let errors_final = error_listen_for_ctrlc.clone();
|
||||
|
||||
let summarize_file_types = options.is_present("types");
|
||||
ctrlc::set_handler(move || {
|
||||
error_listen_for_ctrlc.lock().unwrap().abort = true;
|
||||
println!("\nAborting");
|
||||
})
|
||||
.expect("Error setting Ctrl-C handler");
|
||||
|
||||
let filter_regexs = get_regex_value(options.values_of("filter"));
|
||||
let invert_filter_regexs = get_regex_value(options.values_of("invert_filter"));
|
||||
let target_dirs = match options.get_many::<String>("params") {
|
||||
Some(values) => values.map(|v| v.as_str()).collect::<Vec<&str>>(),
|
||||
None => vec!["."],
|
||||
};
|
||||
|
||||
let terminal_width = options
|
||||
.value_of_t("width")
|
||||
.unwrap_or_else(|_| get_width_of_terminal());
|
||||
let summarize_file_types = options.get_flag("types");
|
||||
|
||||
let depth = options.value_of_t("depth").unwrap_or(usize::MAX);
|
||||
let filter_regexs = get_regex_value(options.get_many("filter"));
|
||||
let invert_filter_regexs = get_regex_value(options.get_many("invert_filter"));
|
||||
|
||||
let terminal_width: usize = match options.get_one::<usize>("width") {
|
||||
Some(&val) => val,
|
||||
None => get_width_of_terminal(),
|
||||
};
|
||||
|
||||
let depth = config.get_depth(&options);
|
||||
|
||||
// If depth is set, then we set the default number_of_lines to be max
|
||||
// instead of screen height
|
||||
let default_height = if depth != usize::MAX {
|
||||
usize::MAX
|
||||
} else {
|
||||
get_height_of_terminal()
|
||||
|
||||
let number_of_lines = match options.get_one::<usize>("number_of_lines") {
|
||||
Some(&val) => val,
|
||||
None => {
|
||||
if depth != usize::MAX {
|
||||
usize::MAX
|
||||
} else {
|
||||
get_height_of_terminal()
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let number_of_lines = options
|
||||
.value_of("number_of_lines")
|
||||
.and_then(|v| {
|
||||
v.parse()
|
||||
.map_err(|_| eprintln!("Ignoring bad value for number_of_lines"))
|
||||
.ok()
|
||||
})
|
||||
.unwrap_or(default_height);
|
||||
let is_colors = should_init_color(
|
||||
config.get_no_colors(&options),
|
||||
config.get_force_colors(&options),
|
||||
);
|
||||
|
||||
let no_colors = init_color(config.get_no_colors(&options));
|
||||
let ignore_directories = match options.get_many::<String>("ignore_directory") {
|
||||
Some(values) => values
|
||||
.map(|v| v.as_str())
|
||||
.map(PathBuf::from)
|
||||
.collect::<Vec<PathBuf>>(),
|
||||
None => vec![],
|
||||
};
|
||||
|
||||
let ignore_directories = options
|
||||
.values_of("ignore_directory")
|
||||
.unwrap_or_default()
|
||||
.map(PathBuf::from);
|
||||
let ignore_from_file_result = match options.get_one::<String>("ignore_all_in_file") {
|
||||
Some(val) => read_to_string(val)
|
||||
.unwrap()
|
||||
.lines()
|
||||
.map(Regex::new)
|
||||
.collect::<Vec<Result<Regex, Error>>>(),
|
||||
None => vec![],
|
||||
};
|
||||
let ignore_from_file = ignore_from_file_result
|
||||
.into_iter()
|
||||
.filter_map(|x| x.ok())
|
||||
.collect::<Vec<Regex>>();
|
||||
|
||||
let by_filecount = options.is_present("by_filecount");
|
||||
let limit_filesystem = options.is_present("limit_filesystem");
|
||||
let invert_filter_regexs = invert_filter_regexs
|
||||
.into_iter()
|
||||
.chain(ignore_from_file)
|
||||
.collect::<Vec<Regex>>();
|
||||
|
||||
let by_filecount = options.get_flag("by_filecount");
|
||||
let limit_filesystem = options.get_flag("limit_filesystem");
|
||||
let follow_links = options.get_flag("dereference_links");
|
||||
|
||||
let simplified_dirs = simplify_dir_names(target_dirs);
|
||||
let allowed_filesystems = limit_filesystem
|
||||
@@ -142,9 +198,19 @@ fn main() {
|
||||
.unwrap_or_default();
|
||||
|
||||
let ignored_full_path: HashSet<PathBuf> = ignore_directories
|
||||
.into_iter()
|
||||
.flat_map(|x| simplified_dirs.iter().map(move |d| d.join(&x)))
|
||||
.collect();
|
||||
|
||||
let output_format = config.get_output_format(&options);
|
||||
|
||||
let ignore_hidden = config.get_ignore_hidden(&options);
|
||||
|
||||
let mut indicator = PIndicator::build_me();
|
||||
if !config.get_disable_progress(&options) {
|
||||
indicator.spawn(output_format.clone())
|
||||
}
|
||||
|
||||
let walk_data = WalkData {
|
||||
ignore_directories: ignored_full_path,
|
||||
filter_regex: &filter_regexs,
|
||||
@@ -152,42 +218,110 @@ fn main() {
|
||||
allowed_filesystems,
|
||||
use_apparent_size: config.get_apparent_size(&options),
|
||||
by_filecount,
|
||||
ignore_hidden: config.get_ignore_hidden(&options),
|
||||
ignore_hidden,
|
||||
follow_links,
|
||||
progress_data: indicator.data.clone(),
|
||||
errors: errors_for_rayon,
|
||||
};
|
||||
// Larger stack size to handle cases with lots of nested directories
|
||||
rayon::ThreadPoolBuilder::new()
|
||||
.stack_size(usize::pow(1024, 3))
|
||||
.build_global()
|
||||
.unwrap();
|
||||
let stack_size = config.get_custom_stack_size(&options);
|
||||
init_rayon(&stack_size);
|
||||
|
||||
let iso = config.get_iso(&options);
|
||||
let (top_level_nodes, has_errors) = walk_it(simplified_dirs, walk_data);
|
||||
let top_level_nodes = walk_it(simplified_dirs, &walk_data);
|
||||
|
||||
let tree = match summarize_file_types {
|
||||
true => get_all_file_types(&top_level_nodes, number_of_lines),
|
||||
false => get_biggest(
|
||||
top_level_nodes,
|
||||
config.get_min_size(&options, iso),
|
||||
number_of_lines,
|
||||
depth,
|
||||
options.values_of("filter").is_some() || options.value_of("invert_filter").is_some(),
|
||||
),
|
||||
false => {
|
||||
let agg_data = AggregateData {
|
||||
min_size: config.get_min_size(&options),
|
||||
only_dir: config.get_only_dir(&options),
|
||||
only_file: config.get_only_file(&options),
|
||||
number_of_lines,
|
||||
depth,
|
||||
using_a_filter: !filter_regexs.is_empty() || !invert_filter_regexs.is_empty(),
|
||||
};
|
||||
get_biggest(top_level_nodes, agg_data)
|
||||
}
|
||||
};
|
||||
|
||||
if has_errors {
|
||||
// Must have stopped indicator before we print to stderr
|
||||
indicator.stop();
|
||||
|
||||
if errors_final.lock().unwrap().abort {
|
||||
return;
|
||||
}
|
||||
|
||||
let final_errors = walk_data.errors.lock().unwrap();
|
||||
let failed_permissions = final_errors.no_permissions;
|
||||
if !final_errors.file_not_found.is_empty() {
|
||||
let err = final_errors
|
||||
.file_not_found
|
||||
.iter()
|
||||
.map(|a| a.as_ref())
|
||||
.collect::<Vec<&str>>()
|
||||
.join(", ");
|
||||
eprintln!("No such file or directory: {}", err);
|
||||
}
|
||||
if failed_permissions {
|
||||
eprintln!("Did not have permissions for all directories");
|
||||
}
|
||||
if !final_errors.unknown_error.is_empty() {
|
||||
let err = final_errors
|
||||
.unknown_error
|
||||
.iter()
|
||||
.map(|a| a.as_ref())
|
||||
.collect::<Vec<&str>>()
|
||||
.join(", ");
|
||||
eprintln!("Unknown Error: {}", err);
|
||||
}
|
||||
|
||||
if let Some(root_node) = tree {
|
||||
let idd = InitialDisplayData {
|
||||
short_paths: !config.get_full_paths(&options),
|
||||
is_reversed: !config.get_reverse(&options),
|
||||
colors_on: is_colors,
|
||||
by_filecount,
|
||||
is_screen_reader: config.get_screen_reader(&options),
|
||||
output_format,
|
||||
bars_on_right: config.get_bars_on_right(&options),
|
||||
};
|
||||
draw_it(
|
||||
config.get_full_paths(&options),
|
||||
!config.get_reverse(&options),
|
||||
no_colors,
|
||||
idd,
|
||||
config.get_no_bars(&options),
|
||||
terminal_width,
|
||||
by_filecount,
|
||||
&root_node,
|
||||
iso,
|
||||
config.get_skip_total(&options),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn init_rayon(stack_size: &Option<usize>) {
|
||||
// Rayon seems to raise this error on 32-bit builds
|
||||
// The global thread pool has not been initialized.: ThreadPoolBuildError { kind: GlobalPoolAlreadyInitialized }
|
||||
if cfg!(target_pointer_width = "64") {
|
||||
let result = panic::catch_unwind(|| {
|
||||
match stack_size {
|
||||
Some(n) => rayon::ThreadPoolBuilder::new()
|
||||
.stack_size(*n)
|
||||
.build_global(),
|
||||
None => {
|
||||
let large_stack = usize::pow(1024, 3);
|
||||
let mut s = System::new();
|
||||
s.refresh_memory();
|
||||
let available = s.available_memory();
|
||||
|
||||
if available > large_stack.try_into().unwrap() {
|
||||
// Larger stack size to handle cases with lots of nested directories
|
||||
rayon::ThreadPoolBuilder::new()
|
||||
.stack_size(large_stack)
|
||||
.build_global()
|
||||
} else {
|
||||
rayon::ThreadPoolBuilder::new().build_global()
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
if result.is_err() {
|
||||
eprintln!("Problem initializing rayon, try: export RAYON_NUM_THREADS=1")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ pub fn get_metadata(d: &Path, use_apparent_size: bool) -> Option<(u64, Option<(u
|
||||
}
|
||||
|
||||
#[cfg(target_family = "windows")]
|
||||
pub fn get_metadata(d: &Path, _use_apparent_size: bool) -> Option<(u64, Option<(u64, u64)>)> {
|
||||
pub fn get_metadata(d: &Path, use_apparent_size: bool) -> Option<(u64, Option<(u64, u64)>)> {
|
||||
// On windows opening the file to get size, file ID and volume can be very
|
||||
// expensive because 1) it causes a few system calls, and more importantly 2) it can cause
|
||||
// windows defender to scan the file.
|
||||
@@ -90,16 +90,27 @@ pub fn get_metadata(d: &Path, _use_apparent_size: bool) -> Option<(u64, Option<(
|
||||
Ok(Handle::from_file(file))
|
||||
}
|
||||
|
||||
fn get_metadata_expensive(d: &Path) -> Option<(u64, Option<(u64, u64)>)> {
|
||||
fn get_metadata_expensive(
|
||||
d: &Path,
|
||||
use_apparent_size: bool,
|
||||
) -> Option<(u64, Option<(u64, u64)>)> {
|
||||
use winapi_util::file::information;
|
||||
|
||||
let h = handle_from_path_limited(d).ok()?;
|
||||
let info = information(&h).ok()?;
|
||||
|
||||
Some((
|
||||
info.file_size(),
|
||||
Some((info.file_index(), info.volume_serial_number())),
|
||||
))
|
||||
if use_apparent_size {
|
||||
use filesize::PathExt;
|
||||
Some((
|
||||
d.size_on_disk().ok()?,
|
||||
Some((info.file_index(), info.volume_serial_number())),
|
||||
))
|
||||
} else {
|
||||
Some((
|
||||
info.file_size(),
|
||||
Some((info.file_index(), info.volume_serial_number())),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
use std::os::windows::fs::MetadataExt;
|
||||
@@ -111,18 +122,31 @@ pub fn get_metadata(d: &Path, _use_apparent_size: bool) -> Option<(u64, Option<(
|
||||
const FILE_ATTRIBUTE_SYSTEM: u32 = 0x04;
|
||||
const FILE_ATTRIBUTE_NORMAL: u32 = 0x80;
|
||||
const FILE_ATTRIBUTE_DIRECTORY: u32 = 0x10;
|
||||
|
||||
const FILE_ATTRIBUTE_SPARSE_FILE: u32 = 0x00000200;
|
||||
const FILE_ATTRIBUTE_PINNED: u32 = 0x00080000;
|
||||
const FILE_ATTRIBUTE_UNPINNED: u32 = 0x00100000;
|
||||
const FILE_ATTRIBUTE_RECALL_ON_OPEN: u32 = 0x00040000;
|
||||
const FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS: u32 = 0x00400000;
|
||||
const FILE_ATTRIBUTE_OFFLINE: u32 = 0x00001000;
|
||||
// normally FILE_ATTRIBUTE_SPARSE_FILE would be enough, however Windows sometimes likes to mask it out. see: https://stackoverflow.com/q/54560454
|
||||
const IS_PROBABLY_ONEDRIVE: u32 = FILE_ATTRIBUTE_SPARSE_FILE
|
||||
| FILE_ATTRIBUTE_PINNED
|
||||
| FILE_ATTRIBUTE_UNPINNED
|
||||
| FILE_ATTRIBUTE_RECALL_ON_OPEN
|
||||
| FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS
|
||||
| FILE_ATTRIBUTE_OFFLINE;
|
||||
let attr_filtered = md.file_attributes()
|
||||
& !(FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM);
|
||||
if (attr_filtered & FILE_ATTRIBUTE_ARCHIVE) != 0
|
||||
if ((attr_filtered & FILE_ATTRIBUTE_ARCHIVE) != 0
|
||||
|| (attr_filtered & FILE_ATTRIBUTE_DIRECTORY) != 0
|
||||
|| md.file_attributes() == FILE_ATTRIBUTE_NORMAL
|
||||
|| md.file_attributes() == FILE_ATTRIBUTE_NORMAL)
|
||||
&& !((attr_filtered & IS_PROBABLY_ONEDRIVE != 0) && use_apparent_size)
|
||||
{
|
||||
Some((md.len(), None))
|
||||
} else {
|
||||
get_metadata_expensive(d)
|
||||
get_metadata_expensive(d, use_apparent_size)
|
||||
}
|
||||
}
|
||||
_ => get_metadata_expensive(d),
|
||||
_ => get_metadata_expensive(d, use_apparent_size),
|
||||
}
|
||||
}
|
||||
|
||||
153
src/progress.rs
Normal file
153
src/progress.rs
Normal file
@@ -0,0 +1,153 @@
|
||||
use std::{
|
||||
collections::HashSet,
|
||||
io::Write,
|
||||
path::Path,
|
||||
sync::{
|
||||
atomic::{AtomicU64, AtomicU8, AtomicUsize, Ordering},
|
||||
mpsc::{self, RecvTimeoutError, Sender},
|
||||
Arc, RwLock,
|
||||
},
|
||||
thread::JoinHandle,
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use crate::display::human_readable_number;
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
pub const ORDERING: Ordering = Ordering::Relaxed;
|
||||
|
||||
const SPINNER_SLEEP_TIME: u64 = 100;
|
||||
const PROGRESS_CHARS: [char; 4] = ['-', '\\', '|', '/'];
|
||||
const PROGRESS_CHARS_LEN: usize = PROGRESS_CHARS.len();
|
||||
|
||||
pub trait ThreadSyncTrait<T> {
|
||||
fn set(&self, val: T);
|
||||
fn get(&self) -> T;
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct ThreadStringWrapper {
|
||||
inner: RwLock<String>,
|
||||
}
|
||||
|
||||
impl ThreadSyncTrait<String> for ThreadStringWrapper {
|
||||
fn set(&self, val: String) {
|
||||
*self.inner.write().unwrap() = val;
|
||||
}
|
||||
|
||||
fn get(&self) -> String {
|
||||
(*self.inner.read().unwrap()).clone()
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
// creating an enum this way allows to have simpler syntax compared to a Mutex or a RwLock
|
||||
#[allow(non_snake_case)]
|
||||
pub mod Operation {
|
||||
pub const INDEXING: u8 = 0;
|
||||
pub const PREPARING: u8 = 1;
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct PAtomicInfo {
|
||||
pub num_files: AtomicUsize,
|
||||
pub total_file_size: AtomicU64,
|
||||
pub state: AtomicU8,
|
||||
pub current_path: ThreadStringWrapper,
|
||||
}
|
||||
|
||||
impl PAtomicInfo {
|
||||
pub fn clear_state(&self, dir: &Path) {
|
||||
self.state.store(Operation::INDEXING, ORDERING);
|
||||
let dir_name = dir.to_string_lossy().to_string();
|
||||
self.current_path.set(dir_name);
|
||||
self.total_file_size.store(0, ORDERING);
|
||||
self.num_files.store(0, ORDERING);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct RuntimeErrors {
|
||||
pub no_permissions: bool,
|
||||
pub file_not_found: HashSet<String>,
|
||||
pub unknown_error: HashSet<String>,
|
||||
pub abort: bool,
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
fn format_preparing_str(prog_char: char, data: &PAtomicInfo, output_display: &str) -> String {
|
||||
let path_in = data.current_path.get();
|
||||
let size = human_readable_number(data.total_file_size.load(ORDERING), output_display);
|
||||
format!("Preparing: {path_in} {size} ... {prog_char}")
|
||||
}
|
||||
|
||||
fn format_indexing_str(prog_char: char, data: &PAtomicInfo, output_display: &str) -> String {
|
||||
let path_in = data.current_path.get();
|
||||
let file_count = data.num_files.load(ORDERING);
|
||||
let size = human_readable_number(data.total_file_size.load(ORDERING), output_display);
|
||||
let file_str = format!("{file_count} files, {size}");
|
||||
format!("Indexing: {path_in} {file_str} ... {prog_char}")
|
||||
}
|
||||
|
||||
pub struct PIndicator {
|
||||
pub thread: Option<(Sender<()>, JoinHandle<()>)>,
|
||||
pub data: Arc<PAtomicInfo>,
|
||||
}
|
||||
|
||||
impl PIndicator {
|
||||
pub fn build_me() -> Self {
|
||||
Self {
|
||||
thread: None,
|
||||
data: Arc::new(PAtomicInfo {
|
||||
..Default::default()
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn spawn(&mut self, output_display: String) {
|
||||
let data = self.data.clone();
|
||||
let (stop_handler, receiver) = mpsc::channel::<()>();
|
||||
|
||||
let time_info_thread = std::thread::spawn(move || {
|
||||
let mut progress_char_i: usize = 0;
|
||||
let mut stdout = std::io::stdout();
|
||||
let mut msg = "".to_string();
|
||||
|
||||
// While the timeout triggers we go round the loop
|
||||
// If we disconnect or the sender sends its message we exit the while loop
|
||||
while let Err(RecvTimeoutError::Timeout) =
|
||||
receiver.recv_timeout(Duration::from_millis(SPINNER_SLEEP_TIME))
|
||||
{
|
||||
// Clear the text written by 'write!'& Return at the start of line
|
||||
print!("\r{:width$}", " ", width = msg.len());
|
||||
let prog_char = PROGRESS_CHARS[progress_char_i];
|
||||
|
||||
msg = match data.state.load(ORDERING) {
|
||||
Operation::INDEXING => format_indexing_str(prog_char, &data, &output_display),
|
||||
Operation::PREPARING => format_preparing_str(prog_char, &data, &output_display),
|
||||
_ => panic!("Unknown State"),
|
||||
};
|
||||
|
||||
write!(stdout, "\r{msg}").unwrap();
|
||||
stdout.flush().unwrap();
|
||||
|
||||
progress_char_i += 1;
|
||||
progress_char_i %= PROGRESS_CHARS_LEN;
|
||||
}
|
||||
print!("\r{:width$}", " ", width = msg.len());
|
||||
print!("\r");
|
||||
stdout.flush().unwrap();
|
||||
});
|
||||
self.thread = Some((stop_handler, time_info_thread))
|
||||
}
|
||||
|
||||
pub fn stop(self) {
|
||||
if let Some((stop_handler, thread)) = self.thread {
|
||||
stop_handler.send(()).unwrap();
|
||||
thread.join().unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1 +1,2 @@
|
||||
hi
|
||||
something
|
||||
.secret
|
||||
|
||||
0
tests/test_dir_hidden_entries/.secret
Normal file
0
tests/test_dir_hidden_entries/.secret
Normal file
@@ -52,7 +52,15 @@ fn exact_output_test<T: AsRef<OsStr>>(valid_outputs: Vec<String>, command_args:
|
||||
|
||||
let output = str::from_utf8(&a.unwrap().stdout).unwrap().to_owned();
|
||||
|
||||
assert!(valid_outputs.iter().any(|i| output.contains(i)));
|
||||
let will_fail = valid_outputs.iter().any(|i| output.contains(i));
|
||||
if !will_fail {
|
||||
eprintln!(
|
||||
"output:\n{}\ndoes not contain any of:\n{}",
|
||||
output,
|
||||
valid_outputs.join("\n\n")
|
||||
);
|
||||
}
|
||||
assert!(will_fail)
|
||||
}
|
||||
|
||||
// "windows" result data can vary by host (size seems to be variable by one byte); fix code vs test and re-enable
|
||||
@@ -60,7 +68,7 @@ fn exact_output_test<T: AsRef<OsStr>>(valid_outputs: Vec<String>, command_args:
|
||||
#[test]
|
||||
pub fn test_main_basic() {
|
||||
// -c is no color mode - This makes testing much simpler
|
||||
exact_output_test(main_output(), vec!["-c", "/tmp/test_dir/"])
|
||||
exact_output_test(main_output(), vec!["-c", "-B", "/tmp/test_dir/"])
|
||||
}
|
||||
|
||||
#[cfg_attr(target_os = "windows", ignore)]
|
||||
@@ -68,6 +76,7 @@ pub fn test_main_basic() {
|
||||
pub fn test_main_multi_arg() {
|
||||
let command_args = vec![
|
||||
"-c",
|
||||
"-B",
|
||||
"/tmp/test_dir/many/",
|
||||
"/tmp/test_dir",
|
||||
"/tmp/test_dir",
|
||||
@@ -102,7 +111,7 @@ fn main_output() -> Vec<String> {
|
||||
#[cfg_attr(target_os = "windows", ignore)]
|
||||
#[test]
|
||||
pub fn test_main_long_paths() {
|
||||
let command_args = vec!["-c", "-p", "/tmp/test_dir/"];
|
||||
let command_args = vec!["-c", "-p", "-B", "/tmp/test_dir/"];
|
||||
exact_output_test(main_output_long_paths(), command_args);
|
||||
}
|
||||
|
||||
@@ -130,7 +139,7 @@ fn main_output_long_paths() -> Vec<String> {
|
||||
#[cfg_attr(target_os = "windows", ignore)]
|
||||
#[test]
|
||||
pub fn test_substring_of_names_and_long_names() {
|
||||
let command_args = vec!["-c", "/tmp/test_dir2"];
|
||||
let command_args = vec!["-c", "-B", "/tmp/test_dir2"];
|
||||
exact_output_test(no_substring_of_names_output(), command_args);
|
||||
}
|
||||
|
||||
@@ -164,7 +173,7 @@ fn no_substring_of_names_output() -> Vec<String> {
|
||||
#[cfg_attr(target_os = "windows", ignore)]
|
||||
#[test]
|
||||
pub fn test_unicode_directories() {
|
||||
let command_args = vec!["-c", "/tmp/test_dir_unicode"];
|
||||
let command_args = vec!["-c", "-B", "/tmp/test_dir_unicode"];
|
||||
exact_output_test(unicode_dir(), command_args);
|
||||
}
|
||||
|
||||
@@ -197,12 +206,19 @@ pub fn test_apparent_size() {
|
||||
|
||||
fn apparent_size_output() -> Vec<String> {
|
||||
// The apparent directory sizes are too unpredictable and system dependent to try and match
|
||||
let files = r#"
|
||||
let one_space_before = r#"
|
||||
0B ┌── a_file
|
||||
6B ├── hello_file
|
||||
"#
|
||||
.trim()
|
||||
.to_string();
|
||||
|
||||
let two_space_before = r#"
|
||||
0B ┌── a_file
|
||||
6B ├── hello_file
|
||||
"#
|
||||
.trim()
|
||||
.to_string();
|
||||
|
||||
vec![files]
|
||||
vec![one_space_before, two_space_before]
|
||||
}
|
||||
|
||||
@@ -64,6 +64,7 @@ pub fn test_d_flag_works_and_still_recurses_down() {
|
||||
// We had a bug where running with '-d 1' would stop at the first directory and the code
|
||||
// would fail to recurse down
|
||||
let output = build_command(vec!["-d", "1", "-f", "-c", "tests/test_dir2/"]);
|
||||
assert!(output.contains("1 ┌── dir"));
|
||||
assert!(output.contains("4 ┌─┴ test_dir2"));
|
||||
}
|
||||
|
||||
@@ -74,12 +75,24 @@ pub fn test_ignore_dir() {
|
||||
assert!(!output.contains("dir_substring"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_ignore_all_in_file() {
|
||||
let output = build_command(vec![
|
||||
"-c",
|
||||
"-I",
|
||||
"tests/test_dir_hidden_entries/.hidden_file",
|
||||
"tests/test_dir_hidden_entries/",
|
||||
]);
|
||||
assert!(output.contains(" test_dir_hidden_entries"));
|
||||
assert!(!output.contains(".secret"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_with_bad_param() {
|
||||
let mut cmd = Command::cargo_bin("dust").unwrap();
|
||||
let result = cmd.arg("bad_place").unwrap();
|
||||
let stderr = str::from_utf8(&result.stderr).unwrap();
|
||||
assert!(stderr.contains("Did not have permissions for all directories"));
|
||||
assert!(stderr.contains("No such file or directory"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -116,6 +129,15 @@ pub fn test_show_files_by_type() {
|
||||
assert!(output.contains("┌─┴ (total)"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(target_family = "unix")]
|
||||
pub fn test_show_files_only() {
|
||||
let output = build_command(vec!["-c", "-F", "tests/test_dir"]);
|
||||
assert!(output.contains("tests/test_dir/many/a_file"));
|
||||
assert!(output.contains("tests/test_dir/many/hello_file"));
|
||||
assert!(!output.contains("tests/test_dir/many "));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_output_skip_total() {
|
||||
let output = build_command(vec![
|
||||
@@ -127,6 +149,23 @@ pub fn test_output_skip_total() {
|
||||
assert!(!output.contains("(total)"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_output_screen_reader() {
|
||||
let output = build_command(vec!["--screen-reader", "-c", "tests/test_dir/"]);
|
||||
println!("{}", output);
|
||||
assert!(output.contains("test_dir 0"));
|
||||
assert!(output.contains("many 1"));
|
||||
assert!(output.contains("hello_file 2"));
|
||||
assert!(output.contains("a_file 2"));
|
||||
|
||||
// Verify no 'symbols' reported by screen reader
|
||||
assert!(!output.contains('│'));
|
||||
|
||||
for block in ['█', '▓', '▒', '░'] {
|
||||
assert!(!output.contains(block));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_show_files_by_regex_match_lots() {
|
||||
// Check we can see '.rs' files in the tests directory
|
||||
@@ -193,3 +232,19 @@ pub fn test_show_files_by_invert_regex_match_multiple() {
|
||||
assert!(!output.contains("test_dir_unicode"));
|
||||
assert!(output.contains("many"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_no_color() {
|
||||
let output = build_command(vec!["-c"]);
|
||||
// Red is 31
|
||||
assert!(!output.contains("\x1B[31m"));
|
||||
assert!(!output.contains("\x1B[0m"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_force_color() {
|
||||
let output = build_command(vec!["-C"]);
|
||||
// Red is 31
|
||||
assert!(output.contains("\x1B[31m"));
|
||||
assert!(output.contains("\x1B[0m"));
|
||||
}
|
||||
|
||||
@@ -17,6 +17,18 @@ fn build_temp_file(dir: &TempDir) -> PathBuf {
|
||||
file_path
|
||||
}
|
||||
|
||||
fn link_it(link_path: PathBuf, file_path_s: &str, is_soft: bool) -> String {
|
||||
let link_name_s = link_path.to_str().unwrap();
|
||||
let mut c = Command::new("ln");
|
||||
if is_soft {
|
||||
c.arg("-s");
|
||||
}
|
||||
c.arg(file_path_s);
|
||||
c.arg(link_name_s);
|
||||
assert!(c.output().is_ok());
|
||||
link_name_s.into()
|
||||
}
|
||||
|
||||
#[cfg_attr(target_os = "windows", ignore)]
|
||||
#[test]
|
||||
pub fn test_soft_sym_link() {
|
||||
@@ -26,13 +38,7 @@ pub fn test_soft_sym_link() {
|
||||
let file_path_s = file.to_str().unwrap();
|
||||
|
||||
let link_name = dir.path().join("the_link");
|
||||
let link_name_s = link_name.to_str().unwrap();
|
||||
let c = Command::new("ln")
|
||||
.arg("-s")
|
||||
.arg(file_path_s)
|
||||
.arg(link_name_s)
|
||||
.output();
|
||||
assert!(c.is_ok());
|
||||
let link_name_s = link_it(link_name, file_path_s, true);
|
||||
|
||||
let c = format!(" ├── {}", link_name_s);
|
||||
let b = format!(" ┌── {}", file_path_s);
|
||||
@@ -41,7 +47,7 @@ pub fn test_soft_sym_link() {
|
||||
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])
|
||||
.args(["-p", "-c", "-s", "-w", "999", dir_s])
|
||||
.unwrap()
|
||||
.stdout;
|
||||
|
||||
@@ -61,19 +67,14 @@ pub fn test_hard_sym_link() {
|
||||
let file_path_s = file.to_str().unwrap();
|
||||
|
||||
let link_name = dir.path().join("the_link");
|
||||
let link_name_s = link_name.to_str().unwrap();
|
||||
let c = Command::new("ln")
|
||||
.arg(file_path_s)
|
||||
.arg(link_name_s)
|
||||
.output();
|
||||
assert!(c.is_ok());
|
||||
link_it(link_name, file_path_s, false);
|
||||
|
||||
let file_output = format!(" ┌── {}", file_path_s);
|
||||
let dirs_output = format!("─┴ {}", dir_s);
|
||||
|
||||
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;
|
||||
let output = cmd.args(["-p", "-c", "-w", "999", dir_s]).unwrap().stdout;
|
||||
|
||||
// The link should not appear in the output because multiple inodes are now ordered
|
||||
// then filtered.
|
||||
@@ -82,6 +83,34 @@ pub fn test_hard_sym_link() {
|
||||
assert!(output.contains(file_output.as_str()));
|
||||
}
|
||||
|
||||
#[cfg_attr(target_os = "windows", ignore)]
|
||||
#[test]
|
||||
pub fn test_hard_sym_link_no_dup_multi_arg() {
|
||||
let dir = Builder::new().tempdir().unwrap();
|
||||
let dir_link = Builder::new().tempdir().unwrap();
|
||||
let file = build_temp_file(&dir);
|
||||
let dir_s = dir.path().to_str().unwrap();
|
||||
let dir_link_s = dir_link.path().to_str().unwrap();
|
||||
let file_path_s = file.to_str().unwrap();
|
||||
|
||||
let link_name = dir_link.path().join("the_link");
|
||||
let link_name_s = link_it(link_name, file_path_s, false);
|
||||
|
||||
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", "-b", dir_link_s, dir_s])
|
||||
.unwrap()
|
||||
.stdout;
|
||||
|
||||
// The link or the file should appear but not both
|
||||
let output = str::from_utf8(&output).unwrap();
|
||||
let has_file_only = output.contains(file_path_s) && !output.contains(&link_name_s);
|
||||
let has_link_only = !output.contains(file_path_s) && output.contains(&link_name_s);
|
||||
assert!(has_file_only || has_link_only);
|
||||
}
|
||||
|
||||
#[cfg_attr(target_os = "windows", ignore)]
|
||||
#[test]
|
||||
pub fn test_recursive_sym_link() {
|
||||
@@ -89,14 +118,7 @@ pub fn test_recursive_sym_link() {
|
||||
let dir_s = dir.path().to_str().unwrap();
|
||||
|
||||
let link_name = dir.path().join("the_link");
|
||||
let link_name_s = link_name.to_str().unwrap();
|
||||
|
||||
let c = Command::new("ln")
|
||||
.arg("-s")
|
||||
.arg(dir_s)
|
||||
.arg(link_name_s)
|
||||
.output();
|
||||
assert!(c.is_ok());
|
||||
let link_name_s = link_it(link_name, dir_s, true);
|
||||
|
||||
let a = format!("─┬ {}", dir_s);
|
||||
let b = format!(" └── {}", link_name_s);
|
||||
@@ -107,7 +129,8 @@ pub fn test_recursive_sym_link() {
|
||||
.arg("-c")
|
||||
.arg("-r")
|
||||
.arg("-s")
|
||||
.arg("-w 999")
|
||||
.arg("-w")
|
||||
.arg("999")
|
||||
.arg(dir_s)
|
||||
.unwrap()
|
||||
.stdout;
|
||||
|
||||
Reference in New Issue
Block a user