mirror of
https://github.com/bootandy/dust.git
synced 2025-12-12 07:40:40 -08:00
Add Hide hidden flag
From feature request to respect the .gitignore file. Decided to bundle in respect for hidden files into the same feature [otherwise if you obey the .gitignore file you still endup showing the .git directory]
This commit is contained in:
@@ -126,6 +126,12 @@ fn main() {
|
||||
.long("filecount")
|
||||
.help("Directory 'size' is number of child files/dirs not disk size"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("ignore_hidden")
|
||||
.short("i") // Do not use 'h' this is used by 'help'
|
||||
.long("ignore_hidden")
|
||||
.help("Obey .git_ignore rules & Do not display hidden files"),
|
||||
)
|
||||
|
||||
.arg(Arg::with_name("inputs").multiple(true))
|
||||
.get_matches();
|
||||
@@ -165,6 +171,7 @@ fn main() {
|
||||
None => None,
|
||||
};
|
||||
let by_filecount = options.is_present("by_filecount");
|
||||
let show_hidden = !options.is_present("ignore_hidden");
|
||||
|
||||
let simplified_dirs = simplify_dir_names(target_dirs);
|
||||
let (permissions, nodes) = get_dir_tree(
|
||||
@@ -173,6 +180,7 @@ fn main() {
|
||||
use_apparent_size,
|
||||
limit_filesystem,
|
||||
by_filecount,
|
||||
show_hidden,
|
||||
depth,
|
||||
);
|
||||
let sorted_data = sort(nodes);
|
||||
|
||||
@@ -81,16 +81,19 @@ pub fn simplify_dir_names<P: AsRef<Path>>(filenames: Vec<P>) -> HashSet<PathBuf>
|
||||
fn prepare_walk_dir_builder<P: AsRef<Path>>(
|
||||
top_level_names: &HashSet<P>,
|
||||
limit_filesystem: bool,
|
||||
show_hidden: bool,
|
||||
max_depth: Option<usize>,
|
||||
) -> WalkBuilder {
|
||||
let mut it = top_level_names.iter();
|
||||
let mut builder = WalkBuilder::new(it.next().unwrap());
|
||||
builder.follow_links(false);
|
||||
builder.ignore(false);
|
||||
builder.git_global(false);
|
||||
builder.git_ignore(false);
|
||||
builder.git_exclude(false);
|
||||
builder.hidden(false);
|
||||
if show_hidden {
|
||||
builder.hidden(false);
|
||||
builder.ignore(false);
|
||||
builder.git_global(false);
|
||||
builder.git_ignore(false);
|
||||
builder.git_exclude(false);
|
||||
}
|
||||
|
||||
if limit_filesystem {
|
||||
builder.same_file_system(true);
|
||||
@@ -110,6 +113,7 @@ pub fn get_dir_tree<P: AsRef<Path>>(
|
||||
apparent_size: bool,
|
||||
limit_filesystem: bool,
|
||||
by_filecount: bool,
|
||||
show_hidden: bool,
|
||||
max_depth: Option<usize>,
|
||||
) -> (bool, HashMap<PathBuf, u64>) {
|
||||
let (tx, rx) = channel::bounded::<PathData>(1000);
|
||||
@@ -119,7 +123,8 @@ pub fn get_dir_tree<P: AsRef<Path>>(
|
||||
let t2 = HashSet::from_iter(top_level_names.iter().map(|p| p.as_ref().to_path_buf()));
|
||||
|
||||
let t = create_reader_thread(rx, t2, apparent_size);
|
||||
let walk_dir_builder = prepare_walk_dir_builder(top_level_names, limit_filesystem, max_depth);
|
||||
let walk_dir_builder =
|
||||
prepare_walk_dir_builder(top_level_names, limit_filesystem, show_hidden, max_depth);
|
||||
|
||||
walk_dir_builder.build_parallel().run(|| {
|
||||
let txc = tx.clone();
|
||||
|
||||
Reference in New Issue
Block a user