diff --git a/src/app.rs b/src/app.rs index 5b00658c..d2438ba4 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,6 +1,7 @@ use std::collections::HashSet; use std::env; use std::path::Path; +use std::str::FromStr; use atty::{self, Stream}; @@ -178,14 +179,15 @@ impl App { .takes_value(true) .possible_values(&[ "auto", "full", "plain", "changes", "header", "grid", "numbers", - ]).default_value("auto") + ]) .help("Comma-separated list of style elements to display.") .long_help( "Configure which elements (line numbers, file headers, grid \ borders, Git modifications, ..) to display in addition to the \ file contents. The argument is a comma-separated list of \ components to display (e.g. 'numbers,changes,grid') or a \ - pre-defined style ('full')", + pre-defined style ('full'). To set a default theme, export the \ + BAT_STYLE environment variable (e.g.: export BAT_STYLE=\"numbers\").", ), ).arg( Arg::with_name("plain") @@ -462,7 +464,18 @@ impl App { } else if matches.is_present("plain") { [OutputComponent::Plain].iter().cloned().collect() } else { - values_t!(matches.values_of("style"), OutputComponent)? + let env_style_components: Option> = + transpose(env::var("BAT_STYLE").ok().map(|style_str| { + style_str + .split(",") + .map(|x| OutputComponent::from_str(&x)) + .collect::>>() + }))?; + + values_t!(matches.values_of("style"), OutputComponent) + .ok() + .or(env_style_components) + .unwrap_or(vec![OutputComponent::Full]) .into_iter() .map(|style| style.components(self.interactive_output)) .fold(HashSet::new(), |mut acc, components| { diff --git a/src/style.rs b/src/style.rs index efd83697..56b04ee1 100644 --- a/src/style.rs +++ b/src/style.rs @@ -54,7 +54,8 @@ impl FromStr for OutputComponent { "header" => Ok(OutputComponent::Header), "numbers" => Ok(OutputComponent::Numbers), "full" => Ok(OutputComponent::Full), - "plain" | _ => Ok(OutputComponent::Plain), + "plain" => Ok(OutputComponent::Plain), + _ => Err(format!("Unknown style '{}'", s).into()), } } }