Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/fs/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ impl Dir {
git_ignoring: bool,
deref_links: bool,
total_size: bool,
#[cfg(windows)] show_hidden_underscore: bool,
) -> Files<'dir, 'ig> {
Files {
inner: self.contents.iter(),
Expand All @@ -68,6 +69,8 @@ impl Dir {
git_ignoring,
deref_links,
total_size,
#[cfg(windows)]
show_hidden_underscore,
}
}

Expand Down Expand Up @@ -109,6 +112,10 @@ pub struct Files<'dir, 'ig> {

/// Whether to calculate the directory size recursively
total_size: bool,

/// Whether to show files with underscore prefix on Windows
#[cfg(windows)]
show_hidden_underscore: bool,
}

impl<'dir, 'ig> Files<'dir, 'ig> {
Expand All @@ -135,7 +142,7 @@ impl<'dir, 'ig> Files<'dir, 'ig> {
// Also hide _prefix files on Windows because it's used by old applications
// as an alternative to dot-prefix files.
#[cfg(windows)]
if !self.dotfiles && filename.starts_with('_') {
if !self.dotfiles && !self.show_hidden_underscore && filename.starts_with('_') {
continue;
}

Expand Down
10 changes: 9 additions & 1 deletion src/fs/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,15 @@ impl<'dir> File<'dir> {
match Dir::read_dir(self.path.clone()) {
// . & .. are skipped, if the returned iterator has .next(), it's not empty
Ok(has_files) => has_files
.files(super::DotFilter::Dotfiles, None, false, false, false)
.files(
super::DotFilter::Dotfiles,
None,
false,
false,
false,
#[cfg(windows)]
false,
)
.next()
.is_none(),
Err(_) => false,
Expand Down
8 changes: 8 additions & 0 deletions src/fs/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ pub enum FileFilterFlags {
/// Whether directories should be listed as the last items, after other
/// types of file. Some users prefer it like this.
ListDirsLast,

/// Whether files starting with a _ should be treated as hidden under windows
#[cfg(windows)]
ShowHiddenUnderscore
}

/// The **file filter** processes a list of files before displaying them to
Expand Down Expand Up @@ -90,6 +94,10 @@ pub struct FileFilter {

/// Whether to explicitly show symlinks
pub show_symlinks: bool,

/// Whether to treat files with an _prefix as hidden under windows
#[cfg(windows)]
pub show_hidden_underscore: bool,
}

impl FileFilter {
Expand Down
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,8 @@ impl<'args> Exa<'args> {
git_ignore,
self.options.view.deref_links,
self.options.view.total_size,
#[cfg(windows)]
self.options.filter.show_hidden_underscore,
) {
children.push(file);
}
Expand Down
21 changes: 14 additions & 7 deletions src/options/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ impl FileFilter {
(matches.has(&flags::SHOW_SYMLINKS)?, FFF::ShowSymlinks),
(matches.has(&flags::DIRS_LAST)?, FFF::ListDirsLast),
(matches.has(&flags::DIRS_FIRST)?, FFF::ListDirsFirst),
#[cfg(windows)]
(
matches.has(&flags::SHOW_HIDDEN_UNDERSCORE)?,
FFF::ShowHiddenUnderscore,
),
] {
if *has {
filter_flags.push(flag.clone());
Expand All @@ -36,13 +41,15 @@ impl FileFilter {

#[rustfmt::skip]
return Ok(Self {
no_symlinks: filter_flags.contains(&FFF::NoSymlinks),
show_symlinks: filter_flags.contains(&FFF::ShowSymlinks),
flags: filter_flags,
sort_field: SortField::deduce(matches)?,
dot_filter: DotFilter::deduce(matches)?,
ignore_patterns: IgnorePatterns::deduce(matches)?,
git_ignore: GitIgnore::deduce(matches)?,
no_symlinks: filter_flags.contains(&FFF::NoSymlinks),
show_symlinks: filter_flags.contains(&FFF::ShowSymlinks),
#[cfg(windows)]
show_hidden_underscore: filter_flags.contains(&FFF::ShowHiddenUnderscore),
flags: filter_flags,
sort_field: SortField::deduce(matches)?,
dot_filter: DotFilter::deduce(matches)?,
ignore_patterns: IgnorePatterns::deduce(matches)?,
git_ignore: GitIgnore::deduce(matches)?,
});
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/options/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pub static ONLY_DIRS: Arg = Arg { short: Some(b'D'), long: "only-dirs", takes_
pub static ONLY_FILES: Arg = Arg { short: Some(b'f'), long: "only-files", takes_value: TakesValue::Forbidden };
pub static NO_SYMLINKS: Arg = Arg { short: None, long: "no-symlinks", takes_value: TakesValue::Forbidden };
pub static SHOW_SYMLINKS: Arg = Arg { short: None, long: "show-symlinks", takes_value: TakesValue::Forbidden };
pub static SHOW_HIDDEN_UNDERSCORE: Arg = Arg {short: None, long: "show-hidden-underscore", takes_value: TakesValue::Forbidden };
const SORTS: Values = &[ "name", "Name", "size", "extension",
"Extension", "modified", "changed", "accessed",
"created", "inode", "type", "none" ];
Expand Down Expand Up @@ -109,6 +110,7 @@ pub static ALL_ARGS: Args = Args(&[
&BINARY, &BYTES, &GROUP, &NUMERIC, &HEADER, &ICONS, &INODE, &LINKS, &MODIFIED, &CHANGED,
&BLOCKSIZE, &TOTAL_SIZE, &TIME, &ACCESSED, &CREATED, &TIME_STYLE, &HYPERLINK, &MOUNTS,
&NO_PERMISSIONS, &NO_FILESIZE, &NO_USER, &NO_TIME, &SMART_GROUP, &NO_SYMLINKS, &SHOW_SYMLINKS,
&SHOW_HIDDEN_UNDERSCORE,

&GIT, &NO_GIT, &GIT_REPOS, &GIT_REPOS_NO_STAT,
&EXTENDED, &OCTAL, &SECURITY_CONTEXT, &STDIN, &FILE_FLAGS
Expand Down
11 changes: 9 additions & 2 deletions src/output/color_scale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,16 @@ fn update_information_recursively(
match file.to_dir() {
Ok(dir) => {
let files: Vec<File<'_>> = dir
.files(dot_filter, git, git_ignoring, false, false)
.files(
dot_filter,
git,
git_ignoring,
false,
false,
#[cfg(windows)]
false,
)
.collect();

update_information_recursively(
information,
&files,
Expand Down
2 changes: 2 additions & 0 deletions src/output/details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,8 @@ impl<'a> Render<'a> {
self.git_ignoring,
egg.file.deref_links,
egg.file.is_recursive_size(),
#[cfg(windows)]
false
) {
files.push(file_to_add);
}
Expand Down