From f23bf370c97d2d486cfd972cf96eba32f243cdcf Mon Sep 17 00:00:00 2001 From: Deepak Date: Wed, 16 Oct 2019 00:53:02 +0530 Subject: [PATCH 1/3] Added a function to read from multiple config files --- src/config.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/config.rs b/src/config.rs index 0f46bff461..cab3bc7c1a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -8,7 +8,7 @@ use shell_words; use crate::dirs::PROJECT_DIRS; use crate::util::transpose; -pub fn config_file() -> PathBuf { +pub fn default_config_path() -> PathBuf { env::var("BAT_CONFIG_PATH") .ok() .map(PathBuf::from) @@ -17,8 +17,22 @@ pub fn config_file() -> PathBuf { } pub fn get_args_from_config_file() -> Result, shell_words::ParseError> { + let mut config_file_path = vec![PathBuf::from("/etc/bat/config")]; + config_file_path.push(default_config_path()); + + let mut config_args = vec![]; + + for path in config_file_path.iter() { + let args = read_args_from_config_file(path.to_path_buf()); + config_args.append(&mut args.unwrap()); + } + + Ok(config_args) +} + +fn read_args_from_config_file(config_file_path: PathBuf) -> Result, shell_words::ParseError> { Ok(transpose( - fs::read_to_string(config_file()) + fs::read_to_string(config_file_path) .ok() .map(|content| get_args_from_str(&content)), )? From 11f9e1b13fc699e55bd93754ad2579c5367eaddc Mon Sep 17 00:00:00 2001 From: Deepak Date: Wed, 16 Oct 2019 01:21:48 +0530 Subject: [PATCH 2/3] Fixed build error --- src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9d222bd72c..f62a68d629 100644 --- a/src/main.rs +++ b/src/main.rs @@ -50,7 +50,7 @@ use ansi_term::Style; use crate::app::{App, Config}; use crate::assets::{cache_dir, clear_assets, config_dir, HighlightingAssets}; -use crate::config::config_file; +use crate::config::default_config_path; use crate::controller::Controller; use crate::inputfile::InputFile; use crate::style::{OutputComponent, OutputComponents}; @@ -231,7 +231,7 @@ fn run() -> Result { Ok(true) } else if app.matches.is_present("config-file") { - println!("{}", config_file().to_string_lossy()); + println!("{}", default_config_path().to_string_lossy()); Ok(true) } else if app.matches.is_present("config-dir") { From 85e69db64d154acc8570822d3b19999da2376280 Mon Sep 17 00:00:00 2001 From: Deepak Date: Mon, 21 Oct 2019 17:31:48 +0530 Subject: [PATCH 3/3] Fixed import error --- src/bin/bat/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/bat/main.rs b/src/bin/bat/main.rs index b6f54f9ae8..8e67092a74 100644 --- a/src/bin/bat/main.rs +++ b/src/bin/bat/main.rs @@ -17,7 +17,7 @@ use std::process; use ansi_term::Colour::Green; use ansi_term::Style; -use crate::{app::App, config::config_file}; +use crate::{app::App, config::default_config_path}; use bat::controller::Controller; use bat::{