'switch' command now supports detach flag, and updated manual documentation for 'switch'

This commit is contained in:
Valerie Wolfe 2024-07-22 09:26:33 -04:00
parent fdf3114c04
commit 0fe3906578
2 changed files with 16 additions and 7 deletions

View file

@ -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

View file

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