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
6 changes: 2 additions & 4 deletions man/eza_colors-explanation.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ eza_colors-explanation — more details on customizing eza colors
eza provides its own built\-in set of file extension mappings that cover a large range of common file extensions, including documents, archives, media, and temporary files.
Any mappings in the environment variables will override this default set: running eza with `LS_COLORS="*.zip=32"` will turn zip files green but leave the colours of other compressed files alone.

You can also disable this built\-in set entirely by including a
`reset` entry at the beginning of `EZA_COLORS`.
So setting `EZA_COLORS="reset:*.txt=31"` will highlight only text
files; setting `EZA_COLORS="reset"` will highlight nothing.
You can also disable eza's built\-in mappings entirely by including a `reset` entry at the beginning of `EZA_COLORS`.
So setting `EZA_COLORS="reset:*.txt=31"` will highlight only text files in addition to any styles in `LS_COLORS`; setting `EZA_COLORS="reset"` disables eza's built\-ins completely.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
So setting `EZA_COLORS="reset:*.txt=31"` will highlight only text files in addition to any styles in `LS_COLORS`; setting `EZA_COLORS="reset"` disables eza's built\-ins completely.
So setting `EZA_COLORS="reset:*.txt=31"` will highlight only text files in addition to any styles in `LS_COLORS`; setting `EZA_COLORS="reset"` disables eza's built\-ins completely.
However, setting `EZA_COLORS="reset"` is not yet supported when a configuration file (`theme.yml`) is in use.


## Examples

Expand Down
4 changes: 2 additions & 2 deletions man/eza_colors.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,8 @@ Many terminals will treat bolded text as a different colour, or at least provide
eza provides its own built-in set of file extension mappings that cover a large range of common file extensions, including documents, archives, media, and temporary files.
Any mappings in the environment variables will override this default set: running eza with `LS_COLORS="*.zip=32"` will turn zip files green but leave the colours of other compressed files alone.

You can also disable this built-in set entirely by including a `reset` entry at the beginning of `EZA_COLORS`.
So setting `EZA_COLORS="reset:*.txt=31"` will highlight only text files; setting `EZA_COLORS="reset"` will highlight nothing.
You can also disable eza's built-in mapping entirely by including a `reset` entry at the beginning of `EZA_COLORS`.
So setting `EZA_COLORS="reset:*.txt=31"` will highlight only text files in addition to any styles in `LS_COLORS`; setting `EZA_COLORS="reset"` disables eza's built-ins completely.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
So setting `EZA_COLORS="reset:*.txt=31"` will highlight only text files in addition to any styles in `LS_COLORS`; setting `EZA_COLORS="reset"` disables eza's built-ins completely.
So setting `EZA_COLORS="reset:*.txt=31"` will highlight only text files in addition to any styles in `LS_COLORS`; setting `EZA_COLORS="reset"` disables eza's built-ins completely.
However, setting `EZA_COLORS="reset"` is not yet supported when a configuration file (`theme.yml`) is in use.



AUTHOR
Expand Down
13 changes: 10 additions & 3 deletions src/theme/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ impl Options {
}

fn default_theme(&self) -> Theme {
let mut ui = UiStyles::default_theme(self.colour_scale);
let mut ui = if self.definitions.should_reset_styles() {
UiStyles::plain()
} else {
UiStyles::default_theme(self.colour_scale)
};
let (exts, use_default_filetypes) = self.definitions.parse_color_vars(&mut ui);
let exts: Box<dyn FileStyle> = match (exts.is_non_empty(), use_default_filetypes) {
(false, false) => Box::new(NoFileStyle),
Expand All @@ -122,6 +126,10 @@ impl Options {
}

impl Definitions {
fn should_reset_styles(&self) -> bool {
matches!(&self.exa, Some(exa) if exa == "reset" || exa.starts_with("reset:"))
}

/// Parse the environment variables into `LS_COLORS` pairs, putting file glob
/// colours into the `ExtensionMappings` that gets returned, and using the
/// two-character UI codes to modify the mutable `Colours`.
Expand Down Expand Up @@ -151,8 +159,7 @@ impl Definitions {
let mut use_default_filetypes = true;

if let Some(exa) = &self.exa {
// Is this hacky? Yes.
if exa == "reset" || exa.starts_with("reset:") {
if self.should_reset_styles() {
use_default_filetypes = false;
}

Expand Down
Empty file.
1 change: 1 addition & 0 deletions tests/cmd/eza_colors_reset_custom_unix.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[..][..][..] index.svg
14 changes: 14 additions & 0 deletions tests/cmd/eza_colors_reset_custom_unix.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# With reset, only explicitly defined keys should be colored.
# We use `xx` so permission punctuation is colored across Unix and Windows.
bin.name = "eza"
args = "--color always --long --no-user --no-filesize --no-time index.svg"

[fs]
cwd = "../itest"

[env]
remove = ["LS_COLORS"]

[env.add]
EZA_COLORS = "reset:xx=31"
EZA_CONFIG_DIR = "tests/itest"
Empty file.
1 change: 1 addition & 0 deletions tests/cmd/eza_colors_reset_unix.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[..][..][..]index.svg
11 changes: 11 additions & 0 deletions tests/cmd/eza_colors_reset_unix.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# reset should disable built-in long-view colors while still honoring LS_COLORS
bin.name = "eza"
args = "--color always --long --no-user --no-filesize --no-time index.svg"

[fs]
cwd = "../itest"

[env.add]
LS_COLORS = "fi=31"
EZA_COLORS = "reset"
EZA_CONFIG_DIR = "tests/itest"
Loading