diff --git a/man/remux.1 b/man/remux.1 index c003f7a..12564c6 100644 --- a/man/remux.1 +++ b/man/remux.1 @@ -101,8 +101,8 @@ aliases: p Prints the session path. .Ed .It Xo Ic switch -.Op Fl r , Fl -read-only -.Ar title +.Op Fl rd +.Op Ar title .Xc .Bd -literal -compact aliases: s @@ -110,10 +110,12 @@ Switches from the current session to the target. .Ed .Pp .Bl -tag -width Ds -compact +.It Fl d , Fl -detach +Detaches other clients from the target session. .It Fl r , Fl -read-only Switch to the target session in read-only mode. .It Ar title -The title of the session to switch to. +The title of the session to switch to. If blank, the previous session will be used. .El .It Ic title .Bd -literal -compact diff --git a/src/command/session.rs b/src/command/session.rs index 0c59452..2f9cbe7 100644 --- a/src/command/session.rs +++ b/src/command/session.rs @@ -30,7 +30,7 @@ pub fn switch(state: &mut State) { // consume optional flags let read_only = state.flags.read_only; - //TODO: -d flag handling needs to be done manually + let detach_other = state.flags.detached; let args = state.args.clone().finish(); let target: String = match if let Some(inner) = args.get(0) { inner.to_str() } else { None } { @@ -44,12 +44,19 @@ pub fn switch(state: &mut State) { let exists = util::session_exists(target.clone()); if !exists { error::no_target(target.clone()); } + let mut tmux = Tmux::new(); + + if detach_other { + let detach = commands::DetachClient::new() + .target_session(&target); + tmux = tmux.add_command(detach); + } + let mut switch = commands::SwitchClient::new(); - switch = switch.target_session(target); + switch = switch.target_session(&target); if read_only { switch.read_only = true; } - Tmux::new() - .add_command(switch) + tmux.add_command(switch) .stderr(NULL).output().ok(); }