@@ -1,6 +1,7 @@
11use std::collections::HashSet;
22use std::env;
33use std::path::Path;
4+use std::str::FromStr;
45
56use atty::{self, Stream};
67
@@ -178,14 +179,15 @@ impl App {
178179 .takes_value(true)
179180 .possible_values(&[
180181 "auto", "full", "plain", "changes", "header", "grid", "numbers",
181− ]).default_value("auto")
182+ ])
182183 .help("Comma-separated list of style elements to display.")
183184 .long_help(
184185 "Configure which elements (line numbers, file headers, grid \
185186 borders, Git modifications, ..) to display in addition to the \
186187 file contents. The argument is a comma-separated list of \
187188 components to display (e.g. 'numbers,changes,grid') or a \
188− pre-defined style ('full')",
189+ pre-defined style ('full'). To set a default theme, export the \
190+ BAT_STYLE environment variable (e.g.: export BAT_STYLE=\"numbers\").",
189191 ),
190192 ).arg(
191193 Arg::with_name("plain")
@@ -462,7 +464,18 @@ impl App {
462464 } else if matches.is_present("plain") {
463465 [OutputComponent::Plain].iter().cloned().collect()
464466 } else {
465− values_t!(matches.values_of("style"), OutputComponent)?
467+ let env_style_components: Option<Vec<OutputComponent>> =
468+ transpose(env::var("BAT_STYLE").ok().map(|style_str| {
469+ style_str
470+ .split(",")
471+ .map(|x| OutputComponent::from_str(&x))
472+ .collect::<Result<Vec<OutputComponent>>>()
473+ }))?;
474+
475+ values_t!(matches.values_of("style"), OutputComponent)
476+ .ok()
477+ .or(env_style_components)
478+ .unwrap_or(vec![OutputComponent::Full])
466479 .into_iter()
467480 .map(|style| style.components(self.interactive_output))
468481 .fold(HashSet::new(), |mut acc, components| {