diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a9d37c5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +target +Cargo.lock diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..3270a89 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "dotfiles_manager" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +clap='4.4.*' diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..a8b9e21 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,51 @@ +use std::fs; +use std::path::PathBuf; +use std::env; + +fn main() { +/* let configs = vec![ + Config::new("laptop/sway/config", "/home/eesim/.config/sway/config"), + Config::new("laptop/nvim/init.lua", "/home/eesim/.config/nvim/init.lua"), + Config::new("laptop/nvim/lua/config", "/home/eesim/.config/nvim/lua/config"), + Config::new("laptop/alacritty/alacritty.toml", "/home/eesim/.config/alacritty/alacritty.toml"), + Config::new("laptop/rofi/config.rasi", "/home/eesim/.config/rofi/config.rasi") + ]; +*/ + + let configs = vec!(Config::new("laptop/rofi/config.rasi", "/home/eesim/.config/rofi/config.rasi")); + + let _dirs = configs.iter().filter(|config| config.is_dir); + let files = configs.iter().filter(|config| !config.is_dir); + + files.for_each(|config| copy_file(&config, true)); + +} + +struct Config { + git_location: PathBuf, + sys_location: PathBuf, + is_dir: bool, +} + +impl Config { + fn new(rel_git_location: &str, sys_location: &str) -> Self { + + let home_dir = PathBuf::from(env::var("HOME").expect("$HOME not set")); + let manager_dir = home_dir.join(".dotfiles/"); + + let git_location = manager_dir.join(rel_git_location); + let sys_location = PathBuf::from(sys_location); + + let is_dir = fs::metadata(&git_location).unwrap().is_dir(); + + Self { git_location, sys_location, is_dir } + } +} + +fn copy_file(config: &Config, to_sys: bool) { + if to_sys { + let _ = fs::copy(&config.git_location, &config.sys_location); + } else { + let _ = fs::copy(&config.sys_location, &config.git_location); + } +}