@@ -16,28 +16,31 @@ pub fn config_file() -> PathBuf {
1616 .unwrap_or_else(|| PROJECT_DIRS.config_dir().join("config"))
1717}
1818
19−pub fn generate_config_file() {
19+pub fn generate_config_file() -> bat::errors::Result<()> {
2020 let config_file = config_file();
2121 if config_file.exists() {
2222 println!("A config file already exists at: {}", config_file.to_string_lossy());
2323
24− print!("Overwrite? (y/n): ");
25− let _ = io::stdout().flush();
24+ print!("Overwrite? (y/N): ");
25+ io::stdout().flush()?;
2626 let mut decision = String::new();
27− io::stdin().read_line(&mut decision).expect("Failed to read input");
27+ io::stdin().read_line(&mut decision)?;
2828
2929 if !decision.trim().eq_ignore_ascii_case("Y") {
30− return;
30+ return Ok(());
3131 }
3232 } else {
33− let config_dir = config_file.parent().unwrap();
34− if !config_dir.exists() {
35− fs::create_dir(config_dir).expect("Unable to create config directory");
33+ let config_dir = config_file.parent();
34+ match config_dir {
35+ Some(path) => fs::create_dir_all(path)?,
36+ None => return Ok(Err(format!("Unable to write config file to: {}", config_file.to_string_lossy()))?),
3637 }
3738 }
3839
39− let default_config = "# Specify desired theme (e.g. \"TwoDark\")
40−#--theme=\"TwoDark\"
40+ let default_config = r#"# bat config
41+
42+# Specify desired theme (e.g. "TwoDark"). Issue `bat --list-themes` for a list of all available themes
43+#--theme="TwoDark"
4144
4245# Enable this to use italic text on the terminal (not supported on all terminals):
4346#--italic-text=always
@@ -46,14 +49,16 @@ pub fn generate_config_file() {
4649#--paging=never
4750
4851# Use C++ syntax for .ino files
49−#--map-syntax \"*.ino:C++\"
52+#--map-syntax "*.ino:C++"
5053
51−# Use \".gitignore\"-style highlighting for \".ignore\" files
52−#--map-syntax \".ignore:Git Ignore\"
53−";
54+# Use ".gitignore"-style highlighting for ".ignore" files
55+#--map-syntax ".ignore:Git Ignore"
56+"#;
5457
55− fs::write(&config_file, default_config).expect("Error writing config file!");
58+ fs::write(&config_file, default_config)?;
5659 println!("Success! Config file written to {}", config_file.to_string_lossy());
60+
61+ return Ok(());
5762}
5863
5964pub fn get_args_from_config_file() -> Result<Vec<OsString>, shell_words::ParseError> {