Skip to content

Commit

Permalink
Merge pull request #533 from Xemptuous/feature/add-recursive-dir-size
Browse files Browse the repository at this point in the history
feat: added recursive directory parser with `--total-size` flag
  • Loading branch information
cafkafk authored Oct 26, 2023
2 parents bba97b5 + dadfccc commit a41a820
Show file tree
Hide file tree
Showing 18 changed files with 308 additions and 86 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ log = "0.4"
natord = "1.0"
num_cpus = "1.16"
number_prefix = "0.4"
once_cell = "1.18.0"
percent-encoding = "2.3.0"
phf = { version = "0.11.2", features = ["macros"] }
scoped_threadpool = "0.1"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ These options are available when running with `--long` (`-l`):
- **--git-repos-no-status**: list whether a directory is a Git repository, but not its status (faster)
- **--no-git**: suppress Git status (always overrides `--git`, `--git-repos`, `--git-repos-no-status`)
- **--time-style**: how to format timestamps. valid timestamp styles are ‘`default`’, ‘`iso`’, ‘`long-iso`’, ‘`full-iso`’, ‘`relative`', or you can use a `custom` style with '`+`' as prefix. (Ex: "`+%Y/%m/%d, %H:%M`" => "`2023/9/30, 12:00`"). [more about format syntax](https://docs.rs/chrono/latest/chrono/format/strftime/index.html).
- **--total-size**: show recursive directory size
- **--no-permissions**: suppress the permissions field
- **-o**, **--octal-permissions**: list each file's permission in octal format
- **--no-filesize**: suppress the filesize field
Expand Down Expand Up @@ -425,4 +426,3 @@ The Nix Flake has a few features:
## Star History

[![Star History Chart](https://api.star-history.com/svg?repos=eza-community/eza&type=Date)](https://star-history.com/#eza-community/eza&Date)

1 change: 1 addition & 0 deletions completions/fish/eza.fish
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ complete -c eza -l time-style -d "How to format timestamps" -x -a "
full-iso\t'Display full ISO timestamps, up to the nanosecond'
relative\t'Display relative timestamps'
"
complete -c eza -l total-size -d "Show recursive directory size"
complete -c eza -l no-permissions -d "Suppress the permissions field"
complete -c eza -s o -l octal-permissions -d "List each file's permission in octal format"
complete -c eza -l no-filesize -d "Suppress the filesize field"
Expand Down
1 change: 1 addition & 0 deletions completions/nush/eza.nu
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export extern "eza" [
--accessed(-u) # Use the accessed timestamp field
--created(-U) # Use the created timestamp field
--time-style # How to format timestamps
--total-size # Show recursive directory size
--no-permissions # Suppress the permissions field
--octal-permissions(-o) # List each file's permission in octal format
--no-filesize # Suppress the filesize field
Expand Down
1 change: 1 addition & 0 deletions completions/zsh/_eza
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ __eza() {
{-S,--blocksize}"[List each file's size of allocated file system blocks.]" \
{-t,--time}="[Which time field to show]:(time field):(accessed changed created modified)" \
--time-style="[How to format timestamps]:(time style):(default iso long-iso full-iso relative)" \
--total-size="[Show recursive directory size]" \
--no-permissions"[Suppress the permissions field]" \
{-o,--octal-permissions}"[List each file's permission in octal format]" \
--no-filesize"[Suppress the filesize field]" \
Expand Down
5 changes: 4 additions & 1 deletion man/eza.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ These options are available when running with `--long` (`-l`):

: Valid timestamp styles are ‘`default`’, ‘`iso`’, ‘`long-iso`’, ‘`full-iso`’, ‘`relative`', or you can use a `custom` style with '`+`' as prefix. (Ex: "`+%Y/%m/%d, %H:%M`" => "`2023/9/30, 12:00`"). for more details about format syntax, please read: https://docs.rs/chrono/latest/chrono/format/strftime/index.html

`--total-size`
: Show recursive directory size.

`-u`, `--accessed`
: Use the accessed timestamp field.

Expand Down Expand Up @@ -230,7 +233,7 @@ These options are available when running with `--long` (`-l`):

`--git` [if eza was built with git support]
: List each file’s Git status, if tracked.
This adds a two-character column indicating the staged and unstaged statuses respectively. The status character can be ‘`-`’ for not modified, ‘`M`’ for a modified file, ‘`N`’ for a new file, ‘`D`’ for deleted, ‘`R`’ for renamed, ‘`T`’ for type-change, ‘`I`’ for ignored, and ‘`U`’ for conflicted. Directories will be shown to have the status of their contents, which is how ‘deleted’ is possible if a directory contains a file that has a certain status, it will be shown to have that status.
This adds a two-character column indicating the staged and unstaged statuses respectively. The status character can be ‘`-`’ for not modified, ‘`M`’ for a modified file, ‘`N`’ for a new file, ‘`D`’ for deleted, ‘`R`’ for renamed, ‘`T`’ for type-change, ‘`I`’ for ignored, and ‘`U`’ for conflicted. Directories will be shown to have the status of their contents, which is how ‘deleted’ is possible if a directory contains a file that has a certain status, it will be shown to have that status.

`--git-repos` [if eza was built with git support]
: List each directory’s Git status, if tracked.
Expand Down
26 changes: 22 additions & 4 deletions src/fs/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ impl Dir {
git: Option<&'ig GitCache>,
git_ignoring: bool,
deref_links: bool,
total_size: bool,
) -> Files<'dir, 'ig> {
Files {
inner: self.contents.iter(),
Expand All @@ -60,6 +61,7 @@ impl Dir {
git,
git_ignoring,
deref_links,
total_size,
}
}

Expand All @@ -75,6 +77,7 @@ impl Dir {
}

/// Iterator over reading the contents of a directory as `File` objects.
#[allow(clippy::struct_excessive_bools)]
pub struct Files<'dir, 'ig> {
/// The internal iterator over the paths that have been read already.
inner: SliceIter<'dir, PathBuf>,
Expand All @@ -95,6 +98,9 @@ pub struct Files<'dir, 'ig> {

/// Whether symbolic links should be dereferenced when querying information.
deref_links: bool,

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

impl<'dir, 'ig> Files<'dir, 'ig> {
Expand Down Expand Up @@ -131,8 +137,14 @@ impl<'dir, 'ig> Files<'dir, 'ig> {
}
}

let file = File::from_args(path.clone(), self.dir, filename, self.deref_links)
.map_err(|e| (path.clone(), e));
let file = File::from_args(
path.clone(),
self.dir,
filename,
self.deref_links,
self.total_size,
)
.map_err(|e| (path.clone(), e));

// Windows has its own concept of hidden files, when dotfiles are
// hidden Windows hidden files should also be filtered out
Expand Down Expand Up @@ -169,12 +181,18 @@ impl<'dir, 'ig> Iterator for Files<'dir, 'ig> {
match self.dots {
DotsNext::Dot => {
self.dots = DotsNext::DotDot;
Some(File::new_aa_current(self.dir).map_err(|e| (Path::new(".").to_path_buf(), e)))
Some(
File::new_aa_current(self.dir, self.total_size)
.map_err(|e| (Path::new(".").to_path_buf(), e)),
)
}

DotsNext::DotDot => {
self.dots = DotsNext::Files;
Some(File::new_aa_parent(self.parent(), self.dir).map_err(|e| (self.parent(), e)))
Some(
File::new_aa_parent(self.parent(), self.dir, self.total_size)
.map_err(|e| (self.parent(), e)),
)
}

DotsNext::Files => self.next_visible_file(),
Expand Down
Loading

0 comments on commit a41a820

Please sign in to comment.