@@ -1,6 +1,7 @@
11use std::env;
22use std::ffi::OsString;
33use std::fs;
4+use std::io::{self, Write};
45use std::path::PathBuf;
56
67use shell_words;
@@ -15,6 +16,46 @@ pub fn config_file() -> PathBuf {
1516 .unwrap_or_else(|| PROJECT_DIRS.config_dir().join("config"))
1617}
1718
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());
23+
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");
28+
29+ if !decision.trim().eq_ignore_ascii_case("Y") {
30+ return;
31+ }
32+ } 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");
36+ }
37+ }
38+
39+ let default_config = "# Specify desired theme (e.g. \"TwoDark\")
40+#--theme=\"TwoDark\"
41+
42+# Enable this to use italic text on the terminal (not supported on all terminals):
43+#--italic-text=always
44+
45+# Uncomment the following line to disable automatic paging:
46+#--paging=never
47+
48+# Use C++ syntax for .ino files
49+#--map-syntax \"*.ino:C++\"
50+
51+# Use \".gitignore\"-style highlighting for \".ignore\" files
52+#--map-syntax \".ignore:Git Ignore\"
53+";
54+
55+ fs::write(&config_file, default_config).expect("Error writing config file!");
56+ println!("Success! Config file written to {}", config_file.to_string_lossy());
57+}
58+
1859pub fn get_args_from_config_file() -> Result<Vec<OsString>, shell_words::ParseError> {
1960 Ok(fs::read_to_string(config_file())
2061 .ok()