mirror of
https://github.com/eza-community/eza
synced 2024-10-02 22:23:45 +00:00
feat(flags)!: add --classify=always,auto,never
BREAKING CHANGE: --classify now accepts WHEN (always,auto,never). When none specified defaults to "auto" instead of previous "always" behavior
This commit is contained in:
parent
3c31fe09d2
commit
367ff558a6
|
@ -88,7 +88,7 @@ eza’s options are almost, but not quite, entirely unlike `ls`’s.
|
||||||
- **-R**, **--recurse**: recurse into directories
|
- **-R**, **--recurse**: recurse into directories
|
||||||
- **-T**, **--tree**: recurse into directories as a tree
|
- **-T**, **--tree**: recurse into directories as a tree
|
||||||
- **-x**, **--across**: sort the grid across, rather than downwards
|
- **-x**, **--across**: sort the grid across, rather than downwards
|
||||||
- **-F**, **--classify**: display type indicator by file names
|
- **-F**, **--classify=(when)**: display type indicator by file names (always, auto, never)
|
||||||
- **--colo[u]r=(when)**: when to use terminal colours (always, auto, never)
|
- **--colo[u]r=(when)**: when to use terminal colours (always, auto, never)
|
||||||
- **--colo[u]r-scale=(field)**: highlight levels of `field` distinctly(all, age, size)
|
- **--colo[u]r-scale=(field)**: highlight levels of `field` distinctly(all, age, size)
|
||||||
- **--color-scale-mode=(mode)**: use gradient or fixed colors in --color-scale. valid options are `fixed` or `gradient`
|
- **--color-scale-mode=(mode)**: use gradient or fixed colors in --color-scale. valid options are `fixed` or `gradient`
|
||||||
|
|
|
@ -19,7 +19,7 @@ __eza() {
|
||||||
{-R,--recurse}"[Recurse into directories]" \
|
{-R,--recurse}"[Recurse into directories]" \
|
||||||
{-T,--tree}"[Recurse into directories as a tree]" \
|
{-T,--tree}"[Recurse into directories as a tree]" \
|
||||||
{-X,--dereference}"[Dereference symbolic links when displaying information]" \
|
{-X,--dereference}"[Dereference symbolic links when displaying information]" \
|
||||||
{-F,--classify}"[Display type indicator by file names]" \
|
{-F,--classify}"[Display type indicator by file names]:(when):(always auto automatic never)" \
|
||||||
--colo{,u}r="[When to use terminal colours]:(when):(always auto automatic never)" \
|
--colo{,u}r="[When to use terminal colours]:(when):(always auto automatic never)" \
|
||||||
--colo{,u}r-scale"[highlight levels of 'field' distinctly]:(fields):(all age size)" \
|
--colo{,u}r-scale"[highlight levels of 'field' distinctly]:(fields):(all age size)" \
|
||||||
--colo{,u}r-scale-mode"[Use gradient or fixed colors in --color-scale]:(mode):(fixed gradient)" \
|
--colo{,u}r-scale-mode"[Use gradient or fixed colors in --color-scale]:(mode):(fixed gradient)" \
|
||||||
|
|
|
@ -54,9 +54,14 @@ DISPLAY OPTIONS
|
||||||
`-1`, `--oneline`
|
`-1`, `--oneline`
|
||||||
: Display one entry per line.
|
: Display one entry per line.
|
||||||
|
|
||||||
`-F`, `--classify`
|
`-F`, `--classify=WHEN`
|
||||||
: Display file kind indicators next to file names.
|
: Display file kind indicators next to file names.
|
||||||
|
|
||||||
|
Valid settings are ‘`always`’, ‘`automatic`’ (or ‘`auto`’ for short), and ‘`never`’.
|
||||||
|
The default value is ‘`automatic`’.
|
||||||
|
|
||||||
|
The default behavior (`automatic` or `auto`) will display file kind indicators only when the standard output is connected to a real terminal. If `eza` is ran while in a `tty`, or the output of `eza` is either redirected to a file or piped into another program, file kind indicators will not be used. Setting this option to ‘`always`’ causes `eza` to always display file kind indicators, while ‘`never`’ disables the use of file kind indicators.
|
||||||
|
|
||||||
`-G`, `--grid`
|
`-G`, `--grid`
|
||||||
: Display entries as a grid (default).
|
: Display entries as a grid (default).
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,12 @@ commands:
|
||||||
? - -F
|
? - -F
|
||||||
- --classify
|
- --classify
|
||||||
:
|
:
|
||||||
|
? - -F
|
||||||
|
- --classify
|
||||||
|
: values:
|
||||||
|
- auto
|
||||||
|
- always
|
||||||
|
- never
|
||||||
? - null
|
? - null
|
||||||
- --color
|
- --color
|
||||||
: values:
|
: values:
|
||||||
|
|
|
@ -28,12 +28,17 @@ impl Options {
|
||||||
|
|
||||||
impl Classify {
|
impl Classify {
|
||||||
fn deduce(matches: &MatchedFlags<'_>) -> Result<Self, OptionsError> {
|
fn deduce(matches: &MatchedFlags<'_>) -> Result<Self, OptionsError> {
|
||||||
let flagged = matches.has(&flags::CLASSIFY)?;
|
let mode_opt = matches.get(&flags::CLASSIFY)?;
|
||||||
|
|
||||||
if flagged {
|
match mode_opt {
|
||||||
Ok(Self::AddFileIndicators)
|
Some(word) => match word.to_str() {
|
||||||
} else {
|
Some("always") => Ok(Self::AddFileIndicators),
|
||||||
Ok(Self::JustFilenames)
|
Some("auto" | "automatic") => Ok(Self::AutomaticAddFileIndicators),
|
||||||
|
Some("never") => Ok(Self::JustFilenames),
|
||||||
|
_ => Err(OptionsError::BadArgument(&flags::CLASSIFY, word.into())),
|
||||||
|
},
|
||||||
|
// No flag given, default to just filenames
|
||||||
|
None => Ok(Self::JustFilenames),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ pub static GRID: Arg = Arg { short: Some(b'G'), long: "grid", take
|
||||||
pub static ACROSS: Arg = Arg { short: Some(b'x'), long: "across", takes_value: TakesValue::Forbidden };
|
pub static ACROSS: Arg = Arg { short: Some(b'x'), long: "across", takes_value: TakesValue::Forbidden };
|
||||||
pub static RECURSE: Arg = Arg { short: Some(b'R'), long: "recurse", takes_value: TakesValue::Forbidden };
|
pub static RECURSE: Arg = Arg { short: Some(b'R'), long: "recurse", takes_value: TakesValue::Forbidden };
|
||||||
pub static TREE: Arg = Arg { short: Some(b'T'), long: "tree", takes_value: TakesValue::Forbidden };
|
pub static TREE: Arg = Arg { short: Some(b'T'), long: "tree", takes_value: TakesValue::Forbidden };
|
||||||
pub static CLASSIFY: Arg = Arg { short: Some(b'F'), long: "classify", takes_value: TakesValue::Forbidden };
|
pub static CLASSIFY: Arg = Arg { short: Some(b'F'), long: "classify", takes_value: TakesValue::Optional(Some(WHEN), "auto") };
|
||||||
pub static DEREF_LINKS: Arg = Arg { short: Some(b'X'), long: "dereference", takes_value: TakesValue::Forbidden };
|
pub static DEREF_LINKS: Arg = Arg { short: Some(b'X'), long: "dereference", takes_value: TakesValue::Forbidden };
|
||||||
pub static WIDTH: Arg = Arg { short: Some(b'w'), long: "width", takes_value: TakesValue::Necessary(None) };
|
pub static WIDTH: Arg = Arg { short: Some(b'w'), long: "width", takes_value: TakesValue::Necessary(None) };
|
||||||
pub static NO_QUOTES: Arg = Arg { short: None, long: "no-quotes", takes_value: TakesValue::Forbidden };
|
pub static NO_QUOTES: Arg = Arg { short: None, long: "no-quotes", takes_value: TakesValue::Forbidden };
|
||||||
|
|
|
@ -19,7 +19,7 @@ DISPLAY OPTIONS
|
||||||
-R, --recurse recurse into directories
|
-R, --recurse recurse into directories
|
||||||
-T, --tree recurse into directories as a tree
|
-T, --tree recurse into directories as a tree
|
||||||
-X, --dereference dereference symbolic links when displaying information
|
-X, --dereference dereference symbolic links when displaying information
|
||||||
-F, --classify display type indicator by file names
|
-F, --classify=WHEN display type indicator by file names (always, auto, never)
|
||||||
--colo[u]r=WHEN when to use terminal colours (always, auto, never)
|
--colo[u]r=WHEN when to use terminal colours (always, auto, never)
|
||||||
--colo[u]r-scale highlight levels of 'field' distinctly(all, age, size)
|
--colo[u]r-scale highlight levels of 'field' distinctly(all, age, size)
|
||||||
--colo[u]r-scale-mode use gradient or fixed colors in --color-scale (fixed, gradient)
|
--colo[u]r-scale-mode use gradient or fixed colors in --color-scale (fixed, gradient)
|
||||||
|
|
|
@ -74,9 +74,12 @@ pub enum Classify {
|
||||||
/// Just display the file names, without any characters.
|
/// Just display the file names, without any characters.
|
||||||
JustFilenames,
|
JustFilenames,
|
||||||
|
|
||||||
/// Add a character after the file name depending on what class of file
|
/// Always add a character after the file name depending on what class of
|
||||||
/// it is.
|
/// file it is.
|
||||||
AddFileIndicators,
|
AddFileIndicators,
|
||||||
|
|
||||||
|
// Like previous, but only when output is going to a terminal, not otherwise.
|
||||||
|
AutomaticAddFileIndicators,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Classify {
|
impl Default for Classify {
|
||||||
|
@ -189,6 +192,12 @@ impl<'a, 'dir, C: Colours> FileName<'a, 'dir, C> {
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let should_add_classify_char = match self.options.classify {
|
||||||
|
Classify::AddFileIndicators => true,
|
||||||
|
Classify::AutomaticAddFileIndicators if self.options.is_a_tty => true,
|
||||||
|
_ => false,
|
||||||
|
};
|
||||||
|
|
||||||
if let Some(spaces_count) = spaces_count_opt {
|
if let Some(spaces_count) = spaces_count_opt {
|
||||||
let style = iconify_style(self.style());
|
let style = iconify_style(self.style());
|
||||||
let file_icon = icon_for_file(self.file).to_string();
|
let file_icon = icon_for_file(self.file).to_string();
|
||||||
|
@ -248,7 +257,7 @@ impl<'a, 'dir, C: Colours> FileName<'a, 'dir, C> {
|
||||||
bits.push(bit);
|
bits.push(bit);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Classify::AddFileIndicators = self.options.classify {
|
if should_add_classify_char {
|
||||||
if let Some(class) = self.classify_char(target) {
|
if let Some(class) = self.classify_char(target) {
|
||||||
bits.push(Style::default().paint(class));
|
bits.push(Style::default().paint(class));
|
||||||
}
|
}
|
||||||
|
@ -274,7 +283,7 @@ impl<'a, 'dir, C: Colours> FileName<'a, 'dir, C> {
|
||||||
// Do nothing — the error gets displayed on the next line
|
// Do nothing — the error gets displayed on the next line
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if let Classify::AddFileIndicators = self.options.classify {
|
} else if should_add_classify_char {
|
||||||
if let Some(class) = self.classify_char(self.file) {
|
if let Some(class) = self.classify_char(self.file) {
|
||||||
bits.push(Style::default().paint(class));
|
bits.push(Style::default().paint(class));
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ DISPLAY OPTIONS
|
||||||
-R, --recurse recurse into directories
|
-R, --recurse recurse into directories
|
||||||
-T, --tree recurse into directories as a tree
|
-T, --tree recurse into directories as a tree
|
||||||
-X, --dereference dereference symbolic links when displaying information
|
-X, --dereference dereference symbolic links when displaying information
|
||||||
-F, --classify display type indicator by file names
|
-F, --classify=WHEN display type indicator by file names
|
||||||
--colo[u]r=WHEN when to use terminal colours (always, auto, never)
|
--colo[u]r=WHEN when to use terminal colours (always, auto, never)
|
||||||
--colo[u]r-scale highlight levels of 'field' distinctly(all, age, size)
|
--colo[u]r-scale highlight levels of 'field' distinctly(all, age, size)
|
||||||
--colo[u]r-scale-mode use gradient or fixed colors in --color-scale (fixed, gradient)
|
--colo[u]r-scale-mode use gradient or fixed colors in --color-scale (fixed, gradient)
|
||||||
|
|
|
@ -13,7 +13,7 @@ DISPLAY OPTIONS
|
||||||
-R, --recurse recurse into directories
|
-R, --recurse recurse into directories
|
||||||
-T, --tree recurse into directories as a tree
|
-T, --tree recurse into directories as a tree
|
||||||
-X, --dereference dereference symbolic links when displaying information
|
-X, --dereference dereference symbolic links when displaying information
|
||||||
-F, --classify display type indicator by file names
|
-F, --classify=WHEN display type indicator by file names
|
||||||
--colo[u]r=WHEN when to use terminal colours (always, auto, never)
|
--colo[u]r=WHEN when to use terminal colours (always, auto, never)
|
||||||
--colo[u]r-scale highlight levels of 'field' distinctly(all, age, size)
|
--colo[u]r-scale highlight levels of 'field' distinctly(all, age, size)
|
||||||
--colo[u]r-scale-mode use gradient or fixed colors in --color-scale (fixed, gradient)
|
--colo[u]r-scale-mode use gradient or fixed colors in --color-scale (fixed, gradient)
|
||||||
|
|
Loading…
Reference in a new issue