Skip to content

Commit

Permalink
added dotfiles command
Browse files Browse the repository at this point in the history
  • Loading branch information
KCaverly committed Dec 23, 2022
1 parent bf227ab commit 5a45875
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 27 deletions.
38 changes: 11 additions & 27 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use toml;
#[derive(Debug, Deserialize)]
pub struct Config {
pub projects: HashMap<String, Project>,
pub dotfiles: Dotfiles,
}

#[derive(Debug, Deserialize)]
Expand All @@ -16,6 +17,12 @@ pub struct Project {
pub include_hidden: bool,
}

#[derive(Debug, Deserialize)]
pub struct Dotfiles {
pub repo: String,
pub location: String,
}

fn get_peaches_path() -> String {
let mut peaches_path: String = env::var("HOME").ok().unwrap();
peaches_path.push_str("/.peaches");
Expand All @@ -35,6 +42,10 @@ pub fn generate_config() {
min_depth = 1
max_depth = 1
include_hidden = false
[dotfiles]
repo = ""
location = ""
"#;

let peaches_path = get_peaches_path();
Expand All @@ -46,33 +57,6 @@ pub fn load_config() -> Config {

let config_string: String = fs::read_to_string(peaches_path).ok().unwrap();

const TEXT: &str = r#"
[projects]
[projects.personal]
session_name = "kc"
directory = "/home/kcaverly/personal"
max_depth = 1
min_depth = 1
include_hidden = false
[projects.work]
session_name = "kc"
directory = "/home/kcaverly/work"
max_depth = 2
min_depth = 2
include_hidden = false
[projects.dotfiles]
session_name = "kc"
directory = "/home/kcaverly/.dotfiles"
max_depth = 3
min_depth = 3
include_hidden = false
"#;

let config: Config = toml::from_str(&config_string).unwrap();
// println!("{:#?}", config);
return config;
}
22 changes: 22 additions & 0 deletions src/dotfiles.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use std::process;

pub fn git_pull_dotfiles(location: &str) {
println!("{}", location);

let mv = process::Command::new("git")
.args(vec!["pull", "--recurse-submodules"])
.current_dir(location)
.status()
.unwrap();

if mv.success() {
let cmd = process::Command::new("zsh")
.args(vec!["install"])
.current_dir(location)
.status()
.unwrap();
println!("{}", cmd.success());
}

println!("{}", mv.success());
}
12 changes: 12 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod config;
mod dotfiles;
mod projects;
mod tmux;

Expand All @@ -21,6 +22,8 @@ enum Commands {
Upgrade {},
/// Initialize config file
Config {},
/// Update Dotfiles
Dotfiles {},
}

fn run_config() {
Expand Down Expand Up @@ -71,6 +74,10 @@ fn run_projects(cfg: &config::Config) {
tmux::TMUX::attach_or_select_window(&selected_project.session_name, name);
}

fn run_dotfiles(cfg: &config::Config) {
dotfiles::git_pull_dotfiles(&cfg.dotfiles.location);
}

fn main() {
let value = Value::parse();

Expand All @@ -86,5 +93,10 @@ fn main() {
Commands::Config {} => {
run_config();
}

Commands::Dotfiles {} => {
let cfg: config::Config = config::load_config();
run_dotfiles(&cfg);
}
}
}

0 comments on commit 5a45875

Please sign in to comment.