Skip to content

Commit cd53fc7

Browse files
committed
feat: new param: ignore-all-in-file
Add new cmd line param to ignore all files or directories listed in this file
1 parent e8c7990 commit cd53fc7

File tree

11 files changed

+62
-4
lines changed

11 files changed

+62
-4
lines changed

completions/_dust

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ _dust() {
2121
'--number-of-lines=[Number of lines of output to show. (Default is terminal_height - 10)]: : ' \
2222
'*-X+[Exclude any file or directory with this name]: : ' \
2323
'*--ignore-directory=[Exclude any file or directory with this name]: : ' \
24+
'-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]: : ' \
25+
'--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]: : ' \
2426
'-z+[Minimum size file to include in output]: : ' \
2527
'--min-size=[Minimum size file to include in output]: : ' \
2628
'(-e --filter -t --file_types)*-v+[Exclude filepaths matching this regex. To ignore png files type\: -v "\\.png\$" ]: : ' \

completions/_dust.ps1

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Register-ArgumentCompleter -Native -CommandName 'dust' -ScriptBlock {
2727
[CompletionResult]::new('--number-of-lines', 'number-of-lines', [CompletionResultType]::ParameterName, 'Number of lines of output to show. (Default is terminal_height - 10)')
2828
[CompletionResult]::new('-X', 'X ', [CompletionResultType]::ParameterName, 'Exclude any file or directory with this name')
2929
[CompletionResult]::new('--ignore-directory', 'ignore-directory', [CompletionResultType]::ParameterName, 'Exclude any file or directory with this name')
30+
[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')
31+
[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')
3032
[CompletionResult]::new('-z', 'z', [CompletionResultType]::ParameterName, 'Minimum size file to include in output')
3133
[CompletionResult]::new('--min-size', 'min-size', [CompletionResultType]::ParameterName, 'Minimum size file to include in output')
3234
[CompletionResult]::new('-v', 'v', [CompletionResultType]::ParameterName, 'Exclude filepaths matching this regex. To ignore png files type: -v "\.png$" ')

completions/dust.bash

+9-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ _dust() {
1919

2020
case "${cmd}" in
2121
dust)
22-
opts="-d -n -p -X -L -x -s -r -c -b -B -z -R -f -i -v -e -t -w -H -P -D -F -S -h -V --depth --number-of-lines --full-paths --ignore-directory --dereference-links --limit-filesystem --apparent-size --reverse --no-colors --no-percent-bars --bars-on-right --min-size --screen-reader --skip-total --filecount --ignore_hidden --invert-filter --filter --file_types --terminal_width --si --no-progress --only-dir --only-file --stack-size --help --version [params]..."
22+
opts="-d -n -p -X -I -L -x -s -r -c -b -B -z -R -f -i -v -e -t -w -H -P -D -F -S -h -V --depth --number-of-lines --full-paths --ignore-directory --ignore-all-in-file --dereference-links --limit-filesystem --apparent-size --reverse --no-colors --no-percent-bars --bars-on-right --min-size --screen-reader --skip-total --filecount --ignore_hidden --invert-filter --filter --file_types --terminal_width --si --no-progress --only-dir --only-file --stack-size --help --version [params]..."
2323
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
2424
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
2525
return 0
@@ -49,6 +49,14 @@ _dust() {
4949
COMPREPLY=($(compgen -f "${cur}"))
5050
return 0
5151
;;
52+
--ignore-all-in-file)
53+
COMPREPLY=($(compgen -f "${cur}"))
54+
return 0
55+
;;
56+
-I)
57+
COMPREPLY=($(compgen -f "${cur}"))
58+
return 0
59+
;;
5260
--min-size)
5361
COMPREPLY=($(compgen -f "${cur}"))
5462
return 0

completions/dust.elv

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ set edit:completion:arg-completer[dust] = {|@words|
2424
cand --number-of-lines 'Number of lines of output to show. (Default is terminal_height - 10)'
2525
cand -X 'Exclude any file or directory with this name'
2626
cand --ignore-directory 'Exclude any file or directory with this name'
27+
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'
28+
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'
2729
cand -z 'Minimum size file to include in output'
2830
cand --min-size 'Minimum size file to include in output'
2931
cand -v 'Exclude filepaths matching this regex. To ignore png files type: -v "\.png$" '

completions/dust.fish

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
complete -c dust -s d -l depth -d 'Depth to show' -r
22
complete -c dust -s n -l number-of-lines -d 'Number of lines of output to show. (Default is terminal_height - 10)' -r
33
complete -c dust -s X -l ignore-directory -d 'Exclude any file or directory with this name' -r
4+
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
45
complete -c dust -s z -l min-size -d 'Minimum size file to include in output' -r
56
complete -c dust -s v -l invert-filter -d 'Exclude filepaths matching this regex. To ignore png files type: -v "\\.png$" ' -r
67
complete -c dust -s e -l filter -d 'Only include filepaths matching this regex. For png files type: -e "\\.png$" ' -r

man-page/dust.1

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
.SH NAME
55
Dust \- Like du but more intuitive
66
.SH SYNOPSIS
7-
\fBDust\fR [\fB\-d\fR|\fB\-\-depth\fR] [\fB\-n\fR|\fB\-\-number\-of\-lines\fR] [\fB\-p\fR|\fB\-\-full\-paths\fR] [\fB\-X\fR|\fB\-\-ignore\-directory\fR] [\fB\-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\-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\-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] [\fB\-S\fR|\fB\-\-stack\-size\fR] [\fB\-h\fR|\fB\-\-help\fR] [\fB\-V\fR|\fB\-\-version\fR] [\fIparams\fR]
7+
\fBDust\fR [\fB\-d\fR|\fB\-\-depth\fR] [\fB\-n\fR|\fB\-\-number\-of\-lines\fR] [\fB\-p\fR|\fB\-\-full\-paths\fR] [\fB\-X\fR|\fB\-\-ignore\-directory\fR] [\fB\-I\fR|\fB\-\-ignore\-all\-in\-file\fR] [\fB\-L\fR|\fB\-\-dereference\-links\fR] [\fB\-x\fR|\fB\-\-limit\-filesystem\fR] [\fB\-s\fR|\fB\-\-apparent\-size\fR] [\fB\-r\fR|\fB\-\-reverse\fR] [\fB\-c\fR|\fB\-\-no\-colors\fR] [\fB\-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\-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] [\fB\-S\fR|\fB\-\-stack\-size\fR] [\fB\-h\fR|\fB\-\-help\fR] [\fB\-V\fR|\fB\-\-version\fR] [\fIparams\fR]
88
.SH DESCRIPTION
99
Like du but more intuitive
1010
.SH OPTIONS
@@ -21,6 +21,9 @@ Subdirectories will not have their path shortened
2121
\fB\-X\fR, \fB\-\-ignore\-directory\fR
2222
Exclude any file or directory with this name
2323
.TP
24+
\fB\-I\fR, \fB\-\-ignore\-all\-in\-file\fR
25+
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
26+
.TP
2427
\fB\-L\fR, \fB\-\-dereference\-links\fR
2528
dereference sym links \- Treat sym links as directories and go into them
2629
.TP

src/cli.rs

+7
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ pub fn build_cli() -> Command {
3737
.long("ignore-directory")
3838
.action(clap::ArgAction::Append)
3939
.help("Exclude any file or directory with this name"),
40+
)
41+
.arg(
42+
Arg::new("ignore_all_in_file")
43+
.short('I')
44+
.long("ignore-all-in-file")
45+
.value_parser(value_parser!(String))
46+
.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"),
4047
)
4148
.arg(
4249
Arg::new("dereference_links")

src/main.rs

+20
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ use display::InitialDisplayData;
1717
use filter::AggregateData;
1818
use progress::PIndicator;
1919
use progress::ORDERING;
20+
use regex::Error;
2021
use std::collections::HashSet;
22+
use std::fs::read_to_string;
2123
use std::panic;
2224
use std::process;
2325
use sysinfo::{System, SystemExt};
@@ -142,6 +144,24 @@ fn main() {
142144
None => vec![],
143145
};
144146

147+
let ignore_from_file_result = match options.get_one::<String>("ignore_all_in_file") {
148+
Some(val) => read_to_string(val)
149+
.unwrap()
150+
.lines()
151+
.map(Regex::new)
152+
.collect::<Vec<Result<Regex, Error>>>(),
153+
None => vec![],
154+
};
155+
let ignore_from_file = ignore_from_file_result
156+
.into_iter()
157+
.filter_map(|x| x.ok())
158+
.collect::<Vec<Regex>>();
159+
160+
let invert_filter_regexs = invert_filter_regexs
161+
.into_iter()
162+
.chain(ignore_from_file)
163+
.collect::<Vec<Regex>>();
164+
145165
let by_filecount = options.get_flag("by_filecount");
146166
let limit_filesystem = options.get_flag("limit_filesystem");
147167
let follow_links = options.get_flag("dereference_links");
+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
hi
1+
something
2+
.secret

tests/test_dir_hidden_entries/.secret

Whitespace-only changes.

tests/test_flags.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ pub fn test_d_flag_works_and_still_recurses_down() {
6464
// We had a bug where running with '-d 1' would stop at the first directory and the code
6565
// would fail to recurse down
6666
let output = build_command(vec!["-d", "1", "-f", "-c", "tests/test_dir2/"]);
67+
assert!(output.contains("1 ┌── dir"));
6768
assert!(output.contains("4 ┌─┴ test_dir2"));
6869
}
6970

@@ -73,7 +74,18 @@ pub fn test_ignore_dir() {
7374
let output = build_command(vec!["-c", "-X", "dir_substring", "tests/test_dir2/"]);
7475
assert!(!output.contains("dir_substring"));
7576
}
76-
// Add test for multiple dirs - with -d 0 and maybe -d 1 check the
77+
78+
#[test]
79+
pub fn test_ignore_all_in_file() {
80+
let output = build_command(vec![
81+
"-c",
82+
"-I",
83+
"tests/test_dir_hidden_entries/.hidden_file",
84+
"tests/test_dir_hidden_entries/",
85+
]);
86+
assert!(output.contains(" test_dir_hidden_entries"));
87+
assert!(!output.contains(".secret"));
88+
}
7789

7890
#[test]
7991
pub fn test_with_bad_param() {

0 commit comments

Comments
 (0)