From 2593d0c1f042afb46446f6bd1a52a7e61181480d Mon Sep 17 00:00:00 2001 From: zohnannor Date: Sat, 14 Feb 2026 10:46:47 +0100 Subject: [PATCH] fix: make EZA_COLORS=reset clear built-in styles --- man/eza_colors-explanation.5.md | 6 ++---- man/eza_colors.5.md | 4 ++-- src/theme/mod.rs | 13 ++++++++++--- tests/cmd/eza_colors_reset_custom_unix.stderr | 0 tests/cmd/eza_colors_reset_custom_unix.stdout | 1 + tests/cmd/eza_colors_reset_custom_unix.toml | 14 ++++++++++++++ tests/cmd/eza_colors_reset_unix.stderr | 0 tests/cmd/eza_colors_reset_unix.stdout | 1 + tests/cmd/eza_colors_reset_unix.toml | 11 +++++++++++ 9 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 tests/cmd/eza_colors_reset_custom_unix.stderr create mode 100644 tests/cmd/eza_colors_reset_custom_unix.stdout create mode 100644 tests/cmd/eza_colors_reset_custom_unix.toml create mode 100644 tests/cmd/eza_colors_reset_unix.stderr create mode 100644 tests/cmd/eza_colors_reset_unix.stdout create mode 100644 tests/cmd/eza_colors_reset_unix.toml diff --git a/man/eza_colors-explanation.5.md b/man/eza_colors-explanation.5.md index f9b87d659..04d256ec3 100644 --- a/man/eza_colors-explanation.5.md +++ b/man/eza_colors-explanation.5.md @@ -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. ## Examples diff --git a/man/eza_colors.5.md b/man/eza_colors.5.md index d8e54ec90..825a88804 100644 --- a/man/eza_colors.5.md +++ b/man/eza_colors.5.md @@ -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. AUTHOR diff --git a/src/theme/mod.rs b/src/theme/mod.rs index b22b4854c..33f0585a6 100644 --- a/src/theme/mod.rs +++ b/src/theme/mod.rs @@ -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 = match (exts.is_non_empty(), use_default_filetypes) { (false, false) => Box::new(NoFileStyle), @@ -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`. @@ -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; } diff --git a/tests/cmd/eza_colors_reset_custom_unix.stderr b/tests/cmd/eza_colors_reset_custom_unix.stderr new file mode 100644 index 000000000..e69de29bb diff --git a/tests/cmd/eza_colors_reset_custom_unix.stdout b/tests/cmd/eza_colors_reset_custom_unix.stdout new file mode 100644 index 000000000..183bbe32b --- /dev/null +++ b/tests/cmd/eza_colors_reset_custom_unix.stdout @@ -0,0 +1 @@ +[..][..][..] index.svg diff --git a/tests/cmd/eza_colors_reset_custom_unix.toml b/tests/cmd/eza_colors_reset_custom_unix.toml new file mode 100644 index 000000000..23f6b3dc7 --- /dev/null +++ b/tests/cmd/eza_colors_reset_custom_unix.toml @@ -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" diff --git a/tests/cmd/eza_colors_reset_unix.stderr b/tests/cmd/eza_colors_reset_unix.stderr new file mode 100644 index 000000000..e69de29bb diff --git a/tests/cmd/eza_colors_reset_unix.stdout b/tests/cmd/eza_colors_reset_unix.stdout new file mode 100644 index 000000000..1ff6d1281 --- /dev/null +++ b/tests/cmd/eza_colors_reset_unix.stdout @@ -0,0 +1 @@ +[..][..][..]index.svg diff --git a/tests/cmd/eza_colors_reset_unix.toml b/tests/cmd/eza_colors_reset_unix.toml new file mode 100644 index 000000000..16d49adb3 --- /dev/null +++ b/tests/cmd/eza_colors_reset_unix.toml @@ -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"