Просмотр исходного кода

feat: create EZA_ICONS_AUTO environment variable

Ryan Breaker 2 лет назад
Родитель
Сommit
16f758c593
3 измененных файлов с 13 добавлено и 1 удалено
  1. 6 0
      man/eza.1.md
  2. 5 1
      src/options/file_name.rs
  3. 2 0
      src/options/vars.rs

+ 6 - 0
man/eza.1.md

@@ -302,6 +302,12 @@ For more information on the format of these environment variables, see the [eza_
 
 Overrides any `--git` or `--git-repos` argument
 
+## `EZA_ICONS_AUTO`
+
+If set to `true`, automates the same behavior as `--icons` or `--icons=auto`. Useful for if you always want to have icons enabled.
+
+Any use of the `--icons=WHEN` flag overrides this. 
+
 
 EXIT STATUSES
 =============

+ 5 - 1
src/options/file_name.rs

@@ -1,6 +1,7 @@
 use crate::options::parser::MatchedFlags;
 use crate::options::vars::{self, Vars};
 use crate::options::{flags, NumberSource, OptionsError};
+use std::ffi::OsString;
 
 use crate::output::file_name::{Classify, EmbedHyperlinks, Options, QuoteStyle, ShowIcons};
 
@@ -45,8 +46,11 @@ impl ShowIcons {
             Automatic,
         }
 
+        let force_icons = vars
+            .get(vars::EZA_ICONS_AUTO)
+            .eq(&Some(OsString::from("true")));
         let mode_opt = matches.get(&flags::ICONS)?;
-        if !matches.has(&flags::ICONS)? && mode_opt.is_none() {
+        if !force_icons && !matches.has(&flags::ICONS)? && mode_opt.is_none() {
             return Ok(Self::Never);
         }
 

+ 2 - 0
src/options/vars.rs

@@ -55,6 +55,8 @@ pub static EZA_ICON_SPACING: &str = "EZA_ICON_SPACING";
 pub static EXA_OVERRIDE_GIT: &str = "EXA_OVERRIDE_GIT";
 pub static EZA_OVERRIDE_GIT: &str = "EZA_OVERRIDE_GIT";
 
+pub static EZA_ICONS_AUTO: &str = "EZA_ICONS_AUTO";
+
 /// Mockable wrapper for `std::env::var_os`.
 pub trait Vars {
     fn get(&self, name: &'static str) -> Option<OsString>;