on master help sign in
Do not ignore non-existent BAT_CONFIG_PATH
ca60937David Peter
CHANGELOG.md+1
@@ -16,6 +16,7 @@
16- If `PAGER` (but not `BAT_PAGER` or `--pager`) is `more` or `most`, silently use `less` instead to ensure support for colors, see #1063 (@Enselic)
16- If `PAGER` (but not `BAT_PAGER` or `--pager`) is `more` or `most`, silently use `less` instead to ensure support for colors, see #1063 (@Enselic)
17- If `PAGER` is `bat`, silently use `less` to prevent recursion. For `BAT_PAGER` or `--pager`, exit with error, see #1413 (@Enselic)
17- If `PAGER` is `bat`, silently use `less` to prevent recursion. For `BAT_PAGER` or `--pager`, exit with error, see #1413 (@Enselic)
18- Manpage highlighting fix, see #1511 (@keith-hall)
18- Manpage highlighting fix, see #1511 (@keith-hall)
19+- `BAT_CONFIG_PATH` ignored by `bat` if non-existent, see #1550 (@sharkdp)
19
20
20## Other
21## Other
21
22
src/bin/bat/config.rs+9−3
@@ -10,13 +10,12 @@ pub fn config_file() -> PathBuf {
10 env::var("BAT_CONFIG_PATH")
10 env::var("BAT_CONFIG_PATH")
11 .ok()
11 .ok()
12 .map(PathBuf::from)
12 .map(PathBuf::from)
13− .filter(|config_path| config_path.is_file())
14 .unwrap_or_else(|| PROJECT_DIRS.config_dir().join("config"))
13 .unwrap_or_else(|| PROJECT_DIRS.config_dir().join("config"))
15}
14}
16
15
17pub fn generate_config_file() -> bat::error::Result<()> {
16pub fn generate_config_file() -> bat::error::Result<()> {
18 let config_file = config_file();
17 let config_file = config_file();
19− if config_file.exists() {
18+ if config_file.is_file() {
20 println!(
19 println!(
21 "A config file already exists at: {}",
20 "A config file already exists at: {}",
22 config_file.to_string_lossy()
21 config_file.to_string_lossy()
@@ -71,7 +70,14 @@ pub fn generate_config_file() -> bat::error::Result<()> {
71#--map-syntax ".ignore:Git Ignore"
70#--map-syntax ".ignore:Git Ignore"
72"#;
71"#;
73
72
74− fs::write(&config_file, default_config)?;
73+ fs::write(&config_file, default_config).map_err(|e| {
74+ format!(
75+ "Failed to create config file at '{}': {}",
76+ config_file.to_string_lossy(),
77+ e
78+ )
79+ })?;
80+
75 println!(
81 println!(
76 "Success! Config file written to {}",
82 "Success! Config file written to {}",
77 config_file.to_string_lossy()
83 config_file.to_string_lossy()
tests/integration_tests.rs+7
@@ -652,6 +652,13 @@ fn config_location_test() {
652 .assert()
652 .assert()
653 .success()
653 .success()
654 .stdout("bat.conf\n");
654 .stdout("bat.conf\n");
655+
656+ bat_with_config()
657+ .env("BAT_CONFIG_PATH", "not-existing.conf")
658+ .arg("--config-file")
659+ .assert()
660+ .success()
661+ .stdout("not-existing.conf\n");
655}
662}
656
663
657#[test]
664#[test]