new command now attaches if session title exists
This commit is contained in:
parent
d3aaf2e023
commit
e00c9e5366
1 changed files with 23 additions and 11 deletions
|
@ -173,13 +173,16 @@ pub fn new(pargs: &mut Arguments) {
|
|||
command = args.get(1);
|
||||
}
|
||||
|
||||
let mut tmux = Tmux::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); }
|
||||
|
||||
let mut tmux = Tmux::new().add_command(new);
|
||||
tmux = tmux.add_command(new).disable_echo();
|
||||
|
||||
// rename window if var not empty
|
||||
if !window_name.is_empty() {
|
||||
|
@ -187,6 +190,15 @@ pub fn new(pargs: &mut Arguments) {
|
|||
.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();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue