@@ -1,6 +1,7 @@
1use std::env;
1use std::env;
2use std::ffi::OsString;
2use std::ffi::OsString;
3use std::fs;
3use std::fs;
4+use std::io::{self, Write};
4use std::path::PathBuf;
5use std::path::PathBuf;
6use shell_words;
7use shell_words;
@@ -15,6 +16,46 @@ pub fn config_file() -> PathBuf {
15 .unwrap_or_else(|| PROJECT_DIRS.config_dir().join("config"))
16 .unwrap_or_else(|| PROJECT_DIRS.config_dir().join("config"))
19+pub fn generate_config_file() {
20+ let config_file = config_file();
21+ if config_file.exists() {
22+ println!("A config file already exists at: {}", config_file.to_string_lossy());
24+ print!("Overwrite? (y/n): ");
25+ let _ = io::stdout().flush();
26+ let mut decision = String::new();
27+ io::stdin().read_line(&mut decision).expect("Failed to read input");
29+ if !decision.trim().eq_ignore_ascii_case("Y") {
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");
39+ let default_config = "# Specify desired theme (e.g. \"TwoDark\")
42+# Enable this to use italic text on the terminal (not supported on all terminals):
45+# Uncomment the following line to disable automatic paging:
48+# Use C++ syntax for .ino files
49+#--map-syntax \"*.ino:C++\"
51+# Use \".gitignore\"-style highlighting for \".ignore\" files
52+#--map-syntax \".ignore:Git Ignore\"
55+ fs::write(&config_file, default_config).expect("Error writing config file!");
56+ println!("Success! Config file written to {}", config_file.to_string_lossy());
18pub fn get_args_from_config_file() -> Result<Vec<OsString>, shell_words::ParseError> {
59pub fn get_args_from_config_file() -> Result<Vec<OsString>, shell_words::ParseError> {
19 Ok(fs::read_to_string(config_file())
60 Ok(fs::read_to_string(config_file())