Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add --sort=blocks #1190

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ These options are available when running with `--long` (`-l`):
Some of the options accept parameters:

- Valid **--colo\[u\]r** options are **always**, **automatic** (or **auto** for short), and **never**.
- Valid sort fields are **accessed**, **changed**, **created**, **extension**, **Extension**, **inode**, **modified**, **name**, **Name**, **size**, **type**, and **none**. Fields starting with a capital letter sort uppercase before lowercase. The modified field has the aliases **date**, **time**, and **newest**, while its reverse has the aliases **age** and **oldest**.
- Valid sort fields are **accessed**, **changed**, **created**, **extension**, **Extension**, **inode**, **modified**, **name**, **Name**, **size**, **block**, **type**, and **none**. Fields starting with a capital letter sort uppercase before lowercase. The modified field has the aliases **date**, **time**, and **newest**, while its reverse has the aliases **age** and **oldest**.
- Valid time fields are **modified**, **changed**, **accessed**, and **created**.
- Valid time styles are **default**, **iso**, **long-iso**, **full-iso**, and **relative**.

Expand Down
2 changes: 1 addition & 1 deletion completions/bash/eza
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ _eza() {
;;

-s|--sort)
mapfile -t COMPREPLY < <(compgen -W 'name filename Name Filename size filesize extension Extension date time modified changed accessed created type inode oldest newest age none --' -- "$cur")
mapfile -t COMPREPLY < <(compgen -W 'name filename Name Filename size filesize blocks extension Extension date time modified changed accessed created type inode oldest newest age none --' -- "$cur")
return
;;

Expand Down
1 change: 1 addition & 0 deletions completions/fish/eza.fish
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ complete -c eza -s s -l sort -d "Which field to sort by" -x -a "
none\t'Do not sort files at all'
oldest\t'Sort by file modified time'
size\t'Sort by file size'
blocks\t'Sort by blocks number'
time\t'Sort by file modified time'
type\t'Sort by file type'
"
Expand Down
2 changes: 1 addition & 1 deletion completions/zsh/_eza
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ __eza() {
{-L,--level}"+[Limit the depth of recursion]" \
{-w,--width}"+[Limits column output of grid, 0 implies auto-width]" \
{-r,--reverse}"[Reverse the sort order]" \
{-s,--sort}="[Which field to sort by]:(sort field):(accessed age changed created date extension Extension filename Filename inode modified oldest name Name newest none size time type)" \
{-s,--sort}="[Which field to sort by]:(sort field):(accessed age changed created date extension Extension filename Filename inode modified oldest name Name newest none size blocks time type)" \
{-I,--ignore-glob}"[Ignore files that match these glob patterns]" \
{-b,--binary}"[List file sizes with binary prefixes]" \
{-B,--bytes}"[List file sizes in bytes, without any prefixes]" \
Expand Down
10 changes: 10 additions & 0 deletions src/fs/fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,16 @@ pub enum Blocksize {
None,
}

#[cfg(unix)]
impl Blocksize {
pub fn bytes(self) -> u64 {
match self {
Blocksize::Some(n) => n,
Blocksize::None => 0,
}
}
}

/// The ID of the user that owns a file. This will only ever be a number;
/// looking up the username is done in the `display` module.
#[derive(Copy, Clone)]
Expand Down
6 changes: 6 additions & 0 deletions src/fs/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ pub enum SortField {
/// The file’s size, in bytes.
Size,

/// The file’s block size, in bytes.
#[cfg(unix)]
BlockSize,

/// The file’s inode, which usually corresponds to the order in which
/// files were created on the filesystem, more or less.
#[cfg(unix)]
Expand Down Expand Up @@ -272,6 +276,8 @@ impl SortField {
Self::Name(AaBbCc) => natord::compare_ignore_case(&a.name, &b.name),

Self::Size => a.length().cmp(&b.length()),
#[cfg(unix)]
Self::BlockSize => a.blocksize().bytes().cmp(&b.blocksize().bytes()),

#[cfg(unix)]
Self::FileInode => {
Expand Down
2 changes: 2 additions & 0 deletions src/options/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ impl SortField {
".name" | ".filename" => Self::NameMixHidden(SortCase::AaBbCc),
".Name" | ".Filename" => Self::NameMixHidden(SortCase::ABCabc),
"size" | "filesize" => Self::Size,
#[cfg(unix)]
"block" | "blocks" | "blocksize" => Self::BlockSize,
"ext" | "extension" => Self::Extension(SortCase::AaBbCc),
"Ext" | "Extension" => Self::Extension(SortCase::ABCabc),

Expand Down