-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Read bat config from multiple config files #691
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ use shell_words; | |
|
||
use bat::{dirs::PROJECT_DIRS, util::transpose}; | ||
|
||
pub fn config_file() -> PathBuf { | ||
pub fn default_config_path() -> PathBuf { | ||
env::var("BAT_CONFIG_PATH") | ||
.ok() | ||
.map(PathBuf::from) | ||
|
@@ -16,8 +16,22 @@ pub fn config_file() -> PathBuf { | |
} | ||
|
||
pub fn get_args_from_config_file() -> Result<Vec<OsString>, shell_words::ParseError> { | ||
let mut config_file_path = vec![PathBuf::from("/etc/bat/config")]; | ||
config_file_path.push(default_config_path()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so how does that work?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sharkdp Thanks for the review. I'm thinking of moving the logic for getting path from env var |
||
|
||
let mut config_args = vec![]; | ||
|
||
for path in config_file_path.iter() { | ||
let args = read_args_from_config_file(path.to_path_buf()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you could avoid the |
||
config_args.append(&mut args.unwrap()); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not necessary, but the whole loop could probably be written in functional style with Something like (not tested and most probably wrong): let config_args = config_file_path
.iter()
.map(read_args_from_config_file)
.transpose()?
.flatten()
.collect(); |
||
|
||
Ok(config_args) | ||
} | ||
|
||
fn read_args_from_config_file(config_file_path: PathBuf) -> Result<Vec<OsString>, 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)), | ||
)? | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
config_file_path
=>config_file_paths
?