summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Peter <mail@david-peter.de>2021-02-27 12:21:06 +0100
committerDavid Peter <sharkdp@users.noreply.github.com>2021-02-28 10:08:24 +0100
commitca60937c2e0b6b3de3d3e379fd419cdac9daecd6 (patch)
treee32f8ff8a87833812d1a6e2c1a4349ca6d4597a5 /src
parent2aa3ed9da889a0b32b478ccbbf2738cedec08947 (diff)
Do not ignore non-existent BAT_CONFIG_PATH
Do not ignore `BAT_CONFIG_PATH` if it doesn't exist. Both when generating a new config file with `--generate-config-file` and when attempting to read the config. Also, provide a better error message in case the file can not be created. closes #1550
Diffstat (limited to 'src')
-rw-r--r--src/bin/bat/config.rs12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/bin/bat/config.rs b/src/bin/bat/config.rs
index e7ede5a3..93ce8aaa 100644
--- a/src/bin/bat/config.rs
+++ b/src/bin/bat/config.rs
@@ -10,13 +10,12 @@ pub fn config_file() -> PathBuf {
env::var("BAT_CONFIG_PATH")
.ok()
.map(PathBuf::from)
- .filter(|config_path| config_path.is_file())
.unwrap_or_else(|| PROJECT_DIRS.config_dir().join("config"))
}
pub fn generate_config_file() -> bat::error::Result<()> {
let config_file = config_file();
- if config_file.exists() {
+ if config_file.is_file() {
println!(
"A config file already exists at: {}",
config_file.to_string_lossy()
@@ -71,7 +70,14 @@ pub fn generate_config_file() -> bat::error::Result<()> {
#--map-syntax ".ignore:Git Ignore"
"#;
- fs::write(&config_file, default_config)?;
+ fs::write(&config_file, default_config).map_err(|e| {
+ format!(
+ "Failed to create config file at '{}': {}",
+ config_file.to_string_lossy(),
+ e
+ )
+ })?;
+
println!(
"Success! Config file written to {}",
config_file.to_string_lossy()