mirror of
https://github.com/sharkdp/bat
synced 2024-11-18 15:26:16 +00:00
Add BAT_OPTS environment variable
This commit is contained in:
parent
866b9e16a8
commit
5bff4548be
@ -15,7 +15,7 @@ use console::Term;
|
|||||||
use ansi_term;
|
use ansi_term;
|
||||||
|
|
||||||
use assets::BAT_THEME_DEFAULT;
|
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 errors::*;
|
||||||
use inputfile::InputFile;
|
use inputfile::InputFile;
|
||||||
use line_range::LineRange;
|
use line_range::LineRange;
|
||||||
@ -104,8 +104,9 @@ impl App {
|
|||||||
let mut cli_args = wild::args_os();
|
let mut cli_args = wild::args_os();
|
||||||
|
|
||||||
// Read arguments from bats config file
|
// Read arguments from bats config file
|
||||||
let mut args =
|
let mut args = get_args_from_env_var()
|
||||||
get_args_from_config_file().chain_err(|| "Could not parse configuration file")?;
|
.unwrap_or_else(|| get_args_from_config_file())
|
||||||
|
.chain_err(|| "Could not parse configuration file")?;
|
||||||
|
|
||||||
// Put the zero-th CLI argument (program name) first
|
// Put the zero-th CLI argument (program name) first
|
||||||
args.insert(0, cli_args.next().unwrap());
|
args.insert(0, cli_args.next().unwrap());
|
||||||
|
@ -17,6 +17,10 @@ pub fn get_args_from_config_file() -> Result<Vec<OsString>, shell_words::ParseEr
|
|||||||
.unwrap_or(vec![]))
|
.unwrap_or(vec![]))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_args_from_env_var() -> Option<Result<Vec<OsString>, 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<Vec<OsString>, shell_words::ParseError> {
|
fn get_args_from_str<'a>(content: &'a str) -> Result<Vec<OsString>, shell_words::ParseError> {
|
||||||
let args_per_line = content
|
let args_per_line = content
|
||||||
.split('\n')
|
.split('\n')
|
||||||
|
Loading…
Reference in New Issue
Block a user