'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. Prints the session path.
.Ed .Ed
.It Xo Ic switch .It Xo Ic switch
.Op Fl r , Fl -read-only .Op Fl rd
.Ar title .Op Ar title
.Xc .Xc
.Bd -literal -compact .Bd -literal -compact
aliases: s aliases: s
@ -110,10 +110,12 @@ Switches from the current session to the target.
.Ed .Ed
.Pp .Pp
.Bl -tag -width Ds -compact .Bl -tag -width Ds -compact
.It Fl d , Fl -detach
Detaches other clients from the target session.
.It Fl r , Fl -read-only .It Fl r , Fl -read-only
Switch to the target session in read-only mode. Switch to the target session in read-only mode.
.It Ar title .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 .El
.It Ic title .It Ic title
.Bd -literal -compact .Bd -literal -compact

View file

@ -30,7 +30,7 @@ pub fn switch(state: &mut State) {
// consume optional flags // consume optional flags
let read_only = state.flags.read_only; 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 args = state.args.clone().finish();
let target: String = match if let Some(inner) = args.get(0) { inner.to_str() } else { None } { 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()); let exists = util::session_exists(target.clone());
if !exists { error::no_target(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(); let mut switch = commands::SwitchClient::new();
switch = switch.target_session(target); switch = switch.target_session(&target);
if read_only { switch.read_only = true; } if read_only { switch.read_only = true; }
Tmux::new() tmux.add_command(switch)
.add_command(switch)
.stderr(NULL).output().ok(); .stderr(NULL).output().ok();
} }