From e00c9e5366eafba06ada0019494722ed39dd4d66 Mon Sep 17 00:00:00 2001 From: Valerie Wolfe Date: Mon, 10 Jun 2024 09:04:14 -0400 Subject: [PATCH] new command now attaches if session title exists --- src/command/share.rs | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/command/share.rs b/src/command/share.rs index d4f47f8..27f7949 100644 --- a/src/command/share.rs +++ b/src/command/share.rs @@ -173,20 +173,32 @@ pub fn new(pargs: &mut Arguments) { command = args.get(1); } - let mut new = commands::NewSession::new(); - new = new.session_name(title); - if let Some(command) = command { new.shell_command = Some(command.to_string_lossy()); } - if detached { new.detached = true; } - if let Ok(target_dir) = target_dir { new = new.start_directory(target_dir); } + let mut tmux = Tmux::new(); - let mut tmux = Tmux::new().add_command(new); + // if no session exists with the given title, create one + if !util::session_exists(&title) { + let mut new = commands::NewSession::new(); + new = new.session_name(title); + if let Some(command) = command { new.shell_command = Some(command.to_string_lossy()); } + if detached { new.detached = true; } + if let Ok(target_dir) = target_dir { new = new.start_directory(target_dir); } + tmux = tmux.add_command(new).disable_echo(); - // rename window if var not empty - if !window_name.is_empty() { - let auto_name = commands::RenameWindow::new() - .new_name(window_name); - tmux = tmux.add_command(auto_name); + // rename window if var not empty + if !window_name.is_empty() { + let auto_name = commands::RenameWindow::new() + .new_name(window_name); + tmux = tmux.add_command(auto_name); + } } + // otherwise, use the existing session + else { + let mut attach = commands::AttachSession::new(); + attach = attach.target_session(title); + tmux = tmux.add_command(attach); + } + + tmux.output().ok(); }