diff options
| -rw-r--r-- | src/config.rs | 11 | ||||
| -rw-r--r-- | src/main.rs | 6 | 
2 files changed, 15 insertions, 2 deletions
diff --git a/src/config.rs b/src/config.rs index 5daa4455..bd073371 100644 --- a/src/config.rs +++ b/src/config.rs @@ -6,11 +6,12 @@  use std::env;  use std::fmt;  use std::fs; -use std::io::{self, Read}; +use std::io::{self, Read, Write};  use std::path::{Path, PathBuf};  use std::str::FromStr;  use std::sync::mpsc;  use std::ops::{Index, IndexMut}; +use std::fs::File;  use ::Rgb;  use font::Size; @@ -821,6 +822,14 @@ impl Config {          Config::load_from(path)      } +    pub fn write_defaults() -> io::Result<PathBuf> { +        let path = ::xdg::BaseDirectories::new() +            .map_err(|err| io::Error::new(io::ErrorKind::NotFound, ::std::error::Error::description(&err))) +            .and_then(|p| p.place_config_file("alacritty.yml"))?; +        File::create(&path)?.write_all(DEFAULT_ALACRITTY_CONFIG.as_bytes())?; +        Ok(path) +    } +      /// Get list of colors      ///      /// The ordering returned here is expected by the terminal. Colors are simply indexed in this diff --git a/src/main.rs b/src/main.rs index 3328ab59..ce323ac1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,7 +38,11 @@ fn main() {          match err {              // Use default config when not found              config::Error::NotFound => { -                err_println!("Config file not found; using defaults"); +                match Config::write_defaults() { +                    Ok(path) => err_println!("Config file not found; write defaults config to {:?}", path), +                    Err(err) => err_println!("Write defaults config failure: {}", err) +                } +                  Config::default()              },  | 
