From f621a46954f43426e0e7c053f7f5153fd2f2e823 Mon Sep 17 00:00:00 2001 From: pyro Date: Wed, 30 Sep 2026 12:41:58 -0500 Subject: [PATCH] modified the launch_termianl command to start in the projects files folder. --- src/appstate.rs | 67 +++++++++++++++++++++++++++---------------------- src/project.rs | 16 +++++++++--- 2 files changed, 50 insertions(+), 33 deletions(-) diff --git a/src/appstate.rs b/src/appstate.rs index 67d44aa..8f2914a 100644 --- a/src/appstate.rs +++ b/src/appstate.rs @@ -163,22 +163,26 @@ impl AppState { new_project.load_config(display)?; let template_box = self.config.get("template_box").unwrap(); let tools = self.config.get("tools").unwrap(); - let db = DistroBox { - name: format!( - "{}-{}-{}", - template_box, - new_project.org_name.clone(), - new_project.name.clone() - ), - volumes: vec![ - new_project.files.display().to_string(), - new_project.notes.display().to_string(), - tools.clone(), - ], - created: false, - template: template_box.clone(), - }; - new_project.db = Some(db); + if template_box != "NONE" || new_project.distrobox { + let db = DistroBox { + name: format!( + "{}-{}-{}", + template_box, + new_project.org_name.clone(), + new_project.name.clone() + ), + volumes: vec![ + new_project.files.display().to_string(), + new_project.notes.display().to_string(), + tools.clone(), + ], + created: false, + template: template_box.clone(), + }; + new_project.db = Some(db); + } else { + new_project.db = None; + } self.projects.push(new_project); } } @@ -581,24 +585,24 @@ impl AppState { let project = self.projects[self.selected_project].clone(); if let Some(cmd) = self.config.get("term_cmd") { if let Some(db) = project.db { - db.launch_terminal(cmd.to_string()); + let _ = self + .main_tx + .send(ToolMessage::Output((rid, format!("launcing distrobox...")))); + db.launch_terminal( + cmd.to_string(), + self.projects[self.selected_project].files.clone(), + ); } else { if let Some((prog, _)) = cmd.split_once(" ") { let mut launch_cmd = Command::new(prog); - match prog { - "konsole" => { - launch_cmd - .arg(format!("--workdir {}", project.files.display())); - } - "xfce4-terminal" => { - launch_cmd.arg(format!( - "--working-directory={}", - project.files.display() - )); - } - _ => {} + launch_cmd.current_dir(&project.files); + if let Some(dir) = launch_cmd.get_current_dir() { + let _ = self.main_tx.send(ToolMessage::Output(( + rid, + format!("launcing terminal in {}", dir.display()), + ))); } - match launch_cmd.spawn() { + match launch_cmd.current_dir(&project.files).spawn() { Ok(_) => {} Err(e) => { let _ = self.main_tx.send(ToolMessage::Output(( @@ -2038,6 +2042,7 @@ impl AppState { } } let mut db = None; + let mut distrobx = false; if template_box != &"NONE".to_string() { db = Some(DistroBox { name: format!("{}-{}-{}", template_box, org, name), @@ -2049,6 +2054,7 @@ impl AppState { created: false, template: template_box.to_string(), }); + distrobx = true; }; let mut new_project = Project { org_name: org, @@ -2059,6 +2065,7 @@ impl AppState { config_folder: project_config_file, current: false, db: db, + distrobox: distrobx, scope: Vec::new(), exclusions: Vec::new(), }; diff --git a/src/project.rs b/src/project.rs index d11917d..560f8c3 100644 --- a/src/project.rs +++ b/src/project.rs @@ -22,6 +22,7 @@ pub struct Project { pub hosts: Vec, pub current: bool, pub db: Option, + pub distrobox: bool, pub scope: Vec, pub exclusions: Vec, } @@ -37,6 +38,7 @@ impl Project { hosts: Vec::new(), current: false, db: None, + distrobox: false, scope: Vec::new(), exclusions: Vec::new(), } @@ -117,6 +119,13 @@ impl Project { self.exclusions.push(ip.to_string()); }); } + "db" => { + if parts[1].contains("false") { + self.distrobox = false; + } else { + self.distrobox = true; + } + } _ => {} } } @@ -236,13 +245,14 @@ impl Project { } let mut file = File::create(&self.config_folder)?; let mut out_string = format!( - "org_name: {}\nname: {}\nnotes: {}\nfiles: {}\nscope: {}\nexclusions: {}\n", + "org_name: {}\nname: {}\nnotes: {}\nfiles: {}\nscope: {}\nexclusions: {}\ndb: {}\n", self.org_name, self.name, self.notes.display(), self.files.display(), self.scope.join(","), self.exclusions.join(","), + self.distrobox ); if self.current { out_string.push_str("stage: current"); @@ -458,7 +468,7 @@ impl DistroBox { return Ok(()); } - pub fn launch_terminal(&self, cmd: String) { + pub fn launch_terminal(&self, cmd: String, dir: PathBuf) { if let Some((terminal_cmd, args)) = cmd.split_once(" ") { let mut term_cmd = Command::new(terminal_cmd); args.split(" ").into_iter().for_each(|arg| { @@ -474,7 +484,7 @@ impl DistroBox { term_cmd.arg(arg); } }); - let _ = term_cmd.spawn(); + let _ = term_cmd.current_dir(dir).spawn(); } }