Skip to content
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ These options are available when running with `--long` (`-l`):

- **-b**, **--binary**: list file sizes with binary prefixes
- **-B**, **--bytes**: list file sizes in bytes, without any prefixes
- **-g**, **--group**: list each file’s group
- **--hex**: list file sizes in hexadecimal (0x<size>)
- **-g**, **--group**: list each file's group
- **--smart-group**: only show group if it has a different name from owner
- **-h**, **--header**: add a header row to each column
- **-H**, **--links**: list each file’s number of hard links
Expand Down
1 change: 1 addition & 0 deletions completions/fish/eza.fish
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ complete -c eza -l no-symlinks -d "Do not show symbolic links"
# Long view options
complete -c eza -s b -l binary -d "List file sizes with binary prefixes"
complete -c eza -s B -l bytes -d "List file sizes in bytes, without any prefixes"
complete -c eza -l hex -d "List file sizes in hexadecimal (0x<size>)"
complete -c eza -s g -l group -d "List each file's group"
complete -c eza -s h -l header -d "Add a header row to each column"
complete -c eza -s H -l links -d "List each file's number of hard links"
Expand Down
1 change: 1 addition & 0 deletions completions/nush/eza.nu
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export extern "eza" [
--no-symlinks # Do not show symbolic links
--binary(-b) # List file sizes with binary prefixes
--bytes(-B) # List file sizes in bytes, without any prefixes
--hex # List file sizes in hexadecimal (0x<size>)
--group(-g) # List each file's group
--header(-h) # Add a header row to each column
--links(-H) # List each file's number of hard links
Expand Down
3 changes: 2 additions & 1 deletion completions/pwsh/_eza.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ Register-ArgumentCompleter -Native -CommandName 'eza' -ScriptBlock {
# [CompletionResult]::new('-b' ,'binary' , [CompletionResultType]::ParameterName, 'list file sizes with binary prefixes')
[CompletionResult]::new('--binary' ,'binary' , [CompletionResultType]::ParameterName, 'list file sizes with binary prefixes')
# [CompletionResult]::new('-B' ,'bytes' , [CompletionResultType]::ParameterName, 'list file sizes in bytes, without any prefixes')
[CompletionResult]::new('--bytes' ,'bytes' , [CompletionResultType]::ParameterName, 'list file sizes in bytes, without any prefixes')
[CompletionResult]::new('--bytes' ,'bytes' , [CompletionResultType]::ParameterName, 'list file sizes in bytes, without any prefixes')
[CompletionResult]::new('--hex' ,'hex' , [CompletionResultType]::ParameterName, 'list file sizes in hexadecimal (0x<size>)')
# [CompletionResult]::new('-g' ,'group' , [CompletionResultType]::ParameterName, 'list each file''s group')
[CompletionResult]::new('--smart-group' ,'smart-group' , [CompletionResultType]::ParameterName, 'only show group if it has a different name from owner')
[CompletionResult]::new('--group' ,'group' , [CompletionResultType]::ParameterName, 'list each file''s group')
Expand Down
1 change: 1 addition & 0 deletions completions/zsh/_eza
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ __eza() {
{-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]" \
--hex"[List file sizes in hexadecimal (0x<size>)]" \
--changed"[Use the changed timestamp field]" \
{-g,--group}"[List each file's group]" \
{-h,--header}"[Add a header row to each column]" \
Expand Down
3 changes: 3 additions & 0 deletions man/eza.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ These options are available when running with `--long` (`-l`):
`-B`, `--bytes`
: List file sizes in bytes, without any prefixes.

`--hex`
: List file sizes in hexadecimal (0x<size>).

`--changed`
: Use the changed timestamp field.

Expand Down
3 changes: 2 additions & 1 deletion src/options/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const SORTS: Values = &[ "name", "Name", "size", "extension",
// display options
pub static BINARY: Arg = Arg { short: Some(b'b'), long: "binary", takes_value: TakesValue::Forbidden };
pub static BYTES: Arg = Arg { short: Some(b'B'), long: "bytes", takes_value: TakesValue::Forbidden };
pub static HEX: Arg = Arg { short: None, long: "hex", takes_value: TakesValue::Forbidden };
pub static GROUP: Arg = Arg { short: Some(b'g'), long: "group", takes_value: TakesValue::Forbidden };
pub static NUMERIC: Arg = Arg { short: Some(b'n'), long: "numeric", takes_value: TakesValue::Forbidden };
pub static HEADER: Arg = Arg { short: Some(b'h'), long: "header", takes_value: TakesValue::Forbidden };
Expand Down Expand Up @@ -108,7 +109,7 @@ pub static ALL_ARGS: Args = Args(&[
&ALL, &ALMOST_ALL, &TREAT_DIRS_AS_FILES, &LIST_DIRS, &LEVEL, &REVERSE, &SORT, &DIRS_FIRST, &DIRS_LAST,
&IGNORE_GLOB, &GIT_IGNORE, &ONLY_DIRS, &ONLY_FILES,

&BINARY, &BYTES, &GROUP, &NUMERIC, &HEADER, &ICONS, &INODE, &LINKS, &MODIFIED, &CHANGED,
&BINARY, &BYTES, &HEX, &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,

Expand Down
1 change: 1 addition & 0 deletions src/options/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ static USAGE_PART2: &str = " \
LONG VIEW OPTIONS
-b, --binary list file sizes with binary prefixes
-B, --bytes list file sizes in bytes, without any prefixes
--hex list file sizes in hexadecimal (0x<size>)
-g, --group list each file's group
--smart-group only show group if it has a different name from owner
-h, --header add a header row to each column
Expand Down
17 changes: 11 additions & 6 deletions src/options/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,13 @@ impl Mode {
}

fn strict_check_long_flags(matches: &MatchedFlags<'_>) -> Result<(), OptionsError> {
// If --long hasnt been passed, then check if we need to warn the
// user about flags that wont have any effect.
// If --long hasn't been passed, then check if we need to warn the
// user about flags that won't have any effect.
if matches.is_strict() {
for option in &[
&flags::BINARY,
&flags::BYTES,
&flags::HEX,
&flags::INODE,
&flags::LINKS,
&flags::HEADER,
Expand Down Expand Up @@ -315,19 +316,22 @@ impl Columns {

impl SizeFormat {
/// Determine which file size to use in the file size column based on
/// the users options.
/// the user's options.
///
/// The default mode is to use the decimal prefixes, as they are the
/// most commonly-understood, and dont involve trying to parse large
/// most commonly-understood, and don't involve trying to parse large
/// strings of digits in your head. Changing the format to anything else
/// involves the `--binary` or `--bytes` flags, and these conflict with
/// involves the `--binary`, `--bytes`, or `--hex` flags, and these conflict with
/// each other.
fn deduce(matches: &MatchedFlags<'_>) -> Result<Self, OptionsError> {
let flag = matches.has_where(|f| f.matches(&flags::BINARY) || f.matches(&flags::BYTES))?;
let flag = matches.has_where(|f| {
f.matches(&flags::BINARY) || f.matches(&flags::BYTES) || f.matches(&flags::HEX)
})?;

Ok(match flag {
Some(f) if f.matches(&flags::BINARY) => Self::BinaryBytes,
Some(f) if f.matches(&flags::BYTES) => Self::JustBytes,
Some(f) if f.matches(&flags::HEX) => Self::HexBytes,
_ => Self::DecimalBytes,
})
}
Expand Down Expand Up @@ -541,6 +545,7 @@ mod test {
static TEST_ARGS: &[&Arg] = &[
&flags::BINARY,
&flags::BYTES,
&flags::HEX,
&flags::TIME_STYLE,
&flags::TIME,
&flags::MODIFIED,
Expand Down
12 changes: 12 additions & 0 deletions src/output/render/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ impl f::Blocksize {
// But format the number directly using the locale.
let string = numerics.format_int(size);

return TextCell::paint(colours.blocksize(prefix), string);
}
SizeFormat::HexBytes => {
// Use the binary prefix to select a style.
let prefix = match NumberPrefix::binary(size as f64) {
NumberPrefix::Standalone(_) => None,
NumberPrefix::Prefixed(p, _) => Some(p),
};

// Format as hexadecimal with 0x prefix.
let string = format!("0x{size:x}");

return TextCell::paint(colours.blocksize(prefix), string);
}
};
Expand Down
20 changes: 20 additions & 0 deletions src/output/render/size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,26 @@ impl f::Size {
// But format the number directly using the locale.
let string = numerics.format_int(size);

return if is_gradient_mode {
let csi = color_scale_info.unwrap();
TextCell::paint(
csi.adjust_style(colours.size(prefix), size as f32, csi.size),
string,
)
} else {
TextCell::paint(colours.size(prefix), string)
}
}
SizeFormat::HexBytes => {
// Use the binary prefix to select a style.
let prefix = match NumberPrefix::binary(size as f64) {
NumberPrefix::Standalone(_) => None,
NumberPrefix::Prefixed(p, _) => Some(p),
};

// Format as hexadecimal with 0x prefix.
let string = format!("0x{size:x}");

return if is_gradient_mode {
let csi = color_scale_info.unwrap();
TextCell::paint(
Expand Down
11 changes: 7 additions & 4 deletions src/output/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,17 +241,20 @@ impl Column {
#[allow(clippy::enum_variant_names)]
#[derive(PartialEq, Eq, Debug, Default, Copy, Clone)]
pub enum SizeFormat {
/// Format the file size using **decimal** prefixes, such as kilo,
/// mega, or giga.
/// Format the file size using **decimal** prefixes, such as "kilo",
/// "mega", or "giga".
#[default]
DecimalBytes,

/// Format the file size using **binary** prefixes, such as kibi,
/// mebi, or gibi.
/// Format the file size using **binary** prefixes, such as "kibi",
/// "mebi", or "gibi".
BinaryBytes,

/// Do no formatting and just display the size as a number of bytes.
JustBytes,

/// Display the size as a hexadecimal number (0x prefix).
HexBytes,
}

/// Formatting options for user and group.
Expand Down
Loading