created switch command

This commit is contained in:
Valerie Wolfe 2024-03-07 17:10:45 -05:00
parent 41a64f039f
commit 5c3fb7df3f
3 changed files with 35 additions and 1 deletions

View file

@ -1,4 +1,4 @@
pub mod share;
//pub mod session;
pub mod session;

31
src/command/session.rs Normal file
View file

@ -0,0 +1,31 @@
//! commands accessible from within a session
use pico_args::Arguments;
use tmux_interface::{
Tmux,
commands
};
use crate::{ error, flag, util };
pub fn switch(pargs: &mut Arguments) {
// consume optional flags
let read_only = pargs.contains(flag::READ_ONLY);
let detach_other = pargs.contains(flag::DETACHED);
let args = pargs.clone().finish();
if args.len() < 1 { error::missing_target(); }
let target = args.get(0).unwrap().to_string_lossy().to_string();
println!("{target}");
let exists = util::session_exists(target.clone());
if !exists { error::no_target(target.clone()); }
let mut switch = commands::SwitchClient::new();
switch = switch.target_session(target);
Tmux::new()
.add_command(switch)
.output().ok();
}

View file

@ -64,6 +64,9 @@ fn main() {
Some("n" | "new")
=> command::share::new(&mut args),
Some("s" | "switch")
=> command::session::switch(&mut args),
_
=> error::no_subcommand(subcommand.unwrap())
}