-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
34 lines (32 loc) · 1.14 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use std::env::var;
use std::path::PathBuf;
use std::include_str;
use std::fs;
use std::io::Write;
use dirs::home_dir;
fn generate_config() {
let mut home = home_dir().unwrap();
home.push(".config");
let config_file = var("SHRTCUT_CONFIG_FILE");
let config_path = match config_file {
Ok(path) => PathBuf::from(&path),
Err(_) => {
let mut default_config_path = home.clone();
default_config_path.push(".shrtcut.toml");
default_config_path
}
};
if !config_path.exists() {
fs::create_dir_all(&config_path.parent().unwrap_or(&home_dir().expect("[error] Cannot find home directory.")))
.expect("[error] Could not create config directory.");
let mut new_config_file =
fs::File::create(&config_path).expect("[error] Could not create config file.");
new_config_file
.write_all(include_str!("src/resources/default.toml").as_bytes())
.expect("[error] Could not write to config file.");
};
}
fn main() {
println!("cargo:rerun-if-env-changed=SHRTCUT_CONFIG_FILE");
generate_config();
}