new command now attaches if session title exists

This commit is contained in:
Valerie Wolfe 2024-06-10 09:04:14 -04:00
parent d3aaf2e023
commit e00c9e5366

View file

@ -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();
}