소스 검색

feat: create EZA_ICONS_AUTO environment variable

Ryan Breaker 2 년 전
부모
커밋
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
 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
 EXIT STATUSES
 =============
 =============

+ 5 - 1
src/options/file_name.rs

@@ -1,6 +1,7 @@
 use crate::options::parser::MatchedFlags;
 use crate::options::parser::MatchedFlags;
 use crate::options::vars::{self, Vars};
 use crate::options::vars::{self, Vars};
 use crate::options::{flags, NumberSource, OptionsError};
 use crate::options::{flags, NumberSource, OptionsError};
+use std::ffi::OsString;
 
 
 use crate::output::file_name::{Classify, EmbedHyperlinks, Options, QuoteStyle, ShowIcons};
 use crate::output::file_name::{Classify, EmbedHyperlinks, Options, QuoteStyle, ShowIcons};
 
 
@@ -45,8 +46,11 @@ impl ShowIcons {
             Automatic,
             Automatic,
         }
         }
 
 
+        let force_icons = vars
+            .get(vars::EZA_ICONS_AUTO)
+            .eq(&Some(OsString::from("true")));
         let mode_opt = matches.get(&flags::ICONS)?;
         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);
             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 EXA_OVERRIDE_GIT: &str = "EXA_OVERRIDE_GIT";
 pub static EZA_OVERRIDE_GIT: &str = "EZA_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`.
 /// Mockable wrapper for `std::env::var_os`.
 pub trait Vars {
 pub trait Vars {
     fn get(&self, name: &'static str) -> Option<OsString>;
     fn get(&self, name: &'static str) -> Option<OsString>;