From 5bff4548be2575d82e8fd1df5e55aea122c82412 Mon Sep 17 00:00:00 2001 From: sharkdp Date: Thu, 11 Oct 2018 23:01:19 +0200 Subject: [PATCH] Add BAT_OPTS environment variable --- src/app.rs | 7 ++++--- src/config.rs | 4 ++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/app.rs b/src/app.rs index d5dd2b8f..fbe75cea 100644 --- a/src/app.rs +++ b/src/app.rs @@ -15,7 +15,7 @@ use console::Term; use ansi_term; use assets::BAT_THEME_DEFAULT; -use config::get_args_from_config_file; +use config::{get_args_from_config_file, get_args_from_env_var}; use errors::*; use inputfile::InputFile; use line_range::LineRange; @@ -104,8 +104,9 @@ impl App { let mut cli_args = wild::args_os(); // Read arguments from bats config file - let mut args = - get_args_from_config_file().chain_err(|| "Could not parse configuration file")?; + let mut args = get_args_from_env_var() + .unwrap_or_else(|| get_args_from_config_file()) + .chain_err(|| "Could not parse configuration file")?; // Put the zero-th CLI argument (program name) first args.insert(0, cli_args.next().unwrap()); diff --git a/src/config.rs b/src/config.rs index b5833f5c..4ee40afd 100644 --- a/src/config.rs +++ b/src/config.rs @@ -17,6 +17,10 @@ pub fn get_args_from_config_file() -> Result, shell_words::ParseEr .unwrap_or(vec![])) } +pub fn get_args_from_env_var() -> Option, shell_words::ParseError>> { + env::var("BAT_OPTS").ok().map(|s| get_args_from_str(&s)) +} + fn get_args_from_str<'a>(content: &'a str) -> Result, shell_words::ParseError> { let args_per_line = content .split('\n')