Compare commits
No commits in common. "4615777cae3baa37bd92ab78e87dd6336b39f5ad" and "41a64f039f8112f5b80a7e66bbecf2634d914846" have entirely different histories.
4615777cae
...
41a64f039f
7 changed files with 5 additions and 71 deletions
|
@ -1,4 +1,4 @@
|
|||
|
||||
pub mod share;
|
||||
pub mod session;
|
||||
//pub mod session;
|
||||
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
//! 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) {
|
||||
// refuse to run outside a session
|
||||
util::session_enforce("switch");
|
||||
|
||||
// consume optional flags
|
||||
let read_only = pargs.contains(flag::READ_ONLY);
|
||||
//TODO: -d flag handling needs to be done manually
|
||||
|
||||
let args = pargs.clone().finish();
|
||||
if args.len() < 1 { error::missing_target(); }
|
||||
let target = args.get(0).unwrap().to_string_lossy().to_string();
|
||||
|
||||
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);
|
||||
if read_only { switch.read_only = true; }
|
||||
|
||||
Tmux::new()
|
||||
.add_command(switch)
|
||||
.output().ok();
|
||||
}
|
||||
|
|
@ -55,7 +55,7 @@ pub fn attach(pargs: &mut Arguments) {
|
|||
// build dispatch
|
||||
let mut tmux = Tmux::new().add_command(attach);
|
||||
if let Some(select_window) = select_window { tmux = tmux.add_command(select_window); }
|
||||
tmux.disable_echo().output().ok();
|
||||
tmux.output().ok();
|
||||
}
|
||||
|
||||
pub fn detach(pargs: &mut Arguments) {
|
||||
|
@ -77,7 +77,7 @@ pub fn detach(pargs: &mut Arguments) {
|
|||
.target_session(target);
|
||||
Tmux::new()
|
||||
.add_command(detach)
|
||||
.disable_echo().output().ok();
|
||||
.output().ok();
|
||||
}
|
||||
|
||||
pub fn has(pargs: &mut Arguments) {
|
||||
|
@ -168,6 +168,7 @@ pub fn new(pargs: &mut Arguments) {
|
|||
|
||||
Tmux::new()
|
||||
.add_command(new)
|
||||
.disable_echo().output().ok();
|
||||
|
||||
.output().ok();
|
||||
}
|
||||
|
||||
|
|
|
@ -37,9 +37,3 @@ pub fn not_nesting() {
|
|||
exit(6);
|
||||
}
|
||||
|
||||
/// tried to run a session command outside a session; code 7
|
||||
pub fn not_in_session(cmd: &'static str) {
|
||||
println!("remux: '{cmd}' must be run from within a session");
|
||||
exit(7);
|
||||
}
|
||||
|
||||
|
|
15
src/help.rs
15
src/help.rs
|
@ -91,21 +91,6 @@ flags:
|
|||
-n, --nest Create the session inside another session.
|
||||
-t, --target <dir> Sets the target directory for the new session."),
|
||||
|
||||
Some("s" | "switch")
|
||||
=>
|
||||
println!("remux switch
|
||||
Switch to a different tmux session.
|
||||
Must be run from inside a session.
|
||||
|
||||
usage: remux switch [flags] <title>
|
||||
remux s [flags] <title>
|
||||
|
||||
args:
|
||||
<title> The title of the session to switch to.
|
||||
|
||||
flags:
|
||||
-r, --read-only Attach the target session as read-only."),
|
||||
|
||||
// not found
|
||||
_ => error::no_help(topic.unwrap())
|
||||
}
|
||||
|
|
|
@ -64,9 +64,6 @@ fn main() {
|
|||
Some("n" | "new")
|
||||
=> command::share::new(&mut args),
|
||||
|
||||
Some("s" | "switch")
|
||||
=> command::session::switch(&mut args),
|
||||
|
||||
_
|
||||
=> error::no_subcommand(subcommand.unwrap())
|
||||
}
|
||||
|
|
|
@ -30,20 +30,11 @@ pub fn prevent_nest() {
|
|||
}
|
||||
}
|
||||
|
||||
/// enforce a command is being used in-session
|
||||
pub fn session_enforce(cmd: &'static str) {
|
||||
let tmux = var("TMUX").unwrap_or("".to_string());
|
||||
if tmux.is_empty() {
|
||||
error::not_in_session(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
/// check whether a target session exists
|
||||
pub fn session_exists<S: Into<String>>(target: S) -> bool {
|
||||
let has_session = commands::HasSession::new()
|
||||
.target_session(target.into());
|
||||
Tmux::new().add_command(has_session)
|
||||
.disable_echo()
|
||||
.status()
|
||||
.unwrap()
|
||||
.success()
|
||||
|
|
Loading…
Reference in a new issue