created switch command
This commit is contained in:
parent
41a64f039f
commit
5c3fb7df3f
3 changed files with 35 additions and 1 deletions
|
@ -1,4 +1,4 @@
|
||||||
|
|
||||||
pub mod share;
|
pub mod share;
|
||||||
//pub mod session;
|
pub mod session;
|
||||||
|
|
||||||
|
|
31
src/command/session.rs
Normal file
31
src/command/session.rs
Normal 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();
|
||||||
|
}
|
||||||
|
|
|
@ -64,6 +64,9 @@ fn main() {
|
||||||
Some("n" | "new")
|
Some("n" | "new")
|
||||||
=> command::share::new(&mut args),
|
=> command::share::new(&mut args),
|
||||||
|
|
||||||
|
Some("s" | "switch")
|
||||||
|
=> command::session::switch(&mut args),
|
||||||
|
|
||||||
_
|
_
|
||||||
=> error::no_subcommand(subcommand.unwrap())
|
=> error::no_subcommand(subcommand.unwrap())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue