Compare commits

..

2 Commits

Author SHA1 Message Date
andy.boot
b8aab2df97 Increment version
Request for security fix
https://github.com/bootandy/dust/issues/324
2023-05-05 20:36:49 +01:00
andy.boot
38444f2d36 cargo update: update dependencies 2023-05-05 20:25:28 +01:00
22 changed files with 691 additions and 1433 deletions

View File

@@ -96,11 +96,6 @@ jobs:
target: arm-unknown-linux-gnueabihf, target: arm-unknown-linux-gnueabihf,
use-cross: use-cross, use-cross: use-cross,
} }
- {
os: ubuntu-latest,
target: arm-unknown-linux-musleabi,
use-cross: use-cross,
}
- { - {
os: ubuntu-latest, os: ubuntu-latest,
target: i686-unknown-linux-gnu, target: i686-unknown-linux-gnu,
@@ -210,9 +205,7 @@ jobs:
echo set-output name=CARGO_TEST_OPTIONS::${CARGO_TEST_OPTIONS} echo set-output name=CARGO_TEST_OPTIONS::${CARGO_TEST_OPTIONS}
echo ::set-output name=CARGO_TEST_OPTIONS::${CARGO_TEST_OPTIONS} echo ::set-output name=CARGO_TEST_OPTIONS::${CARGO_TEST_OPTIONS}
# * strip executable? # * 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="" ;; armv7-unknown-linux-musleabi) STRIP="" ;; arm-unknown-linux-musleabi) 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="" ;;esac;
echo set-output name=STRIP::${STRIP} echo set-output name=STRIP::${STRIP}
echo ::set-output name=STRIP::${STRIP} echo ::set-output name=STRIP::${STRIP}
- name: Create all needed build/work directories - name: Create all needed build/work directories

734
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,7 @@
[package] [package]
name = "du-dust" name = "du-dust"
description = "A more intuitive version of du" description = "A more intuitive version of du"
version = "1.0.0" version = "0.8.6"
authors = ["bootandy <bootandy@gmail.com>", "nebkor <code@ardent.nebcorp.com>"] authors = ["bootandy <bootandy@gmail.com>", "nebkor <code@ardent.nebcorp.com>"]
edition = "2021" edition = "2021"
readme = "README.md" readme = "README.md"
@@ -28,7 +28,8 @@ strip = true
[dependencies] [dependencies]
ansi_term = "0.12" ansi_term = "0.12"
clap = "4.4" atty = "0.2.14"
clap = "3.2.17"
lscolors = "0.13" lscolors = "0.13"
terminal_size = "0.2" terminal_size = "0.2"
unicode-width = "0.1" unicode-width = "0.1"
@@ -38,24 +39,20 @@ stfu8 = "0.2"
regex = "1" regex = "1"
config-file = "0.2" config-file = "0.2"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
directories = "4" directories = "4"
sysinfo = "0.27" sysinfo = "0.27"
ctrlc = "3.4"
chrono = "0.4"
[target.'cfg(windows)'.dependencies] [target.'cfg(windows)'.dependencies]
winapi-util = "0.1" winapi-util = "0.1"
filesize = "0.2.0"
[dev-dependencies] [dev-dependencies]
assert_cmd = "2" assert_cmd = "2"
tempfile = "=3" tempfile = "=3"
[build-dependencies] [build-dependencies]
clap = "4.4" clap = "3.2.17"
clap_complete = "4.4" clap_complete = "3.2.4"
clap_mangen = "0.2" clap_mangen = "0.1"
[[test]] [[test]]
name = "integration" name = "integration"

View File

@@ -1,5 +1,4 @@
[![Build Status](https://github.com/bootandy/dust/actions/workflows/CICD.yml/badge.svg)](https://github.com/bootandy/dust/actions) [![Build Status](https://travis-ci.org/bootandy/dust.svg?branch=master)](https://travis-ci.org/bootandy/dust)
# Dust # Dust
@@ -25,23 +24,18 @@ Because I want an easy way to see where my disk is being used.
#### 🍺 Homebrew (Linux) #### 🍺 Homebrew (Linux)
- `brew install dust` - `brew tap tgotwig/linux-dust && brew install dust`
#### [Pacstall](https://github.com/pacstall/pacstall) (Debian/Ubuntu) #### [Pacstall](https://github.com/pacstall/pacstall) (Debian/Ubuntu)
- `pacstall -I dust-bin` - `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](https://github.com/wimpysworld/deb-get) (Debian/Ubuntu)
- `deb-get install du-dust` - `deb-get install du-dust`
#### Windows: #### Windows:
- `scoop install dust`
- Windows GNU version - works - Windows GNU version - works
- Windows MSVC - requires: [VCRUNTIME140.dll](https://docs.microsoft.com/en-gb/cpp/windows/latest-supported-vc-redist?view=msvc-170) - Windows MSVC - requires: [VCRUNTIME140.dll](https://docs.microsoft.com/en-gb/cpp/windows/latest-supported-vc-redist?view=msvc-170)
@@ -72,14 +66,12 @@ Usage: dust -d 3 (Shows 3 levels of subdirectories)
Usage: dust -D (Show only directories (eg dust -D)) Usage: dust -D (Show only directories (eg dust -D))
Usage: dust -F (Show only files - finds your largest files) Usage: dust -F (Show only files - finds your largest files)
Usage: dust -r (reverse order of output) Usage: dust -r (reverse order of output)
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 -H (si print sizes in powers of 1000 instead of 1024)
Usage: dust -X ignore (ignore all files and directories with the name 'ignore') 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 -x (Only show directories on the same filesystem)
Usage: dust -b (Do not show percentages or draw ASCII bars) 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 -i (Do not show hidden files)
Usage: dust -c (No colors [monochrome]) Usage: dust -c (No colors [monochrome])
Usage: dust -C (Force colors)
Usage: dust -f (Count files instead of diskspace) Usage: dust -f (Count files instead of diskspace)
Usage: dust -t (Group by filetype) Usage: dust -t (Group by filetype)
Usage: dust -z 10M (min-size, Only include files larger than 10M) Usage: dust -z 10M (min-size, Only include files larger than 10M)
@@ -88,19 +80,9 @@ Usage: dust -v regex (Exclude files matching this regex (eg dust -v "\.png$" wou
Usage: dust -L (dereference-links - Treat sym links as directories and go into them) Usage: dust -L (dereference-links - Treat sym links as directories and go into them)
Usage: dust -P (Disable the progress indicator) 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 -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 --skip-total (No total row will be displayed)
Usage: dust -z 40000/30MB/20kib (Exclude output files/directories below size 40000 bytes / 30MB / 20KiB) Usage: dust -z 4000000 (Exclude files below size 4MB)
Usage: dust -j (Prints JSON representation of directories, try: dust -j | jq)
```
## 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 ## Alternatives

View File

@@ -15,28 +15,24 @@ _dust() {
local context curcontext="$curcontext" state line local context curcontext="$curcontext" state line
_arguments "${_arguments_options[@]}" \ _arguments "${_arguments_options[@]}" \
'-d+[Depth to show]:DEPTH: ' \ '-d+[Depth to show]: : ' \
'--depth=[Depth to show]:DEPTH: ' \ '--depth=[Depth to show]: : ' \
'-T+[Number of threads to use]: : ' \ '-n+[Number of lines of output to show. (Default is terminal_height - 10)]: : ' \
'--threads=[Number of threads to use]: : ' \ '--number-of-lines=[Number of lines of output to show. (Default is terminal_height - 10)]: : ' \
'-n+[Number of lines of output to show. (Default is terminal_height - 10)]:NUMBER: ' \ '*-X+[Exclude any file or directory with this name]: : ' \
'--number-of-lines=[Number of lines of output to show. (Default is terminal_height - 10)]:NUMBER: ' \ '*--ignore-directory=[Exclude any file or directory with this name]: : ' \
'*-X+[Exclude any file or directory with this name]:PATH:_files' \ '-z+[Minimum size file to include in output]: : ' \
'*--ignore-directory=[Exclude any file or directory with this name]:PATH:_files' \ '--min-size=[Minimum size file to include in output]: : ' \
'-I+[Exclude any file or directory with a regex matching that listed in this file, the file entries will be added to the ignore regexs provided by --invert_filter]:FILE:_files' \ '(-e --filter -t --file_types)*-v+[Exclude filepaths matching this regex. To ignore png files type: -v "\\.png$" ]: : ' \
'--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]:FILE:_files' \ '(-e --filter -t --file_types)*--invert-filter=[Exclude filepaths matching this regex. To ignore png files type: -v "\\.png$" ]: : ' \
'-z+[Minimum size file to include in output]:MIN_SIZE: ' \ '(-t --file_types)*-e+[Only include filepaths matching this regex. For png files type: -e "\\.png$" ]: : ' \
'--min-size=[Minimum size file to include in output]:MIN_SIZE: ' \ '(-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\$" ]:REGEX: ' \ '-w+[Specify width of output overriding the auto detection of terminal width]: : ' \
'(-e --filter -t --file_types)*--invert-filter=[Exclude filepaths matching this regex. To ignore png files type\: -v "\\.png\$" ]:REGEX: ' \ '--terminal_width=[Specify width of output overriding the auto detection of terminal width]: : ' \
'(-t --file_types)*-e+[Only include filepaths matching this regex. For png files type\: -e "\\.png\$" ]:REGEX: ' \ '-h[Print help information]' \
'(-t --file_types)*--filter=[Only include filepaths matching this regex. For png files type\: -e "\\.png\$" ]:REGEX: ' \ '--help[Print help information]' \
'-w+[Specify width of output overriding the auto detection of terminal width]:WIDTH: ' \ '-V[Print version information]' \
'--terminal_width=[Specify width of output overriding the auto detection of terminal width]:WIDTH: ' \ '--version[Print version information]' \
'-o+[Changes output display size. si will print sizes in powers of 1000. b k m g t kb mb gb tb will print the whole tree in that size.]:FORMAT:(si b k m g t kb mb gb tb)' \
'--output-format=[Changes output display size. si will print sizes in powers of 1000. b k m g t kb mb gb tb will print the whole tree in that size.]:FORMAT:(si b k m g t kb mb gb tb)' \
'-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: ' \
'--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)]:STACK_SIZE: ' \
'-p[Subdirectories will not have their path shortened]' \ '-p[Subdirectories will not have their path shortened]' \
'--full-paths[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]' \ '-L[dereference sym links - Treat sym links as directories and go into them]' \
@@ -47,36 +43,28 @@ _dust() {
'--apparent-size[Use file length instead of blocks]' \ '--apparent-size[Use file length instead of blocks]' \
'-r[Print tree upside down (biggest highest)]' \ '-r[Print tree upside down (biggest highest)]' \
'--reverse[Print tree upside down (biggest highest)]' \ '--reverse[Print tree upside down (biggest highest)]' \
'-c[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)]' \ '--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]' \ '-b[No percent bars or percentages will be displayed]' \
'--no-percent-bars[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]' \ '-R[For screen readers. Removes bars. Adds new column: depth level (May want to use -p too for full path)]' \
'--bars-on-right[percent bars moved to right side of screen]' \ '--screen-reader[For screen readers. Removes bars. Adds new column: depth level (May want to use -p too for full path)]' \
'-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]' \ '--skip-total[No total row will be displayed]' \
'-f[Directory '\''size'\'' is number of child files instead of disk size]' \ '-f[Directory '\''size'\'' is number of child files/dirs not disk size]' \
'--filecount[Directory '\''size'\'' is number of child files instead of disk size]' \ '--filecount[Directory '\''size'\'' is number of child files/dirs not disk size]' \
'-i[Do not display hidden files]' \ '-i[Do not display hidden files]' \
'--ignore_hidden[Do not display hidden files]' \ '--ignore_hidden[Do not display hidden files]' \
'(-d --depth -D --only-dir)-t[show only these file types]' \ '(-d --depth -D --only-dir)-t[show only these file types]' \
'(-d --depth -D --only-dir)--file_types[show only these file types]' \ '(-d --depth -D --only-dir)--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)]' \
'-P[Disable the progress indication.]' \ '-P[Disable the progress indication.]' \
'--no-progress[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)-D[Only directories will be displayed.]' \
'(-F --only-file -t --file_types)--only-dir[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)-F[Only files will be displayed. (Finds your largest files)]' \
'(-D --only-dir)--only-file[Only files will be displayed. (Finds your largest files)]' \ '(-D --only-dir)--only-file[Only files will be displayed. (Finds your largest files)]' \
'-j[Output the directory tree as json to the current directory]' \ '*::inputs:' \
'--output-json[Output the directory tree as json to the current directory]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
'*::params:_files' \
&& ret=0 && ret=0
} }
@@ -86,8 +74,4 @@ _dust_commands() {
_describe -t commands 'dust commands' commands "$@" _describe -t commands 'dust commands' commands "$@"
} }
if [ "$funcstack[1]" = "_dust" ]; then _dust "$@"
_dust "$@"
else
compdef _dust dust
fi

View File

@@ -23,14 +23,10 @@ Register-ArgumentCompleter -Native -CommandName 'dust' -ScriptBlock {
'dust' { 'dust' {
[CompletionResult]::new('-d', 'd', [CompletionResultType]::ParameterName, 'Depth to show') [CompletionResult]::new('-d', 'd', [CompletionResultType]::ParameterName, 'Depth to show')
[CompletionResult]::new('--depth', 'depth', [CompletionResultType]::ParameterName, 'Depth to show') [CompletionResult]::new('--depth', 'depth', [CompletionResultType]::ParameterName, 'Depth to show')
[CompletionResult]::new('-T', 'T ', [CompletionResultType]::ParameterName, 'Number of threads to use')
[CompletionResult]::new('--threads', 'threads', [CompletionResultType]::ParameterName, 'Number of threads to use')
[CompletionResult]::new('-n', 'n', [CompletionResultType]::ParameterName, 'Number of lines of output to show. (Default is terminal_height - 10)') [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('--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('--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('-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('--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$" ') [CompletionResult]::new('-v', 'v', [CompletionResultType]::ParameterName, 'Exclude filepaths matching this regex. To ignore png files type: -v "\.png$" ')
@@ -39,13 +35,13 @@ 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('--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('-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('--terminal_width', 'terminal_width', [CompletionResultType]::ParameterName, 'Specify width of output overriding the auto detection of terminal width')
[CompletionResult]::new('-o', 'o', [CompletionResultType]::ParameterName, 'Changes output display size. si will print sizes in powers of 1000. b k m g t kb mb gb tb will print the whole tree in that size.') [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help information')
[CompletionResult]::new('--output-format', 'output-format', [CompletionResultType]::ParameterName, 'Changes output display size. si will print sizes in powers of 1000. b k m g t kb mb gb tb will print the whole tree in that size.') [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help information')
[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('-V', 'V', [CompletionResultType]::ParameterName, 'Print version information')
[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('--version', 'version', [CompletionResultType]::ParameterName, 'Print version information')
[CompletionResult]::new('-p', 'p', [CompletionResultType]::ParameterName, 'Subdirectories will not have their path shortened') [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('--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('-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('--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('-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('--limit-filesystem', 'limit-filesystem', [CompletionResultType]::ParameterName, 'Only count the files and directories on the same filesystem as the supplied directory')
@@ -55,33 +51,25 @@ Register-ArgumentCompleter -Native -CommandName 'dust' -ScriptBlock {
[CompletionResult]::new('--reverse', 'reverse', [CompletionResultType]::ParameterName, 'Print tree upside down (biggest highest)') [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('-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('--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('-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('--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('-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('--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('--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('--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 instead of disk size') [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 instead of disk size') [CompletionResult]::new('--filecount', 'filecount', [CompletionResultType]::ParameterName, 'Directory ''size'' is number of child files/dirs not disk size')
[CompletionResult]::new('-i', 'i', [CompletionResultType]::ParameterName, 'Do not display hidden files') [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('--ignore_hidden', 'ignore_hidden', [CompletionResultType]::ParameterName, 'Do not display hidden files')
[CompletionResult]::new('-t', 't', [CompletionResultType]::ParameterName, 'show only these file types') [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('--file_types', 'file_types', [CompletionResultType]::ParameterName, 'show only these file types')
[CompletionResult]::new('-P', 'P ', [CompletionResultType]::ParameterName, 'Disable the progress indication.') [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('--no-progress', 'no-progress', [CompletionResultType]::ParameterName, 'Disable the progress indication.')
[CompletionResult]::new('-D', 'D ', [CompletionResultType]::ParameterName, 'Only directories will be displayed.') [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('--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('-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('--only-file', 'only-file', [CompletionResultType]::ParameterName, 'Only files will be displayed. (Finds your largest files)')
[CompletionResult]::new('-j', 'j', [CompletionResultType]::ParameterName, 'Output the directory tree as json to the current directory')
[CompletionResult]::new('--output-json', 'output-json', [CompletionResultType]::ParameterName, 'Output the directory tree as json to the current directory')
[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 break
} }
}) })

View File

@@ -1,5 +1,5 @@
_dust() { _dust() {
local i cur prev opts cmd local i cur prev opts cmds
COMPREPLY=() COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}" cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}" prev="${COMP_WORDS[COMP_CWORD-1]}"
@@ -8,8 +8,8 @@ _dust() {
for i in ${COMP_WORDS[@]} for i in ${COMP_WORDS[@]}
do do
case "${cmd},${i}" in case "${i}" in
",$1") "$1")
cmd="dust" cmd="dust"
;; ;;
*) *)
@@ -19,7 +19,7 @@ _dust() {
case "${cmd}" in case "${cmd}" in
dust) dust)
opts="-d -T -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 -j -h -V --depth --threads --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 --output-json --help --version [PATH]..." opts="-h -V -d -n -p -X -L -x -s -r -c -b -z -R -f -i -v -e -t -w -H -P -D -F --help --version --depth --number-of-lines --full-paths --ignore-directory --dereference-links --limit-filesystem --apparent-size --reverse --no-colors --no-percent-bars --min-size --screen-reader --skip-total --filecount --ignore_hidden --invert-filter --filter --file_types --terminal_width --si --no-progress --only-dir --only-file <inputs>..."
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0 return 0
@@ -33,14 +33,6 @@ _dust() {
COMPREPLY=($(compgen -f "${cur}")) COMPREPLY=($(compgen -f "${cur}"))
return 0 return 0
;; ;;
--threads)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
-T)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
--number-of-lines) --number-of-lines)
COMPREPLY=($(compgen -f "${cur}")) COMPREPLY=($(compgen -f "${cur}"))
return 0 return 0
@@ -57,36 +49,6 @@ _dust() {
COMPREPLY=($(compgen -f "${cur}")) COMPREPLY=($(compgen -f "${cur}"))
return 0 return 0
;; ;;
--ignore-all-in-file)
local oldifs
if [[ -v IFS ]]; then
oldifs="$IFS"
fi
IFS=$'\n'
COMPREPLY=($(compgen -f "${cur}"))
if [[ -v oldifs ]]; then
IFS="$oldifs"
fi
if [[ "${BASH_VERSINFO[0]}" -ge 4 ]]; then
compopt -o filenames
fi
return 0
;;
-I)
local oldifs
if [[ -v IFS ]]; then
oldifs="$IFS"
fi
IFS=$'\n'
COMPREPLY=($(compgen -f "${cur}"))
if [[ -v oldifs ]]; then
IFS="$oldifs"
fi
if [[ "${BASH_VERSINFO[0]}" -ge 4 ]]; then
compopt -o filenames
fi
return 0
;;
--min-size) --min-size)
COMPREPLY=($(compgen -f "${cur}")) COMPREPLY=($(compgen -f "${cur}"))
return 0 return 0
@@ -119,22 +81,6 @@ _dust() {
COMPREPLY=($(compgen -f "${cur}")) COMPREPLY=($(compgen -f "${cur}"))
return 0 return 0
;; ;;
--output-format)
COMPREPLY=($(compgen -W "si b k m g t kb mb gb tb" -- "${cur}"))
return 0
;;
-o)
COMPREPLY=($(compgen -W "si b k m g t kb mb gb tb" -- "${cur}"))
return 0
;;
--stack-size)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
-S)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
*) *)
COMPREPLY=() COMPREPLY=()
;; ;;
@@ -145,8 +91,4 @@ _dust() {
esac esac
} }
if [[ "${BASH_VERSINFO[0]}" -eq 4 && "${BASH_VERSINFO[1]}" -ge 4 || "${BASH_VERSINFO[0]}" -gt 4 ]]; then complete -F _dust -o bashdefault -o default dust
complete -F _dust -o nosort -o bashdefault -o default dust
else
complete -F _dust -o bashdefault -o default dust
fi

View File

@@ -20,14 +20,10 @@ set edit:completion:arg-completer[dust] = {|@words|
&'dust'= { &'dust'= {
cand -d 'Depth to show' cand -d 'Depth to show'
cand --depth 'Depth to show' cand --depth 'Depth to show'
cand -T 'Number of threads to use'
cand --threads 'Number of threads to use'
cand -n 'Number of lines of output to show. (Default is terminal_height - 10)' cand -n 'Number of lines of output to show. (Default is terminal_height - 10)'
cand --number-of-lines 'Number of lines of output to show. (Default is terminal_height - 10)' cand --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 -X 'Exclude any file or directory with this name'
cand --ignore-directory '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 -z 'Minimum size file to include in output'
cand --min-size '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$" ' cand -v 'Exclude filepaths matching this regex. To ignore png files type: -v "\.png$" '
@@ -36,10 +32,10 @@ set edit:completion:arg-completer[dust] = {|@words|
cand --filter 'Only include filepaths matching this regex. For png files type: -e "\.png$" ' 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 -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 --terminal_width 'Specify width of output overriding the auto detection of terminal width'
cand -o 'Changes output display size. si will print sizes in powers of 1000. b k m g t kb mb gb tb will print the whole tree in that size.' cand -h 'Print help information'
cand --output-format 'Changes output display size. si will print sizes in powers of 1000. b k m g t kb mb gb tb will print the whole tree in that size.' cand --help 'Print help information'
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 -V 'Print version information'
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 --version 'Print version information'
cand -p 'Subdirectories will not have their path shortened' cand -p 'Subdirectories will not have their path shortened'
cand --full-paths '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 -L 'dereference sym links - Treat sym links as directories and go into them'
@@ -52,33 +48,25 @@ set edit:completion:arg-completer[dust] = {|@words|
cand --reverse 'Print tree upside down (biggest highest)' cand --reverse 'Print tree upside down (biggest highest)'
cand -c 'No colors will be printed (Useful for commands like: watch)' 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 --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 -b 'No percent bars or percentages will be displayed'
cand --no-percent-bars '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 -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 --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 --skip-total 'No total row will be displayed'
cand -f 'Directory ''size'' is number of child files instead of disk size' cand -f 'Directory ''size'' is number of child files/dirs not disk size'
cand --filecount 'Directory ''size'' is number of child files instead of disk size' cand --filecount 'Directory ''size'' is number of child files/dirs not disk size'
cand -i 'Do not display hidden files' cand -i 'Do not display hidden files'
cand --ignore_hidden 'Do not display hidden files' cand --ignore_hidden 'Do not display hidden files'
cand -t 'show only these file types' cand -t 'show only these file types'
cand --file_types '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 -P 'Disable the progress indication.'
cand --no-progress 'Disable the progress indication.' cand --no-progress 'Disable the progress indication.'
cand -D 'Only directories will be displayed.' cand -D 'Only directories will be displayed.'
cand --only-dir '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 -F 'Only files will be displayed. (Finds your largest files)'
cand --only-file 'Only files will be displayed. (Finds your largest files)' cand --only-file 'Only files will be displayed. (Finds your largest files)'
cand -j 'Output the directory tree as json to the current directory'
cand --output-json 'Output the directory tree as json to the current directory'
cand -h 'Print help'
cand --help 'Print help'
cand -V 'Print version'
cand --version 'Print version'
} }
] ]
$completions[$command] $completions[$command]

View File

@@ -1,31 +1,25 @@
complete -c dust -s d -l depth -d 'Depth to show' -r complete -c dust -s d -l depth -d 'Depth to show' -r
complete -c dust -s T -l threads -d 'Number of threads to use' -r
complete -c dust -s n -l number-of-lines -d 'Number of lines of output to show. (Default is terminal_height - 10)' -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 -F 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 -F
complete -c dust -s z -l min-size -d 'Minimum size file to include in output' -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 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 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 w -l terminal_width -d 'Specify width of output overriding the auto detection of terminal width' -r
complete -c dust -s o -l output-format -d 'Changes output display size. si will print sizes in powers of 1000. b k m g t kb mb gb tb will print the whole tree in that size.' -r -f -a "{si '',b '',k '',m '',g '',t '',kb '',mb '',gb '',tb ''}" complete -c dust -s h -l help -d 'Print help information'
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 V -l version -d 'Print version information'
complete -c dust -s p -l full-paths -d 'Subdirectories will not have their path shortened' 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 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 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 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 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 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 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 -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 -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 instead of disk size' complete -c dust -s f -l filecount -d 'Directory \'size\' is number of child files/dirs not disk size'
complete -c dust -s i -l ignore_hidden -d 'Do not display hidden files' 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 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 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 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 F -l only-file -d 'Only files will be displayed. (Finds your largest files)'
complete -c dust -s j -l output-json -d 'Output the directory tree as json to the current directory'
complete -c dust -s h -l help -d 'Print help'
complete -c dust -s V -l version -d 'Print version'

View File

@@ -1,32 +1,32 @@
.ie \n(.g .ds Aq \(aq .ie \n(.g .ds Aq \(aq
.el .ds Aq ' .el .ds Aq '
.TH Dust 1 "Dust 1.0.0" .TH Dust 1 "Dust 0.8.6"
.SH NAME .SH NAME
Dust \- Like du but more intuitive Dust \- Like du but more intuitive
.SH SYNOPSIS .SH SYNOPSIS
\fBdust\fR [\fB\-d\fR|\fB\-\-depth\fR] [\fB\-T\fR|\fB\-\-threads\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\-j\fR|\fB\-\-output\-json\fR] [\fB\-h\fR|\fB\-\-help\fR] [\fB\-V\fR|\fB\-\-version\fR] [\fIPATH\fR] \fBDust\fR [\fB\-h\fR|\fB\-\-help\fR] [\fB\-V\fR|\fB\-\-version\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\-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\-b\fR|\fB\-\-no\-percent\-bars\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\-H\fR|\fB\-\-si\fR] [\fB\-P\fR|\fB\-\-no\-progress\fR] [\fB\-D\fR|\fB\-\-only\-dir\fR] [\fB\-F\fR|\fB\-\-only\-file\fR] [\fIinputs\fR]
.SH DESCRIPTION .SH DESCRIPTION
Like du but more intuitive Like du but more intuitive
.SH OPTIONS .SH OPTIONS
.TP .TP
\fB\-d\fR, \fB\-\-depth\fR=\fIDEPTH\fR \fB\-h\fR, \fB\-\-help\fR
Print help information
.TP
\fB\-V\fR, \fB\-\-version\fR
Print version information
.TP
\fB\-d\fR, \fB\-\-depth\fR
Depth to show Depth to show
.TP .TP
\fB\-T\fR, \fB\-\-threads\fR \fB\-n\fR, \fB\-\-number\-of\-lines\fR
Number of threads to use
.TP
\fB\-n\fR, \fB\-\-number\-of\-lines\fR=\fINUMBER\fR
Number of lines of output to show. (Default is terminal_height \- 10) Number of lines of output to show. (Default is terminal_height \- 10)
.TP .TP
\fB\-p\fR, \fB\-\-full\-paths\fR \fB\-p\fR, \fB\-\-full\-paths\fR
Subdirectories will not have their path shortened Subdirectories will not have their path shortened
.TP .TP
\fB\-X\fR, \fB\-\-ignore\-directory\fR=\fIPATH\fR \fB\-X\fR, \fB\-\-ignore\-directory\fR
Exclude any file or directory with this name Exclude any file or directory with this name
.TP .TP
\fB\-I\fR, \fB\-\-ignore\-all\-in\-file\fR=\fIFILE\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 \fB\-L\fR, \fB\-\-dereference\-links\fR
dereference sym links \- Treat sym links as directories and go into them dereference sym links \- Treat sym links as directories and go into them
.TP .TP
@@ -42,16 +42,10 @@ Print tree upside down (biggest highest)
\fB\-c\fR, \fB\-\-no\-colors\fR \fB\-c\fR, \fB\-\-no\-colors\fR
No colors will be printed (Useful for commands like: watch) No colors will be printed (Useful for commands like: watch)
.TP .TP
\fB\-C\fR, \fB\-\-force\-colors\fR
Force colors print
.TP
\fB\-b\fR, \fB\-\-no\-percent\-bars\fR \fB\-b\fR, \fB\-\-no\-percent\-bars\fR
No percent bars or percentages will be displayed No percent bars or percentages will be displayed
.TP .TP
\fB\-B\fR, \fB\-\-bars\-on\-right\fR \fB\-z\fR, \fB\-\-min\-size\fR
percent bars moved to right side of screen
.TP
\fB\-z\fR, \fB\-\-min\-size\fR=\fIMIN_SIZE\fR
Minimum size file to include in output Minimum size file to include in output
.TP .TP
\fB\-R\fR, \fB\-\-screen\-reader\fR \fB\-R\fR, \fB\-\-screen\-reader\fR
@@ -61,23 +55,26 @@ For screen readers. Removes bars. Adds new column: depth level (May want to use
No total row will be displayed No total row will be displayed
.TP .TP
\fB\-f\fR, \fB\-\-filecount\fR \fB\-f\fR, \fB\-\-filecount\fR
Directory \*(Aqsize\*(Aq is number of child files instead of disk size Directory \*(Aqsize\*(Aq is number of child files/dirs not disk size
.TP .TP
\fB\-i\fR, \fB\-\-ignore_hidden\fR \fB\-i\fR, \fB\-\-ignore_hidden\fR
Do not display hidden files Do not display hidden files
.TP .TP
\fB\-v\fR, \fB\-\-invert\-filter\fR=\fIREGEX\fR \fB\-v\fR, \fB\-\-invert\-filter\fR
Exclude filepaths matching this regex. To ignore png files type: \-v "\\.png$" Exclude filepaths matching this regex. To ignore png files type: \-v "\\.png$"
.TP .TP
\fB\-e\fR, \fB\-\-filter\fR=\fIREGEX\fR \fB\-e\fR, \fB\-\-filter\fR
Only include filepaths matching this regex. For png files type: \-e "\\.png$" Only include filepaths matching this regex. For png files type: \-e "\\.png$"
.TP .TP
\fB\-t\fR, \fB\-\-file_types\fR \fB\-t\fR, \fB\-\-file_types\fR
show only these file types show only these file types
.TP .TP
\fB\-w\fR, \fB\-\-terminal_width\fR=\fIWIDTH\fR \fB\-w\fR, \fB\-\-terminal_width\fR
Specify width of output overriding the auto detection of terminal width Specify width of output overriding the auto detection of terminal width
.TP .TP
\fB\-H\fR, \fB\-\-si\fR
print sizes in powers of 1000 (e.g., 1.1G)
.TP
\fB\-P\fR, \fB\-\-no\-progress\fR \fB\-P\fR, \fB\-\-no\-progress\fR
Disable the progress indication. Disable the progress indication.
.TP .TP
@@ -87,26 +84,7 @@ Only directories will be displayed.
\fB\-F\fR, \fB\-\-only\-file\fR \fB\-F\fR, \fB\-\-only\-file\fR
Only files will be displayed. (Finds your largest files) Only files will be displayed. (Finds your largest files)
.TP .TP
\fB\-o\fR, \fB\-\-output\-format\fR=\fIFORMAT\fR [\fIinputs\fR]
Changes output display size. si will print sizes in powers of 1000. b k m g t kb mb gb tb will print the whole tree in that size.
.br
.br
[\fIpossible values: \fRsi, b, k, m, g, t, kb, mb, gb, tb]
.TP
\fB\-S\fR, \fB\-\-stack\-size\fR=\fISTACK_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\-j\fR, \fB\-\-output\-json\fR
Output the directory tree as json to the current directory
.TP
\fB\-h\fR, \fB\-\-help\fR
Print help
.TP
\fB\-V\fR, \fB\-\-version\fR
Print version
.TP
[\fIPATH\fR]
.SH VERSION .SH VERSION
v1.0.0 v0.8.6

View File

@@ -1,160 +1,116 @@
use clap::{builder::PossibleValue, value_parser, Arg, Command}; use clap::{Arg, Command};
// For single thread mode set this variable on your command line: // For single thread mode set this variable on your command line:
// export RAYON_NUM_THREADS=1 // export RAYON_NUM_THREADS=1
pub fn build_cli() -> Command { pub fn build_cli() -> Command<'static> {
Command::new("Dust") Command::new("Dust")
.about("Like du but more intuitive") .about("Like du but more intuitive")
.version(env!("CARGO_PKG_VERSION")) .version(env!("CARGO_PKG_VERSION"))
.trailing_var_arg(true)
.arg( .arg(
Arg::new("depth") Arg::new("depth")
.short('d') .short('d')
.long("depth") .long("depth")
.value_name("DEPTH")
.value_parser(value_parser!(usize))
.help("Depth to show") .help("Depth to show")
.num_args(1) .takes_value(true)
)
.arg(
Arg::new("threads")
.short('T')
.long("threads")
.value_parser(value_parser!(usize))
.help("Number of threads to use")
.num_args(1)
) )
.arg( .arg(
Arg::new("number_of_lines") Arg::new("number_of_lines")
.short('n') .short('n')
.long("number-of-lines") .long("number-of-lines")
.value_name("NUMBER")
.value_parser(value_parser!(usize))
.help("Number of lines of output to show. (Default is terminal_height - 10)") .help("Number of lines of output to show. (Default is terminal_height - 10)")
.num_args(1) .takes_value(true)
) )
.arg( .arg(
Arg::new("display_full_paths") Arg::new("display_full_paths")
.short('p') .short('p')
.long("full-paths") .long("full-paths")
.action(clap::ArgAction::SetTrue)
.help("Subdirectories will not have their path shortened"), .help("Subdirectories will not have their path shortened"),
) )
.arg( .arg(
Arg::new("ignore_directory") Arg::new("ignore_directory")
.short('X') .short('X')
.long("ignore-directory") .long("ignore-directory")
.value_name("PATH") .takes_value(true)
.value_hint(clap::ValueHint::AnyPath) .number_of_values(1)
.action(clap::ArgAction::Append) .multiple_occurrences(true)
.help("Exclude any file or directory with this name"), .help("Exclude any file or directory with this name"),
)
.arg(
Arg::new("ignore_all_in_file")
.short('I')
.long("ignore-all-in-file")
.value_name("FILE")
.value_hint(clap::ValueHint::FilePath)
.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(
Arg::new("dereference_links") Arg::new("dereference_links")
.short('L') .short('L')
.long("dereference-links") .long("dereference-links")
.action(clap::ArgAction::SetTrue)
.help("dereference sym links - Treat sym links as directories and go into them"), .help("dereference sym links - Treat sym links as directories and go into them"),
) )
.arg( .arg(
Arg::new("limit_filesystem") Arg::new("limit_filesystem")
.short('x') .short('x')
.long("limit-filesystem") .long("limit-filesystem")
.action(clap::ArgAction::SetTrue)
.help("Only count the files and directories on the same filesystem as the supplied directory"), .help("Only count the files and directories on the same filesystem as the supplied directory"),
) )
.arg( .arg(
Arg::new("display_apparent_size") Arg::new("display_apparent_size")
.short('s') .short('s')
.long("apparent-size") .long("apparent-size")
.action(clap::ArgAction::SetTrue)
.help("Use file length instead of blocks"), .help("Use file length instead of blocks"),
) )
.arg( .arg(
Arg::new("reverse") Arg::new("reverse")
.short('r') .short('r')
.long("reverse") .long("reverse")
.action(clap::ArgAction::SetTrue)
.help("Print tree upside down (biggest highest)"), .help("Print tree upside down (biggest highest)"),
) )
.arg( .arg(
Arg::new("no_colors") Arg::new("no_colors")
.short('c') .short('c')
.long("no-colors") .long("no-colors")
.action(clap::ArgAction::SetTrue)
.help("No colors will be printed (Useful for commands like: watch)"), .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(
Arg::new("no_bars") Arg::new("no_bars")
.short('b') .short('b')
.long("no-percent-bars") .long("no-percent-bars")
.action(clap::ArgAction::SetTrue)
.help("No percent bars or percentages will be displayed"), .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(
Arg::new("min_size") Arg::new("min_size")
.short('z') .short('z')
.long("min-size") .long("min-size")
.value_name("MIN_SIZE") .takes_value(true)
.num_args(1) .number_of_values(1)
.help("Minimum size file to include in output"), .help("Minimum size file to include in output"),
) )
.arg( .arg(
Arg::new("screen_reader") Arg::new("screen_reader")
.short('R') .short('R')
.long("screen-reader") .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)"), .help("For screen readers. Removes bars. Adds new column: depth level (May want to use -p too for full path)"),
) )
.arg( .arg(
Arg::new("skip_total") Arg::new("skip_total")
.long("skip-total") .long("skip-total")
.action(clap::ArgAction::SetTrue)
.help("No total row will be displayed"), .help("No total row will be displayed"),
) )
.arg( .arg(
Arg::new("by_filecount") Arg::new("by_filecount")
.short('f') .short('f')
.long("filecount") .long("filecount")
.action(clap::ArgAction::SetTrue) .help("Directory 'size' is number of child files/dirs not disk size"),
.help("Directory 'size' is number of child files instead of disk size"),
) )
.arg( .arg(
Arg::new("ignore_hidden") Arg::new("ignore_hidden")
.short('i') // Do not use 'h' this is used by 'help' .short('i') // Do not use 'h' this is used by 'help'
.long("ignore_hidden") .long("ignore_hidden")
.action(clap::ArgAction::SetTrue)
.help("Do not display hidden files"), .help("Do not display hidden files"),
) )
.arg( .arg(
Arg::new("invert_filter") Arg::new("invert_filter")
.short('v') .short('v')
.long("invert-filter") .long("invert-filter")
.value_name("REGEX") .takes_value(true)
.action(clap::ArgAction::Append) .number_of_values(1)
.multiple_occurrences(true)
.conflicts_with("filter") .conflicts_with("filter")
.conflicts_with("types") .conflicts_with("types")
.help("Exclude filepaths matching this regex. To ignore png files type: -v \"\\.png$\" "), .help("Exclude filepaths matching this regex. To ignore png files type: -v \"\\.png$\" "),
@@ -163,8 +119,9 @@ pub fn build_cli() -> Command {
Arg::new("filter") Arg::new("filter")
.short('e') .short('e')
.long("filter") .long("filter")
.value_name("REGEX") .takes_value(true)
.action(clap::ArgAction::Append) .number_of_values(1)
.multiple_occurrences(true)
.conflicts_with("types") .conflicts_with("types")
.help("Only include filepaths matching this regex. For png files type: -e \"\\.png$\" "), .help("Only include filepaths matching this regex. For png files type: -e \"\\.png$\" "),
) )
@@ -174,23 +131,26 @@ pub fn build_cli() -> Command {
.long("file_types") .long("file_types")
.conflicts_with("depth") .conflicts_with("depth")
.conflicts_with("only_dir") .conflicts_with("only_dir")
.action(clap::ArgAction::SetTrue)
.help("show only these file types"), .help("show only these file types"),
) )
.arg( .arg(
Arg::new("width") Arg::new("width")
.short('w') .short('w')
.long("terminal_width") .long("terminal_width")
.value_name("WIDTH") .takes_value(true)
.value_parser(value_parser!(usize)) .number_of_values(1)
.num_args(1)
.help("Specify width of output overriding the auto detection of terminal width"), .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( .arg(
Arg::new("disable_progress") Arg::new("disable_progress")
.short('P') .short('P')
.long("no-progress") .long("no-progress")
.action(clap::ArgAction::SetTrue)
.help("Disable the progress indication."), .help("Disable the progress indication."),
) )
.arg( .arg(
@@ -199,7 +159,6 @@ pub fn build_cli() -> Command {
.long("only-dir") .long("only-dir")
.conflicts_with("only_file") .conflicts_with("only_file")
.conflicts_with("types") .conflicts_with("types")
.action(clap::ArgAction::SetTrue)
.help("Only directories will be displayed."), .help("Only directories will be displayed."),
) )
.arg( .arg(
@@ -207,50 +166,7 @@ pub fn build_cli() -> Command {
.short('F') .short('F')
.long("only-file") .long("only-file")
.conflicts_with("only_dir") .conflicts_with("only_dir")
.action(clap::ArgAction::SetTrue)
.help("Only files will be displayed. (Finds your largest files)"), .help("Only files will be displayed. (Finds your largest files)"),
) )
.arg( .arg(Arg::new("inputs").multiple_occurrences(true))
Arg::new("output_format")
.short('o')
.long("output-format")
.value_name("FORMAT")
.value_parser([
PossibleValue::new("si"),
PossibleValue::new("b"),
PossibleValue::new("k").alias("kib"),
PossibleValue::new("m").alias("mib"),
PossibleValue::new("g").alias("gib"),
PossibleValue::new("t").alias("tib"),
PossibleValue::new("kb"),
PossibleValue::new("mb"),
PossibleValue::new("gb"),
PossibleValue::new("tb"),
])
.ignore_case(true)
.help("Changes output display size. si will print sizes in powers of 1000. b k m g t kb mb gb tb will print the whole tree in that size.")
)
.arg(
Arg::new("stack_size")
.short('S')
.long("stack-size")
.value_name("STACK_SIZE")
.value_parser(value_parser!(usize))
.num_args(1)
.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")
.value_name("PATH")
.value_hint(clap::ValueHint::AnyPath)
.value_parser(value_parser!(String))
.num_args(1..)
)
.arg(
Arg::new("output_json")
.short('j')
.long("output-json")
.action(clap::ArgAction::SetTrue)
.help("Output the directory tree as json to the current directory"),
)
} }

View File

@@ -1,12 +1,10 @@
use clap::ArgMatches; use clap::ArgMatches;
use config_file::FromConfigFile; use config_file::FromConfigFile;
use regex::Regex;
use serde::Deserialize; use serde::Deserialize;
use std::io::IsTerminal;
use std::path::Path; use std::path::Path;
use std::path::PathBuf; use std::path::PathBuf;
use crate::display::get_number_format; use crate::display::UNITS;
#[derive(Deserialize, Default)] #[derive(Deserialize, Default)]
#[serde(rename_all = "kebab-case")] #[serde(rename_all = "kebab-case")]
@@ -16,147 +14,114 @@ pub struct Config {
pub display_apparent_size: Option<bool>, pub display_apparent_size: Option<bool>,
pub reverse: Option<bool>, pub reverse: Option<bool>,
pub no_colors: Option<bool>, pub no_colors: Option<bool>,
pub force_colors: Option<bool>,
pub no_bars: Option<bool>, pub no_bars: Option<bool>,
pub skip_total: Option<bool>, pub skip_total: Option<bool>,
pub screen_reader: Option<bool>, pub screen_reader: Option<bool>,
pub ignore_hidden: Option<bool>, pub ignore_hidden: Option<bool>,
pub output_format: Option<String>, pub iso: Option<bool>,
pub min_size: Option<String>, pub min_size: Option<String>,
pub only_dir: Option<bool>, pub only_dir: Option<bool>,
pub only_file: Option<bool>, pub only_file: Option<bool>,
pub disable_progress: Option<bool>, pub disable_progress: Option<bool>,
pub depth: Option<usize>, pub depth: Option<usize>,
pub bars_on_right: Option<bool>,
pub stack_size: Option<usize>,
pub threads: Option<usize>,
pub output_json: Option<bool>,
} }
impl Config { impl Config {
pub fn get_no_colors(&self, options: &ArgMatches) -> bool { pub fn get_no_colors(&self, options: &ArgMatches) -> bool {
Some(true) == self.no_colors || options.get_flag("no_colors") Some(true) == self.no_colors || options.is_present("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 { pub fn get_disable_progress(&self, options: &ArgMatches) -> bool {
Some(true) == self.disable_progress Some(true) == self.disable_progress || options.is_present("disable_progress")
|| options.get_flag("disable_progress")
|| !std::io::stdout().is_terminal()
} }
pub fn get_apparent_size(&self, options: &ArgMatches) -> bool { pub fn get_apparent_size(&self, options: &ArgMatches) -> bool {
Some(true) == self.display_apparent_size || options.get_flag("display_apparent_size") Some(true) == self.display_apparent_size || options.is_present("display_apparent_size")
} }
pub fn get_ignore_hidden(&self, options: &ArgMatches) -> bool { pub fn get_ignore_hidden(&self, options: &ArgMatches) -> bool {
Some(true) == self.ignore_hidden || options.get_flag("ignore_hidden") Some(true) == self.ignore_hidden || options.is_present("ignore_hidden")
} }
pub fn get_full_paths(&self, options: &ArgMatches) -> bool { pub fn get_full_paths(&self, options: &ArgMatches) -> bool {
Some(true) == self.display_full_paths || options.get_flag("display_full_paths") // If we are only showing files, always show full paths
Some(true) == self.display_full_paths
|| options.is_present("display_full_paths")
|| self.get_only_file(options)
} }
pub fn get_reverse(&self, options: &ArgMatches) -> bool { pub fn get_reverse(&self, options: &ArgMatches) -> bool {
Some(true) == self.reverse || options.get_flag("reverse") Some(true) == self.reverse || options.is_present("reverse")
} }
pub fn get_no_bars(&self, options: &ArgMatches) -> bool { pub fn get_no_bars(&self, options: &ArgMatches) -> bool {
Some(true) == self.no_bars || options.get_flag("no_bars") Some(true) == self.no_bars || options.is_present("no_bars")
} }
pub fn get_output_format(&self, options: &ArgMatches) -> String { pub fn get_iso(&self, options: &ArgMatches) -> bool {
let out_fmt = options.get_one::<String>("output_format"); Some(true) == self.iso || options.is_present("iso")
(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 { pub fn get_skip_total(&self, options: &ArgMatches) -> bool {
Some(true) == self.skip_total || options.get_flag("skip_total") Some(true) == self.skip_total || options.is_present("skip_total")
} }
pub fn get_screen_reader(&self, options: &ArgMatches) -> bool { pub fn get_screen_reader(&self, options: &ArgMatches) -> bool {
Some(true) == self.screen_reader || options.get_flag("screen_reader") Some(true) == self.screen_reader || options.is_present("screen_reader")
} }
pub fn get_depth(&self, options: &ArgMatches) -> usize { pub fn get_depth(&self, options: &ArgMatches) -> usize {
if let Some(v) = options.get_one::<usize>("depth") { if let Some(v) = options.value_of("depth") {
return *v; if let Ok(v) = v.parse::<usize>() {
return v;
}
} }
self.depth.unwrap_or(usize::MAX) self.depth.unwrap_or(usize::MAX)
} }
pub fn get_min_size(&self, options: &ArgMatches) -> Option<usize> { pub fn get_min_size(&self, options: &ArgMatches, iso: bool) -> Option<usize> {
let size_from_param = options.get_one::<String>("min_size"); let size_from_param = options.value_of("min_size");
self._get_min_size(size_from_param) self._get_min_size(size_from_param, iso)
} }
fn _get_min_size(&self, min_size: Option<&String>) -> Option<usize> { 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)); let size_from_param = min_size.and_then(|a| convert_min_size(a, iso));
if size_from_param.is_none() { if size_from_param.is_none() {
self.min_size self.min_size
.as_ref() .as_ref()
.and_then(|a| convert_min_size(a.as_ref())) .and_then(|a| convert_min_size(a.as_ref(), iso))
} else { } else {
size_from_param size_from_param
} }
} }
pub fn get_only_dir(&self, options: &ArgMatches) -> bool { pub fn get_only_dir(&self, options: &ArgMatches) -> bool {
Some(true) == self.only_dir || options.get_flag("only_dir") Some(true) == self.only_dir || options.is_present("only_dir")
} }
pub fn get_only_file(&self, options: &ArgMatches) -> bool { pub fn get_only_file(&self, options: &ArgMatches) -> bool {
Some(true) == self.only_file || options.get_flag("only_file") Some(true) == self.only_file || options.is_present("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()
}
}
pub fn get_threads(&self, options: &ArgMatches) -> Option<usize> {
let from_cmd_line = options.get_one::<usize>("threads");
if from_cmd_line.is_none() {
self.threads
} else {
from_cmd_line.copied()
}
}
pub fn get_output_json(&self, options: &ArgMatches) -> bool {
Some(true) == self.output_json || options.get_flag("output_json")
} }
} }
fn convert_min_size(input: &str) -> Option<usize> { fn convert_min_size(input: &str, iso: bool) -> Option<usize> {
let re = Regex::new(r"([0-9]+)(\w*)").unwrap(); 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>();
if let Some(cap) = re.captures(input) { for (i, u) in UNITS.iter().rev().enumerate() {
let (_, [digits, letters]) = cap.extract(); if Some(*u) == last.to_uppercase().next() {
return match starts.parse::<usize>() {
// Failure to parse should be impossible due to regex match Ok(pure) => {
let digits_as_usize: Option<usize> = digits.parse().ok(); let num: usize = if iso { 1000 } else { 1024 };
let marker = pure * num.pow((i + 1) as u32);
match digits_as_usize { Some(marker)
Some(parsed_digits) => { }
let number_format = get_number_format(&letters.to_lowercase()); Err(_) => {
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}"); eprintln!("Ignoring invalid min-size: {input}");
None None
} }
} };
} }
} }
None => None, starts.push(*last);
starts
.parse()
.map_err(|_| {
eprintln!("Ignoring invalid min-size: {input}");
})
.ok()
} }
} else { None => None,
None
} }
} }
@@ -186,31 +151,30 @@ pub fn get_config() -> Config {
mod tests { mod tests {
#[allow(unused_imports)] #[allow(unused_imports)]
use super::*; use super::*;
use clap::{value_parser, Arg, ArgMatches, Command}; use clap::{Arg, ArgMatches, Command};
#[test] #[test]
fn test_conversion() { fn test_conversion() {
assert_eq!(convert_min_size("55"), Some(55)); assert_eq!(convert_min_size("55", false), Some(55));
assert_eq!(convert_min_size("12344321"), Some(12344321)); assert_eq!(convert_min_size("12344321", false), Some(12344321));
assert_eq!(convert_min_size("95RUBBISH"), None); assert_eq!(convert_min_size("95RUBBISH", false), None);
assert_eq!(convert_min_size("10Ki"), Some(10 * 1024)); assert_eq!(convert_min_size("10K", false), Some(10 * 1024));
assert_eq!(convert_min_size("10MiB"), Some(10 * 1024usize.pow(2))); assert_eq!(convert_min_size("10M", false), Some(10 * 1024usize.pow(2)));
assert_eq!(convert_min_size("10M"), Some(10 * 1024usize.pow(2))); assert_eq!(convert_min_size("10M", true), Some(10 * 1000usize.pow(2)));
assert_eq!(convert_min_size("10Mb"), Some(10 * 1000usize.pow(2))); assert_eq!(convert_min_size("2G", false), Some(2 * 1024usize.pow(3)));
assert_eq!(convert_min_size("2Gi"), Some(2 * 1024usize.pow(3)));
} }
#[test] #[test]
fn test_min_size_from_config_applied_or_overridden() { fn test_min_size_from_config_applied_or_overridden() {
let c = Config { let c = Config {
min_size: Some("1KiB".to_owned()), min_size: Some("1K".to_owned()),
..Default::default() ..Default::default()
}; };
assert_eq!(c._get_min_size(None), Some(1024)); assert_eq!(c._get_min_size(None, false), Some(1024));
assert_eq!(c._get_min_size(Some(&"2KiB".into())), Some(2048)); assert_eq!(c._get_min_size(Some("2K"), false), Some(2048));
assert_eq!(c._get_min_size(Some(&"1kb".into())), Some(1000)); assert_eq!(c._get_min_size(None, true), Some(1000));
assert_eq!(c._get_min_size(Some(&"2KB".into())), Some(2000)); assert_eq!(c._get_min_size(Some("2K"), true), Some(2000));
} }
#[test] #[test]
@@ -244,12 +208,8 @@ mod tests {
fn get_args(args: Vec<&str>) -> ArgMatches { fn get_args(args: Vec<&str>) -> ArgMatches {
Command::new("Dust") Command::new("Dust")
.arg( .trailing_var_arg(true)
Arg::new("depth") .arg(Arg::new("depth").long("depth").takes_value(true))
.long("depth")
.num_args(1)
.value_parser(value_parser!(usize)),
)
.get_matches_from(args) .get_matches_from(args)
} }
} }

View File

@@ -1,11 +1,9 @@
use std::fs; use std::fs;
use std::sync::Arc; use std::sync::Arc;
use std::sync::Mutex;
use crate::node::Node; use crate::node::Node;
use crate::progress::Operation; use crate::progress::Operation;
use crate::progress::PAtomicInfo; use crate::progress::PAtomicInfo;
use crate::progress::RuntimeErrors;
use crate::progress::ORDERING; use crate::progress::ORDERING;
use crate::utils::is_filtered_out_due_to_invert_regex; use crate::utils::is_filtered_out_due_to_invert_regex;
use crate::utils::is_filtered_out_due_to_regex; use crate::utils::is_filtered_out_due_to_regex;
@@ -30,17 +28,16 @@ pub struct WalkData<'a> {
pub ignore_hidden: bool, pub ignore_hidden: bool,
pub follow_links: bool, pub follow_links: bool,
pub progress_data: Arc<PAtomicInfo>, pub progress_data: Arc<PAtomicInfo>,
pub errors: Arc<Mutex<RuntimeErrors>>,
} }
pub fn walk_it(dirs: HashSet<PathBuf>, walk_data: &WalkData) -> Vec<Node> { pub fn walk_it(dirs: HashSet<PathBuf>, walk_data: WalkData) -> Vec<Node> {
let mut inodes = HashSet::new(); let mut inodes = HashSet::new();
let top_level_nodes: Vec<_> = dirs let top_level_nodes: Vec<_> = dirs
.into_iter() .into_iter()
.filter_map(|d| { .filter_map(|d| {
let prog_data = &walk_data.progress_data; let prog_data = &walk_data.progress_data;
prog_data.clear_state(&d); prog_data.clear_state(&d);
let node = walk(d, walk_data, 0)?; let node = walk(d, &walk_data, 0)?;
prog_data.state.store(Operation::PREPARING, ORDERING); prog_data.state.store(Operation::PREPARING, ORDERING);
@@ -129,86 +126,55 @@ fn ignore_file(entry: &DirEntry, walk_data: &WalkData) -> bool {
fn walk(dir: PathBuf, walk_data: &WalkData, depth: usize) -> Option<Node> { fn walk(dir: PathBuf, walk_data: &WalkData, depth: usize) -> Option<Node> {
let prog_data = &walk_data.progress_data; let prog_data = &walk_data.progress_data;
let errors = &walk_data.errors; let mut children = vec![];
if errors.lock().unwrap().abort {
return None;
}
let children = if dir.is_dir() { if let Ok(entries) = fs::read_dir(&dir) {
let read_dir = fs::read_dir(&dir); children = entries
match read_dir { .into_iter()
Ok(entries) => { .par_bridge()
entries .filter_map(|entry| {
.into_iter() if let Ok(ref entry) = entry {
.par_bridge() // uncommenting the below line gives simpler code but
.filter_map(|entry| { // rayon doesn't parallelize as well giving a 3X performance drop
if let Ok(ref entry) = entry { // hence we unravel the recursion a bit
// 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) // return walk(entry.path(), walk_data, depth)
if !ignore_file(entry, walk_data) { if !ignore_file(entry, walk_data) {
if let Ok(data) = entry.file_type() { if let Ok(data) = entry.file_type() {
if data.is_dir() if data.is_dir() || (walk_data.follow_links && data.is_symlink()) {
|| (walk_data.follow_links && data.is_symlink()) return walk(entry.path(), walk_data, depth + 1);
{
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(); let node = build_node(
editable_error.no_permissions = true 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;
} }
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());
} }
} else {
prog_data.no_permissions.store(true, ORDERING)
} }
vec![] None
} })
} .collect();
} else { } else if !dir.is_file() {
if !dir.is_file() { walk_data.progress_data.no_permissions.store(true, ORDERING)
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( build_node(
dir, dir,
children, children,

View File

@@ -23,8 +23,7 @@ pub struct InitialDisplayData {
pub colors_on: bool, pub colors_on: bool,
pub by_filecount: bool, pub by_filecount: bool,
pub is_screen_reader: bool, pub is_screen_reader: bool,
pub output_format: String, pub iso: bool,
pub bars_on_right: bool,
} }
pub struct DisplayData { pub struct DisplayData {
@@ -99,13 +98,7 @@ impl DrawData<'_> {
let mut new_bar = "".to_string(); let mut new_bar = "".to_string();
let idx = 5 - level.clamp(1, 4); let idx = 5 - level.clamp(1, 4);
let itr: Box<dyn Iterator<Item = char>> = if self.display_data.initial.bars_on_right { for c in self.percent_bar.chars() {
Box::new(self.percent_bar.chars())
} else {
Box::new(self.percent_bar.chars().rev())
};
for c in itr {
num_not_my_bar -= 1; num_not_my_bar -= 1;
if num_not_my_bar <= 0 { if num_not_my_bar <= 0 {
new_bar.push(BLOCKS[0]); new_bar.push(BLOCKS[0]);
@@ -115,11 +108,7 @@ impl DrawData<'_> {
new_bar.push(c); new_bar.push(c);
} }
} }
if self.display_data.initial.bars_on_right { new_bar
new_bar
} else {
new_bar.chars().rev().collect()
}
} }
} }
@@ -142,7 +131,7 @@ pub fn draw_it(
let max_size = biggest.size; let max_size = biggest.size;
max_size.separate_with_commas().chars().count() max_size.separate_with_commas().chars().count()
} else { } else {
find_biggest_size_str(root_node, &idd.output_format) find_biggest_size_str(root_node, idd.iso)
}; };
assert!( assert!(
@@ -190,12 +179,10 @@ pub fn draw_it(
} }
} }
fn find_biggest_size_str(node: &DisplayNode, output_format: &str) -> usize { fn find_biggest_size_str(node: &DisplayNode, iso: bool) -> usize {
let mut mx = human_readable_number(node.size, output_format) let mut mx = human_readable_number(node.size, iso).chars().count();
.chars()
.count();
for n in node.children.iter() { for n in node.children.iter() {
mx = max(mx, find_biggest_size_str(n, output_format)); mx = max(mx, find_biggest_size_str(n, iso));
} }
mx mx
} }
@@ -377,7 +364,7 @@ fn get_pretty_size(node: &DisplayNode, is_biggest: bool, display_data: &DisplayD
let output = if display_data.initial.by_filecount { let output = if display_data.initial.by_filecount {
node.size.separate_with_commas() node.size.separate_with_commas()
} else { } else {
human_readable_number(node.size, &display_data.initial.output_format) human_readable_number(node.size, display_data.initial.iso)
}; };
let spaces_to_add = display_data.num_chars_needed_on_left_most - output.chars().count(); let spaces_to_add = display_data.num_chars_needed_on_left_most - output.chars().count();
let output = " ".repeat(spaces_to_add) + output.as_str(); let output = " ".repeat(spaces_to_add) + output.as_str();
@@ -409,51 +396,19 @@ fn get_pretty_name(
} }
} }
// If we are working with SI units or not pub fn human_readable_number(size: u64, iso: bool) -> String {
pub fn get_type_of_thousand(output_str: &str) -> u64 {
if output_str.is_empty() {
1024
} else if output_str == "si" {
1000
} else if output_str.contains('i') || output_str.len() == 1 {
1024
} else {
1000
}
}
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() { for (i, u) in UNITS.iter().enumerate() {
if output_str.starts_with((*u).to_ascii_lowercase()) { let num: u64 = if iso { 1000 } else { 1024 };
let marker = get_type_of_thousand(output_str).pow((UNITS.len() - i) as u32); let marker = num.pow((UNITS.len() - i) as u32);
return Some((marker, *u)); if size >= marker {
} if size / marker < 10 {
} return format!("{:.1}{}", (size as f32 / marker as f32), u);
None } else {
} return format!("{}{}", (size / marker), u);
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!("{size}B")
} }
mod tests { mod tests {
@@ -470,8 +425,7 @@ mod tests {
colors_on: false, colors_on: false,
by_filecount: false, by_filecount: false,
is_screen_reader: false, is_screen_reader: false,
output_format: "".into(), iso: false,
bars_on_right: false,
}; };
DisplayData { DisplayData {
initial, initial,
@@ -537,92 +491,21 @@ mod tests {
#[test] #[test]
fn test_human_readable_number() { fn test_human_readable_number() {
assert_eq!(human_readable_number(1, ""), "1B"); assert_eq!(human_readable_number(1, false), "1B");
assert_eq!(human_readable_number(956, ""), "956B"); assert_eq!(human_readable_number(956, false), "956B");
assert_eq!(human_readable_number(1004, ""), "1004B"); assert_eq!(human_readable_number(1004, false), "1004B");
assert_eq!(human_readable_number(1024, ""), "1.0K"); assert_eq!(human_readable_number(1024, false), "1.0K");
assert_eq!(human_readable_number(1536, ""), "1.5K"); assert_eq!(human_readable_number(1536, false), "1.5K");
assert_eq!(human_readable_number(1024 * 512, ""), "512K"); assert_eq!(human_readable_number(1024 * 512, false), "512K");
assert_eq!(human_readable_number(1024 * 1024, ""), "1.0M"); assert_eq!(human_readable_number(1024 * 1024, false), "1.0M");
assert_eq!(human_readable_number(1024 * 1024 * 1024 - 1, ""), "1023M"); assert_eq!(
assert_eq!(human_readable_number(1024 * 1024 * 1024 * 20, ""), "20G"); human_readable_number(1024 * 1024 * 1024 - 1, false),
assert_eq!(human_readable_number(1024 * 1024 * 1024 * 1024, ""), "1.0T"); "1023M"
} );
assert_eq!(human_readable_number(1024 * 1024 * 1024 * 20, false), "20G");
#[test] assert_eq!(
fn test_human_readable_number_si() { human_readable_number(1024 * 1024 * 1024 * 1024, false),
assert_eq!(human_readable_number(1024 * 100, ""), "100K"); "1.0T"
assert_eq!(human_readable_number(1024 * 100, "si"), "102K"); );
}
// Refer to https://en.wikipedia.org/wiki/Byte#Multiple-byte_units
#[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"), "1K");
assert_eq!(hrn(1023, "k"), "0K");
assert_eq!(hrn(1023, "kib"), "0K");
assert_eq!(hrn(1024, "kib"), "1K");
assert_eq!(hrn(1024 * 512, "kib"), "512K");
assert_eq!(hrn(1024 * 1024, "kib"), "1024K");
assert_eq!(hrn(1024 * 1000 * 1000 * 20, "kib"), "20000000K");
assert_eq!(hrn(1024 * 1024 * 1000 * 20, "mib"), "20000M");
assert_eq!(hrn(1024 * 1024 * 1024 * 20, "gib"), "20G");
}
#[cfg(test)]
fn build_draw_data(disp: &DisplayData, size: u32) -> (DrawData<'_>, 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, "████▓▓▓▓▓▓▓▓▓");
} }
} }

View File

@@ -1,8 +1,6 @@
use std::path::PathBuf; use std::path::PathBuf;
use serde::Serialize; #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone)]
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Serialize)]
pub struct DisplayNode { pub struct DisplayNode {
// Note: the order of fields in important here, for PartialEq and PartialOrd // Note: the order of fields in important here, for PartialEq and PartialOrd
pub size: u64, pub size: u64,

View File

@@ -11,27 +11,24 @@ mod progress;
mod utils; mod utils;
use crate::cli::build_cli; use crate::cli::build_cli;
use crate::progress::RuntimeErrors;
use clap::parser::ValuesRef;
use dir_walker::WalkData; use dir_walker::WalkData;
use display::InitialDisplayData; use display::InitialDisplayData;
use filter::AggregateData; use filter::AggregateData;
use progress::PIndicator; use progress::PIndicator;
use regex::Error; use progress::ORDERING;
use std::collections::HashSet; use std::collections::HashSet;
use std::env; use std::io::BufRead;
use std::fs::read_to_string;
use std::panic; use std::panic;
use std::process; use std::process;
use std::sync::Arc;
use std::sync::Mutex;
use sysinfo::{System, SystemExt}; use sysinfo::{System, SystemExt};
use self::display::draw_it; use self::display::draw_it;
use clap::Values;
use config::get_config; use config::get_config;
use dir_walker::walk_it; use dir_walker::walk_it;
use filter::get_biggest; use filter::get_biggest;
use filter_type::get_all_file_types; use filter_type::get_all_file_types;
use rayon::ThreadPoolBuildError;
use regex::Regex; use regex::Regex;
use std::cmp::max; use std::cmp::max;
use std::path::PathBuf; use std::path::PathBuf;
@@ -42,38 +39,29 @@ use utils::simplify_dir_names;
static DEFAULT_NUMBER_OF_LINES: usize = 30; static DEFAULT_NUMBER_OF_LINES: usize = 30;
static DEFAULT_TERMINAL_WIDTH: usize = 80; static DEFAULT_TERMINAL_WIDTH: usize = 80;
fn should_init_color(no_color: bool, force_color: bool) -> bool { fn init_color(no_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)] #[cfg(windows)]
{ {
// Required for windows 10 // If no color is already set do not print a warning message
// Fails to resolve for windows 8 so disable color if no_color {
match ansi_term::enable_ansi_support() { true
Ok(_) => true, } else {
Err(_) => { // Required for windows 10
eprintln!("This version of Windows does not support ANSI colors"); // Fails to resolve for windows 8 so disable color
false 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
}
} }
} }
} }
#[cfg(not(windows))] #[cfg(not(windows))]
{ {
true no_color
} }
} }
@@ -99,7 +87,7 @@ fn get_width_of_terminal() -> usize {
.unwrap_or(DEFAULT_TERMINAL_WIDTH) .unwrap_or(DEFAULT_TERMINAL_WIDTH)
} }
fn get_regex_value(maybe_value: Option<ValuesRef<String>>) -> Vec<Regex> { fn get_regex_value(maybe_value: Option<Values>) -> Vec<Regex> {
maybe_value maybe_value
.unwrap_or_default() .unwrap_or_default()
.map(|reg| { .map(|reg| {
@@ -111,86 +99,67 @@ fn get_regex_value(maybe_value: Option<ValuesRef<String>>) -> Vec<Regex> {
.collect() .collect()
} }
// Returns a list of lines from stdin or `None` if there's nothing to read
fn get_lines_from_stdin() -> Option<Vec<String>> {
atty::isnt(atty::Stream::Stdin).then(|| {
std::io::stdin()
.lock()
.lines()
.collect::<Result<_, _>>()
.expect("Error reading from stdin")
})
}
fn main() { fn main() {
let options = build_cli().get_matches(); let options = build_cli().get_matches();
let config = get_config(); let config = get_config();
let stdin_lines = get_lines_from_stdin();
let errors = RuntimeErrors::default(); let target_dirs = match options.values_of("inputs") {
let error_listen_for_ctrlc = Arc::new(Mutex::new(errors)); Some(values) => values.collect(),
let errors_for_rayon = error_listen_for_ctrlc.clone(); None => stdin_lines.as_ref().map_or(vec!["."], |lines| {
let errors_final = error_listen_for_ctrlc.clone(); lines.iter().map(String::as_str).collect()
}),
ctrlc::set_handler(move || {
error_listen_for_ctrlc.lock().unwrap().abort = true;
println!("\nAborting");
})
.expect("Error setting Ctrl-C handler");
let target_dirs = match options.get_many::<String>("params") {
Some(values) => values.map(|v| v.as_str()).collect::<Vec<&str>>(),
None => vec!["."],
}; };
let summarize_file_types = options.get_flag("types"); let summarize_file_types = options.is_present("types");
let filter_regexs = get_regex_value(options.get_many("filter")); let filter_regexs = get_regex_value(options.values_of("filter"));
let invert_filter_regexs = get_regex_value(options.get_many("invert_filter")); let invert_filter_regexs = get_regex_value(options.values_of("invert_filter"));
let terminal_width: usize = match options.get_one::<usize>("width") { let terminal_width = options
Some(&val) => val, .value_of_t("width")
None => get_width_of_terminal(), .unwrap_or_else(|_| get_width_of_terminal());
};
let depth = config.get_depth(&options); let depth = config.get_depth(&options);
// If depth is set, then we set the default number_of_lines to be max // If depth is set, then we set the default number_of_lines to be max
// instead of screen height // instead of screen height
let default_height = if depth != usize::MAX {
let number_of_lines = match options.get_one::<usize>("number_of_lines") { usize::MAX
Some(&val) => val, } else {
None => { get_height_of_terminal()
if depth != usize::MAX {
usize::MAX
} else {
get_height_of_terminal()
}
}
}; };
let is_colors = should_init_color( let number_of_lines = options
config.get_no_colors(&options), .value_of("number_of_lines")
config.get_force_colors(&options), .and_then(|v| {
); v.parse()
.map_err(|_| eprintln!("Ignoring bad value for number_of_lines"))
.ok()
})
.unwrap_or(default_height);
let ignore_directories = match options.get_many::<String>("ignore_directory") { let no_colors = init_color(config.get_no_colors(&options));
Some(values) => values
.map(|v| v.as_str())
.map(PathBuf::from)
.collect::<Vec<PathBuf>>(),
None => vec![],
};
let ignore_from_file_result = match options.get_one::<String>("ignore_all_in_file") { let ignore_directories = options
Some(val) => read_to_string(val) .values_of("ignore_directory")
.unwrap() .unwrap_or_default()
.lines() .map(PathBuf::from);
.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 invert_filter_regexs = invert_filter_regexs let by_filecount = options.is_present("by_filecount");
.into_iter() let limit_filesystem = options.is_present("limit_filesystem");
.chain(ignore_from_file) let follow_links = options.is_present("dereference_links");
.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 simplified_dirs = simplify_dir_names(target_dirs);
let allowed_filesystems = limit_filesystem let allowed_filesystems = limit_filesystem
@@ -198,17 +167,16 @@ fn main() {
.unwrap_or_default(); .unwrap_or_default();
let ignored_full_path: HashSet<PathBuf> = ignore_directories let ignored_full_path: HashSet<PathBuf> = ignore_directories
.into_iter()
.flat_map(|x| simplified_dirs.iter().map(move |d| d.join(&x))) .flat_map(|x| simplified_dirs.iter().map(move |d| d.join(&x)))
.collect(); .collect();
let output_format = config.get_output_format(&options); let iso = config.get_iso(&options);
let ignore_hidden = config.get_ignore_hidden(&options); let ignore_hidden = config.get_ignore_hidden(&options);
let mut indicator = PIndicator::build_me(); let mut indicator = PIndicator::build_me();
if !config.get_disable_progress(&options) { if !config.get_disable_progress(&options) {
indicator.spawn(output_format.clone()) indicator.spawn(iso);
} }
let walk_data = WalkData { let walk_data = WalkData {
@@ -221,123 +189,69 @@ fn main() {
ignore_hidden, ignore_hidden,
follow_links, follow_links,
progress_data: indicator.data.clone(), progress_data: indicator.data.clone(),
errors: errors_for_rayon,
}; };
let threads_to_use = config.get_threads(&options);
let stack_size = config.get_custom_stack_size(&options);
init_rayon(&stack_size, &threads_to_use);
let top_level_nodes = walk_it(simplified_dirs, &walk_data); let result = panic::catch_unwind(|| init_rayon);
if result.is_err() {
eprintln!("Problem initializing rayon, try: export RAYON_NUM_THREADS=1")
}
let top_level_nodes = walk_it(simplified_dirs, walk_data);
let tree = match summarize_file_types { let tree = match summarize_file_types {
true => get_all_file_types(&top_level_nodes, number_of_lines), true => get_all_file_types(&top_level_nodes, number_of_lines),
false => { false => {
let agg_data = AggregateData { let agg_data = AggregateData {
min_size: config.get_min_size(&options), min_size: config.get_min_size(&options, iso),
only_dir: config.get_only_dir(&options), only_dir: config.get_only_dir(&options),
only_file: config.get_only_file(&options), only_file: config.get_only_file(&options),
number_of_lines, number_of_lines,
depth, depth,
using_a_filter: !filter_regexs.is_empty() || !invert_filter_regexs.is_empty(), using_a_filter: options.values_of("filter").is_some()
|| options.value_of("invert_filter").is_some(),
}; };
get_biggest(top_level_nodes, agg_data) get_biggest(top_level_nodes, agg_data)
} }
}; };
// Must have stopped indicator before we print to stderr let failed_permissions = indicator.data.no_permissions.load(ORDERING);
indicator.stop(); indicator.stop();
// Must have stopped indicator before we print to stderr
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 { if failed_permissions {
eprintln!("Did not have permissions for all directories"); 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 { if let Some(root_node) = tree {
let idd = InitialDisplayData { let idd = InitialDisplayData {
short_paths: !config.get_full_paths(&options), short_paths: !config.get_full_paths(&options),
is_reversed: !config.get_reverse(&options), is_reversed: !config.get_reverse(&options),
colors_on: is_colors, colors_on: !no_colors,
by_filecount, by_filecount,
iso,
is_screen_reader: config.get_screen_reader(&options), is_screen_reader: config.get_screen_reader(&options),
output_format,
bars_on_right: config.get_bars_on_right(&options),
}; };
draw_it(
if config.get_output_json(&options) { idd,
println!("{}", serde_json::to_string(&root_node).unwrap()); config.get_no_bars(&options),
} else { terminal_width,
draw_it( &root_node,
idd, config.get_skip_total(&options),
config.get_no_bars(&options), )
terminal_width,
&root_node,
config.get_skip_total(&options),
)
}
} }
} }
fn init_rayon(stack_size: &Option<usize>, threads: &Option<usize>) { fn init_rayon() -> Result<(), ThreadPoolBuildError> {
// Rayon seems to raise this error on 32-bit builds let large_stack = usize::pow(1024, 3);
// The global thread pool has not been initialized.: ThreadPoolBuildError { kind: GlobalPoolAlreadyInitialized } let mut s = System::new();
if cfg!(target_pointer_width = "64") { s.refresh_memory();
let result = panic::catch_unwind(|| build_thread_pool(*stack_size, *threads)); let available = s.available_memory();
if result.is_err() {
eprintln!("Problem initializing rayon, try: export RAYON_NUM_THREADS=1") 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()
} }
} }
fn build_thread_pool(
stack: Option<usize>,
threads: Option<usize>,
) -> Result<(), rayon::ThreadPoolBuildError> {
let mut pool = rayon::ThreadPoolBuilder::new();
if let Some(thread_count) = threads {
pool = pool.num_threads(thread_count);
}
let stack_size = match stack {
Some(s) => Some(s),
None => {
let large_stack = usize::pow(1024, 3);
let mut s = System::new();
s.refresh_memory();
// Larger stack size if possible to handle cases with lots of nested directories
let available = s.available_memory();
if available > large_stack.try_into().unwrap() {
Some(large_stack)
} else {
None
}
}
};
if let Some(stack_size_param) = stack_size {
pool = pool.stack_size(stack_size_param);
}
pool.build_global()
}

View File

@@ -26,7 +26,7 @@ pub fn get_metadata(d: &Path, use_apparent_size: bool) -> Option<(u64, Option<(u
} }
#[cfg(target_family = "windows")] #[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 // 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 // expensive because 1) it causes a few system calls, and more importantly 2) it can cause
// windows defender to scan the file. // windows defender to scan the file.
@@ -90,27 +90,16 @@ pub fn get_metadata(d: &Path, use_apparent_size: bool) -> Option<(u64, Option<(u
Ok(Handle::from_file(file)) Ok(Handle::from_file(file))
} }
fn get_metadata_expensive( fn get_metadata_expensive(d: &Path) -> Option<(u64, Option<(u64, u64)>)> {
d: &Path,
use_apparent_size: bool,
) -> Option<(u64, Option<(u64, u64)>)> {
use winapi_util::file::information; use winapi_util::file::information;
let h = handle_from_path_limited(d).ok()?; let h = handle_from_path_limited(d).ok()?;
let info = information(&h).ok()?; let info = information(&h).ok()?;
if use_apparent_size { Some((
use filesize::PathExt; info.file_size(),
Some(( Some((info.file_index(), info.volume_serial_number())),
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; use std::os::windows::fs::MetadataExt;
@@ -122,31 +111,18 @@ pub fn get_metadata(d: &Path, use_apparent_size: bool) -> Option<(u64, Option<(u
const FILE_ATTRIBUTE_SYSTEM: u32 = 0x04; const FILE_ATTRIBUTE_SYSTEM: u32 = 0x04;
const FILE_ATTRIBUTE_NORMAL: u32 = 0x80; const FILE_ATTRIBUTE_NORMAL: u32 = 0x80;
const FILE_ATTRIBUTE_DIRECTORY: u32 = 0x10; 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() let attr_filtered = md.file_attributes()
& !(FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM); & !(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 || (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)) Some((md.len(), None))
} else { } else {
get_metadata_expensive(d, use_apparent_size) get_metadata_expensive(d)
} }
} }
_ => get_metadata_expensive(d, use_apparent_size), _ => get_metadata_expensive(d),
} }
} }

View File

@@ -1,9 +1,8 @@
use std::{ use std::{
collections::HashSet,
io::Write, io::Write,
path::Path, path::Path,
sync::{ sync::{
atomic::{AtomicU64, AtomicU8, AtomicUsize, Ordering}, atomic::{AtomicBool, AtomicU64, AtomicU8, AtomicUsize, Ordering},
mpsc::{self, RecvTimeoutError, Sender}, mpsc::{self, RecvTimeoutError, Sender},
Arc, RwLock, Arc, RwLock,
}, },
@@ -56,6 +55,7 @@ pub struct PAtomicInfo {
pub total_file_size: AtomicU64, pub total_file_size: AtomicU64,
pub state: AtomicU8, pub state: AtomicU8,
pub current_path: ThreadStringWrapper, pub current_path: ThreadStringWrapper,
pub no_permissions: AtomicBool,
} }
impl PAtomicInfo { impl PAtomicInfo {
@@ -68,26 +68,18 @@ impl PAtomicInfo {
} }
} }
#[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 { fn format_preparing_str(prog_char: char, data: &PAtomicInfo, is_iso: bool) -> String {
let path_in = data.current_path.get(); let path_in = data.current_path.get();
let size = human_readable_number(data.total_file_size.load(ORDERING), output_display); let size = human_readable_number(data.total_file_size.load(ORDERING), is_iso);
format!("Preparing: {path_in} {size} ... {prog_char}") format!("Preparing: {path_in} {size} ... {prog_char}")
} }
fn format_indexing_str(prog_char: char, data: &PAtomicInfo, output_display: &str) -> String { fn format_indexing_str(prog_char: char, data: &PAtomicInfo, is_iso: bool) -> String {
let path_in = data.current_path.get(); let path_in = data.current_path.get();
let file_count = data.num_files.load(ORDERING); let file_count = data.num_files.load(ORDERING);
let size = human_readable_number(data.total_file_size.load(ORDERING), output_display); let size = human_readable_number(data.total_file_size.load(ORDERING), is_iso);
let file_str = format!("{file_count} files, {size}"); let file_str = format!("{file_count} files, {size}");
format!("Indexing: {path_in} {file_str} ... {prog_char}") format!("Indexing: {path_in} {file_str} ... {prog_char}")
} }
@@ -107,7 +99,7 @@ impl PIndicator {
} }
} }
pub fn spawn(&mut self, output_display: String) { pub fn spawn(&mut self, is_iso: bool) {
let data = self.data.clone(); let data = self.data.clone();
let (stop_handler, receiver) = mpsc::channel::<()>(); let (stop_handler, receiver) = mpsc::channel::<()>();
@@ -126,8 +118,8 @@ impl PIndicator {
let prog_char = PROGRESS_CHARS[progress_char_i]; let prog_char = PROGRESS_CHARS[progress_char_i];
msg = match data.state.load(ORDERING) { msg = match data.state.load(ORDERING) {
Operation::INDEXING => format_indexing_str(prog_char, &data, &output_display), Operation::INDEXING => format_indexing_str(prog_char, &data, is_iso),
Operation::PREPARING => format_preparing_str(prog_char, &data, &output_display), Operation::PREPARING => format_preparing_str(prog_char, &data, is_iso),
_ => panic!("Unknown State"), _ => panic!("Unknown State"),
}; };

View File

@@ -1,2 +1 @@
something hi
.secret

View File

@@ -52,15 +52,7 @@ fn exact_output_test<T: AsRef<OsStr>>(valid_outputs: Vec<String>, command_args:
let output = str::from_utf8(&a.unwrap().stdout).unwrap().to_owned(); let output = str::from_utf8(&a.unwrap().stdout).unwrap().to_owned();
let will_fail = valid_outputs.iter().any(|i| output.contains(i)); assert!(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 // "windows" result data can vary by host (size seems to be variable by one byte); fix code vs test and re-enable
@@ -68,7 +60,7 @@ fn exact_output_test<T: AsRef<OsStr>>(valid_outputs: Vec<String>, command_args:
#[test] #[test]
pub fn test_main_basic() { pub fn test_main_basic() {
// -c is no color mode - This makes testing much simpler // -c is no color mode - This makes testing much simpler
exact_output_test(main_output(), vec!["-c", "-B", "/tmp/test_dir/"]) exact_output_test(main_output(), vec!["-c", "/tmp/test_dir/"])
} }
#[cfg_attr(target_os = "windows", ignore)] #[cfg_attr(target_os = "windows", ignore)]
@@ -76,7 +68,6 @@ pub fn test_main_basic() {
pub fn test_main_multi_arg() { pub fn test_main_multi_arg() {
let command_args = vec![ let command_args = vec![
"-c", "-c",
"-B",
"/tmp/test_dir/many/", "/tmp/test_dir/many/",
"/tmp/test_dir", "/tmp/test_dir",
"/tmp/test_dir", "/tmp/test_dir",
@@ -111,7 +102,7 @@ fn main_output() -> Vec<String> {
#[cfg_attr(target_os = "windows", ignore)] #[cfg_attr(target_os = "windows", ignore)]
#[test] #[test]
pub fn test_main_long_paths() { pub fn test_main_long_paths() {
let command_args = vec!["-c", "-p", "-B", "/tmp/test_dir/"]; let command_args = vec!["-c", "-p", "/tmp/test_dir/"];
exact_output_test(main_output_long_paths(), command_args); exact_output_test(main_output_long_paths(), command_args);
} }
@@ -139,7 +130,7 @@ fn main_output_long_paths() -> Vec<String> {
#[cfg_attr(target_os = "windows", ignore)] #[cfg_attr(target_os = "windows", ignore)]
#[test] #[test]
pub fn test_substring_of_names_and_long_names() { pub fn test_substring_of_names_and_long_names() {
let command_args = vec!["-c", "-B", "/tmp/test_dir2"]; let command_args = vec!["-c", "/tmp/test_dir2"];
exact_output_test(no_substring_of_names_output(), command_args); exact_output_test(no_substring_of_names_output(), command_args);
} }
@@ -173,7 +164,7 @@ fn no_substring_of_names_output() -> Vec<String> {
#[cfg_attr(target_os = "windows", ignore)] #[cfg_attr(target_os = "windows", ignore)]
#[test] #[test]
pub fn test_unicode_directories() { pub fn test_unicode_directories() {
let command_args = vec!["-c", "-B", "/tmp/test_dir_unicode"]; let command_args = vec!["-c", "/tmp/test_dir_unicode"];
exact_output_test(unicode_dir(), command_args); exact_output_test(unicode_dir(), command_args);
} }
@@ -206,19 +197,12 @@ pub fn test_apparent_size() {
fn apparent_size_output() -> Vec<String> { fn apparent_size_output() -> Vec<String> {
// The apparent directory sizes are too unpredictable and system dependent to try and match // The apparent directory sizes are too unpredictable and system dependent to try and match
let one_space_before = r#" let files = r#"
0B ┌── a_file
6B ├── hello_file
"#
.trim()
.to_string();
let two_space_before = r#"
0B ┌── a_file 0B ┌── a_file
6B ├── hello_file 6B ├── hello_file
"# "#
.trim() .trim()
.to_string(); .to_string();
vec![one_space_before, two_space_before] vec![files]
} }

View File

@@ -59,18 +59,11 @@ pub fn test_d_flag_works() {
assert!(!output.contains("hello_file")); assert!(!output.contains("hello_file"));
} }
#[test]
pub fn test_threads_flag_works() {
let output = build_command(vec!["-T", "1", "tests/test_dir/"]);
assert!(output.contains("hello_file"));
}
#[test] #[test]
pub fn test_d_flag_works_and_still_recurses_down() { 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 // We had a bug where running with '-d 1' would stop at the first directory and the code
// would fail to recurse down // would fail to recurse down
let output = build_command(vec!["-d", "1", "-f", "-c", "tests/test_dir2/"]); let output = build_command(vec!["-d", "1", "-f", "-c", "tests/test_dir2/"]);
assert!(output.contains("1 ┌── dir"));
assert!(output.contains("4 ┌─┴ test_dir2")); assert!(output.contains("4 ┌─┴ test_dir2"));
} }
@@ -80,25 +73,14 @@ pub fn test_ignore_dir() {
let output = build_command(vec!["-c", "-X", "dir_substring", "tests/test_dir2/"]); let output = build_command(vec!["-c", "-X", "dir_substring", "tests/test_dir2/"]);
assert!(!output.contains("dir_substring")); assert!(!output.contains("dir_substring"));
} }
// Add test for multiple dirs - with -d 0 and maybe -d 1 check the
#[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] #[test]
pub fn test_with_bad_param() { pub fn test_with_bad_param() {
let mut cmd = Command::cargo_bin("dust").unwrap(); let mut cmd = Command::cargo_bin("dust").unwrap();
let result = cmd.arg("bad_place").unwrap(); let result = cmd.arg("bad_place").unwrap();
let stderr = str::from_utf8(&result.stderr).unwrap(); let stderr = str::from_utf8(&result.stderr).unwrap();
assert!(stderr.contains("No such file or directory")); assert!(stderr.contains("Did not have permissions for all directories"));
} }
#[test] #[test]
@@ -139,9 +121,9 @@ pub fn test_show_files_by_type() {
#[cfg(target_family = "unix")] #[cfg(target_family = "unix")]
pub fn test_show_files_only() { pub fn test_show_files_only() {
let output = build_command(vec!["-c", "-F", "tests/test_dir"]); let output = build_command(vec!["-c", "-F", "tests/test_dir"]);
assert!(output.contains("a_file")); assert!(output.contains("tests/test_dir/many/a_file"));
assert!(output.contains("hello_file")); assert!(output.contains("tests/test_dir/many/hello_file"));
assert!(!output.contains("many")); assert!(!output.contains("tests/test_dir/many "));
} }
#[test] #[test]
@@ -238,19 +220,3 @@ pub fn test_show_files_by_invert_regex_match_multiple() {
assert!(!output.contains("test_dir_unicode")); assert!(!output.contains("test_dir_unicode"));
assert!(output.contains("many")); 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"));
}