feat(header)!: changed the way header works

header now accept an argument auto, never, always
it is also now deactivated if eza is piped in. If auto is setted

BREAKING_CHANGES:
--header=WHEN (auto, never, always)
header is turned off automatically if eza is piped
This commit is contained in:
MartinFillon 2024-01-07 13:31:34 +01:00
parent e04bdba044
commit e930c2271a
No known key found for this signature in database
GPG key ID: 16DC898F53F94853
33 changed files with 99 additions and 74 deletions

View file

@ -149,7 +149,7 @@ 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 files group
- **-h**, **--header**: add a header row to each column
- **-h when**, **--header=(when)**: when to add a header row to each column (always, auto, never)
- **-H**, **--links**: list each files number of hard links
- **-i**, **--inode**: list each files inode number
- **-m**, **--modified**: use the modified timestamp field

View file

@ -18,6 +18,11 @@ _eza() {
return
;;
--header)
mapfile -t COMPREPLY < <(compgen -W 'always automatic auto never' -- "$cur")
return
;;
-L|--level)
mapfile -t COMPREPLY < <(compgen -W '{0..9}' -- "$cur")
return

View file

@ -90,7 +90,12 @@ complete -c eza -l no-symlinks -d "Do not show symbolic links"
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 -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 header -d "Add a header row to each column" -x -a "
always\t'Always display header'
auto\t'Display header if standard output is a terminal'
automatic\t'Display header if standard output is a terminal'
never\t'Never display header'
"
complete -c eza -s H -l links -d "List each file's number of hard links"
complete -c eza -s i -l inode -d "List each file's inode number"
complete -c eza -s S -l blocksize -d "List each file's size of allocated file system blocks"

View file

@ -37,7 +37,7 @@ export extern "eza" [
--binary(-b) # List file sizes with binary prefixes
--bytes(-B) # List file sizes in bytes, without any prefixes
--group(-g) # List each file's group
--header(-h) # Add a header row to each column
--header(-h) # When to add a header row to each column
--links(-H) # List each file's number of hard links
--inode(-i) # List each file's inode number
--blocksize(-S) # List each file's size of allocated file system blocks

View file

@ -47,7 +47,7 @@ __eza() {
{-B,--bytes}"[List file sizes in bytes, without any prefixes]" \
--changed"[Use the changed timestamp field]" \
{-g,--group}"[List each file's group]" \
{-h,--header}"[Add a header row to each column]" \
{-h,--header}"[When to use header]:(when):(always auto automatic never)" \
{-H,--links}"[List each file's number of hard links]" \
{-i,--inode}"[List each file's inode number]" \
{-m,--modified}"[Use the modified timestamp field]" \

View file

@ -191,9 +191,12 @@ These options are available when running with `--long` (`-l`):
`--smart-group`
: Only show group if it has a different name from owner
`-h`, `--header`
`-h WHEN`, `--header=WHEN`
: Add a header row to each column.
Valid settings are `always`, `automatic` (`auto` for short), and `never`.
The default value is `automatic`.
`-H`, `--links`
: List each files number of hard links.

View file

@ -61,7 +61,7 @@ pub static BINARY: Arg = Arg { short: Some(b'b'), long: "binary", take
pub static BYTES: Arg = Arg { short: Some(b'B'), long: "bytes", 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 };
pub static HEADER: Arg = Arg { short: Some(b'h'), long: "header", takes_value: TakesValue::Optional(Some(WHEN), "auto") };
pub static ICONS: Arg = Arg { short: None, long: "icons", takes_value: TakesValue::Optional(Some(WHEN), "auto")};
pub static INODE: Arg = Arg { short: Some(b'i'), long: "inode", takes_value: TakesValue::Forbidden };
pub static LINKS: Arg = Arg { short: Some(b'H'), long: "links", takes_value: TakesValue::Forbidden };

View file

@ -66,7 +66,7 @@ LONG VIEW OPTIONS
-B, --bytes list file sizes in bytes, without any prefixes
-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, --header=WHEN add a header row to each column
-H, --links list each file's number of hard links
-i, --inode list each file's inode number
-M, --mounts show mount details (Linux and Mac only)
@ -88,7 +88,7 @@ LONG VIEW OPTIONS
--no-filesize suppress the filesize field
--no-user suppress the user field
--no-time suppress the time field
--stdin read file names from stdin, one per line or other separator
--stdin read file names from stdin, one per line or other separator
specified in environment";
static GIT_VIEW_HELP: &str = " \

View file

@ -5,6 +5,7 @@
// SPDX-FileCopyrightText: 2014 Benjamin Sago
// SPDX-License-Identifier: MIT
use std::ffi::OsString;
use std::io;
use crate::fs::feature::xattr;
use crate::options::parser::MatchedFlags;
@ -17,6 +18,7 @@ use crate::output::table::{
};
use crate::output::time::TimeFormat;
use crate::output::{details, grid, Mode, TerminalWidth, View};
use std::io::IsTerminal;
impl View {
pub fn deduce<V: Vars>(matches: &MatchedFlags<'_>, vars: &V) -> Result<Self, OptionsError> {
@ -110,7 +112,6 @@ impl Mode {
&flags::BYTES,
&flags::INODE,
&flags::LINKS,
&flags::HEADER,
&flags::BLOCKSIZE,
&flags::TIME,
&flags::GROUP,
@ -122,6 +123,10 @@ impl Mode {
}
}
if matches.has(&flags::HEADER)? {
return Err(OptionsError::Useless(&flags::HEADER, false, &flags::LONG));
}
if matches.has(&flags::GIT)? && !matches.has(&flags::NO_GIT)? {
return Err(OptionsError::Useless(&flags::GIT, false, &flags::LONG));
} else if matches.has(&flags::LEVEL)?
@ -176,7 +181,7 @@ impl details::Options {
Ok(details::Options {
table: Some(TableOptions::deduce(matches, vars)?),
header: matches.has(&flags::HEADER)?,
header: Self::deduce_header(matches)?,
xattr: xattr::ENABLED && matches.has(&flags::EXTENDED)?,
secattr: xattr::ENABLED && matches.has(&flags::SECURITY_CONTEXT)?,
mounts: matches.has(&flags::MOUNTS)?,
@ -184,6 +189,21 @@ impl details::Options {
follow_links: matches.has(&flags::FOLLOW_LINKS)?,
})
}
fn deduce_header(matches: &MatchedFlags<'_>) -> Result<bool, OptionsError> {
let word = if let Some(w) = matches.get(&flags::HEADER)? {
w.to_os_string()
} else {
return Ok(false);
};
match word.to_string_lossy().as_ref() {
"auto" => Ok(io::stdout().is_terminal()),
"always" => Ok(true),
"never" => Ok(false),
_ => Err(OptionsError::BadArgument(&flags::HEADER, word))?,
}
}
}
impl TerminalWidth {
@ -773,7 +793,7 @@ mod test {
#[cfg(feature = "git")]
test!(just_git: Mode <- ["--git"], None; Last => like Ok(Mode::Grid(_)));
test!(just_header_2: Mode <- ["--header"], None; Complain => err OptionsError::Useless(&flags::HEADER, false, &flags::LONG));
//test!(just_header_2: Mode <- ["--header"], None; Complain => err OptionsError::Useless(&flags::HEADER, false, &flags::LONG));
test!(just_group_2: Mode <- ["--group"], None; Complain => err OptionsError::Useless(&flags::GROUP, false, &flags::LONG));
test!(just_inode_2: Mode <- ["--inode"], None; Complain => err OptionsError::Useless(&flags::INODE, false, &flags::LONG));
test!(just_links_2: Mode <- ["--links"], None; Complain => err OptionsError::Useless(&flags::LINKS, false, &flags::LONG));

View file

@ -1,10 +1,9 @@
Permissions Size User Date Modified Name
drwxr-xr-x - nixbld 1 Jan 1970 git
drwxr-xr-x - nixbld 1 Jan 1970 grid
drwxr-xr-x - nixbld 1 Jan 1970 group
drwxr-xr-x - nixbld 1 Jan 1970 icons
drwxr-xr-x - nixbld 1 Jan 1970 perms
drwxr-xr-x - nixbld 1 Jan 1970 size
drwxr-xr-x - nixbld 1 Jan 1970 specials
drwxr-xr-x - nixbld 1 Jan 1970 symlinks
drwxr-xr-x - nixbld 1 Jan 1970 time
drwxr-xr-x - nixbld 1 Jan 1970 git
drwxr-xr-x - nixbld 1 Jan 1970 grid
drwxr-xr-x - nixbld 1 Jan 1970 group
drwxr-xr-x - nixbld 1 Jan 1970 icons
drwxr-xr-x - nixbld 1 Jan 1970 perms
drwxr-xr-x - nixbld 1 Jan 1970 size
drwxr-xr-x - nixbld 1 Jan 1970 specials
drwxr-xr-x - nixbld 1 Jan 1970 symlinks
drwxr-xr-x - nixbld 1 Jan 1970 time

View file

@ -1,10 +1,9 @@
Size Name
- git
- grid
- group
- icons
- perms
- size
- specials
- symlinks
- time
- git
- grid
- group
- icons
- perms
- size
- specials
- symlinks
- time

View file

@ -1,3 +1,3 @@
thread 'main' panicked at src/options/view.rs:357:21:
thread 'main' panicked at src/options/view.rs:377:21:
Custom timestamp format is empty, please supply a chrono format string after the plus sign.
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

View file

@ -1,3 +1,3 @@
thread 'main' panicked at src/options/view.rs:355:47:
thread 'main' panicked at src/options/view.rs:375:47:
Custom timestamp format is empty, please supply a chrono format string after the plus sign.
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

View file

@ -1,3 +1,3 @@
thread 'main' panicked at src/options/view.rs:371:25:
thread 'main' panicked at src/options/view.rs:391:25:
Custom timestamp format for recent files is empty, please supply a chrono format string at the second line.
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

View file

@ -1,9 +1,9 @@
drwxr-xr-x - nixbld 1 Jan 1970 icons
drwxr-xr-x - nixbld 1 Jan 1970 time
drwxr-xr-x - nixbld 1 Jan 1970 size
drwxr-xr-x - nixbld 1 Jan 1970 group
drwxr-xr-x - nixbld 1 Jan 1970 perms
drwxr-xr-x - nixbld 1 Jan 1970 symlinks
drwxr-xr-x - nixbld 1 Jan 1970 specials
drwxr-xr-x - nixbld 1 Jan 1970 git
drwxr-xr-x - nixbld 1 Jan 1970 group
drwxr-xr-x - nixbld 1 Jan 1970 grid

View file

@ -1,9 +1,9 @@
drwxr-xr-x - nixbld 1 Jan 1970 icons
drwxr-xr-x - nixbld 1 Jan 1970 time
drwxr-xr-x - nixbld 1 Jan 1970 size
drwxr-xr-x - nixbld 1 Jan 1970 group
drwxr-xr-x - nixbld 1 Jan 1970 perms
drwxr-xr-x - nixbld 1 Jan 1970 symlinks
drwxr-xr-x - nixbld 1 Jan 1970 specials
drwxr-xr-x - nixbld 1 Jan 1970 git
drwxr-xr-x - nixbld 1 Jan 1970 group
drwxr-xr-x - nixbld 1 Jan 1970 grid

View file

@ -1,9 +1,9 @@
drwxr-xr-x - nixbld 1 Jan 1970 icons
drwxr-xr-x - nixbld 1 Jan 1970 time
drwxr-xr-x - nixbld 1 Jan 1970 size
drwxr-xr-x - nixbld 1 Jan 1970 group
drwxr-xr-x - nixbld 1 Jan 1970 perms
drwxr-xr-x - nixbld 1 Jan 1970 symlinks
drwxr-xr-x - nixbld 1 Jan 1970 specials
drwxr-xr-x - nixbld 1 Jan 1970 git
drwxr-xr-x - nixbld 1 Jan 1970 group
drwxr-xr-x - nixbld 1 Jan 1970 grid

View file

@ -1,9 +1,9 @@
drwxr-xr-x - nixbld 1 Jan 1970 icons
drwxr-xr-x - nixbld 1 Jan 1970 time
drwxr-xr-x - nixbld 1 Jan 1970 size
drwxr-xr-x - nixbld 1 Jan 1970 group
drwxr-xr-x - nixbld 1 Jan 1970 perms
drwxr-xr-x - nixbld 1 Jan 1970 symlinks
drwxr-xr-x - nixbld 1 Jan 1970 specials
drwxr-xr-x - nixbld 1 Jan 1970 git
drwxr-xr-x - nixbld 1 Jan 1970 group
drwxr-xr-x - nixbld 1 Jan 1970 grid

View file

@ -50,7 +50,7 @@ LONG VIEW OPTIONS
-B, --bytes list file sizes in bytes, without any prefixes
-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, --header=WHEN add a header row to each column
-H, --links list each file's number of hard links
-i, --inode list each file's inode number
-M, --mounts show mount details (Linux and Mac only)
@ -72,7 +72,7 @@ LONG VIEW OPTIONS
--no-filesize suppress the filesize field
--no-user suppress the user field
--no-time suppress the time field
--stdin read file names from stdin, one per line or other separator
--stdin read file names from stdin, one per line or other separator
specified in environment
--git list each file's Git status, if tracked or ignored
--no-git suppress Git status (always overrides --git,

View file

@ -1,8 +1,5 @@
git time
grid
group
icons
perms
size
specials
symlinks
git size
grid specials
group symlinks
icons time
perms

View file

@ -1,9 +1,9 @@
drwxr-xr-x - nixbld 1 Jan 1970 icons
drwxr-xr-x - nixbld 1 Jan 1970 time
drwxr-xr-x - nixbld 1 Jan 1970 size
drwxr-xr-x - nixbld 1 Jan 1970 group
drwxr-xr-x - nixbld 1 Jan 1970 perms
drwxr-xr-x - nixbld 1 Jan 1970 symlinks
drwxr-xr-x - nixbld 1 Jan 1970 specials
drwxr-xr-x - nixbld 1 Jan 1970 git
drwxr-xr-x - nixbld 1 Jan 1970 group
drwxr-xr-x - nixbld 1 Jan 1970 grid

View file

@ -1,9 +1,9 @@
drwxr-xr-x - nixbld 1 Jan 1970 icons
drwxr-xr-x - nixbld 1 Jan 1970 time
drwxr-xr-x - nixbld 1 Jan 1970 size
drwxr-xr-x - nixbld 1 Jan 1970 group
drwxr-xr-x - nixbld 1 Jan 1970 perms
drwxr-xr-x - nixbld 1 Jan 1970 symlinks
drwxr-xr-x - nixbld 1 Jan 1970 specials
drwxr-xr-x - nixbld 1 Jan 1970 git
drwxr-xr-x - nixbld 1 Jan 1970 group
drwxr-xr-x - nixbld 1 Jan 1970 grid

View file

@ -1,9 +1,9 @@
drwxr-xr-x - nixbld 1 Jan 1970 icons
drwxr-xr-x - nixbld 1 Jan 1970 time
drwxr-xr-x - nixbld 1 Jan 1970 size
drwxr-xr-x - nixbld 1 Jan 1970 group
drwxr-xr-x - nixbld 1 Jan 1970 perms
drwxr-xr-x - nixbld 1 Jan 1970 symlinks
drwxr-xr-x - nixbld 1 Jan 1970 specials
drwxr-xr-x - nixbld 1 Jan 1970 git
drwxr-xr-x - nixbld 1 Jan 1970 group
drwxr-xr-x - nixbld 1 Jan 1970 grid

View file

@ -1,9 +1,9 @@
drwxr-xr-x - nixbld 1 Jan 1970 icons
drwxr-xr-x - nixbld 1 Jan 1970 time
drwxr-xr-x - nixbld 1 Jan 1970 size
drwxr-xr-x - nixbld 1 Jan 1970 group
drwxr-xr-x - nixbld 1 Jan 1970 perms
drwxr-xr-x - nixbld 1 Jan 1970 symlinks
drwxr-xr-x - nixbld 1 Jan 1970 specials
drwxr-xr-x - nixbld 1 Jan 1970 git
drwxr-xr-x - nixbld 1 Jan 1970 group
drwxr-xr-x - nixbld 1 Jan 1970 grid

View file

@ -1,9 +1,9 @@
drwxr-xr-x - nixbld 1 Jan 1970 icons
drwxr-xr-x - nixbld 1 Jan 1970 time
drwxr-xr-x - nixbld 1 Jan 1970 size
drwxr-xr-x - nixbld 1 Jan 1970 group
drwxr-xr-x - nixbld 1 Jan 1970 perms
drwxr-xr-x - nixbld 1 Jan 1970 symlinks
drwxr-xr-x - nixbld 1 Jan 1970 specials
drwxr-xr-x - nixbld 1 Jan 1970 git
drwxr-xr-x - nixbld 1 Jan 1970 group
drwxr-xr-x - nixbld 1 Jan 1970 grid

View file

@ -1,9 +1,9 @@
drwxr-xr-x - nixbld 1 Jan 1970 perms
drwxr-xr-x - nixbld 1 Jan 1970 grid
drwxr-xr-x - nixbld 1 Jan 1970 git
drwxr-xr-x - nixbld 1 Jan 1970 specials
drwxr-xr-x - nixbld 1 Jan 1970 symlinks
drwxr-xr-x - nixbld 1 Jan 1970 perms
drwxr-xr-x - nixbld 1 Jan 1970 group
drwxr-xr-x - nixbld 1 Jan 1970 size
drwxr-xr-x - nixbld 1 Jan 1970 time
drwxr-xr-x - nixbld 1 Jan 1970 grid
drwxr-xr-x - nixbld 1 Jan 1970 git
drwxr-xr-x - nixbld 1 Jan 1970 symlinks
drwxr-xr-x - nixbld 1 Jan 1970 icons

View file

@ -1,3 +1,3 @@
eza - A modern, maintained replacement for ls
v0.20.13 [+git] (pre-release debug build!)
v0.21.3 [+git] (pre-release debug build!)
https://github.com/eza-community/eza

View file

@ -1,8 +1,5 @@
git time
grid
group
icons
perms
size
specials
symlinks
git size
grid specials
group symlinks
icons time
perms

View file

@ -1,9 +1,9 @@
drwxr-xr-x - nixbld 1 Jan 1970 icons
drwxr-xr-x - nixbld 1 Jan 1970 time
drwxr-xr-x - nixbld 1 Jan 1970 size
drwxr-xr-x - nixbld 1 Jan 1970 group
drwxr-xr-x - nixbld 1 Jan 1970 perms
drwxr-xr-x - nixbld 1 Jan 1970 symlinks
drwxr-xr-x - nixbld 1 Jan 1970 specials
drwxr-xr-x - nixbld 1 Jan 1970 git
drwxr-xr-x - nixbld 1 Jan 1970 group
drwxr-xr-x - nixbld 1 Jan 1970 grid

View file

@ -1,3 +1,3 @@
eza - A modern, maintained replacement for ls
v0.20.13 [+git] (pre-release debug build!)
v0.21.3 [+git] (pre-release debug build!)
https://github.com/eza-community/eza

View file

@ -1,9 +1,9 @@
drwxr-xr-x - nixbld 1 Jan 1970 icons
drwxr-xr-x - nixbld 1 Jan 1970 time
drwxr-xr-x - nixbld 1 Jan 1970 size
drwxr-xr-x - nixbld 1 Jan 1970 group
drwxr-xr-x - nixbld 1 Jan 1970 perms
drwxr-xr-x - nixbld 1 Jan 1970 symlinks
drwxr-xr-x - nixbld 1 Jan 1970 specials
drwxr-xr-x - nixbld 1 Jan 1970 git
drwxr-xr-x - nixbld 1 Jan 1970 group
drwxr-xr-x - nixbld 1 Jan 1970 grid

View file

@ -1,9 +1,9 @@
drwxr-xr-x - nixbld 1 Jan 1970 perms
drwxr-xr-x - nixbld 1 Jan 1970 grid
drwxr-xr-x - nixbld 1 Jan 1970 git
drwxr-xr-x - nixbld 1 Jan 1970 specials
drwxr-xr-x - nixbld 1 Jan 1970 symlinks
drwxr-xr-x - nixbld 1 Jan 1970 perms
drwxr-xr-x - nixbld 1 Jan 1970 group
drwxr-xr-x - nixbld 1 Jan 1970 size
drwxr-xr-x - nixbld 1 Jan 1970 time
drwxr-xr-x - nixbld 1 Jan 1970 grid
drwxr-xr-x - nixbld 1 Jan 1970 git
drwxr-xr-x - nixbld 1 Jan 1970 symlinks
drwxr-xr-x - nixbld 1 Jan 1970 icons

View file

@ -1,9 +1,9 @@
drwxr-xr-x - nixbld 1 Jan 1970 icons
drwxr-xr-x - nixbld 1 Jan 1970 time
drwxr-xr-x - nixbld 1 Jan 1970 size
drwxr-xr-x - nixbld 1 Jan 1970 group
drwxr-xr-x - nixbld 1 Jan 1970 perms
drwxr-xr-x - nixbld 1 Jan 1970 symlinks
drwxr-xr-x - nixbld 1 Jan 1970 specials
drwxr-xr-x - nixbld 1 Jan 1970 git
drwxr-xr-x - nixbld 1 Jan 1970 group
drwxr-xr-x - nixbld 1 Jan 1970 grid