diff --git a/src/command/session.rs b/src/command/session.rs index 47c9da9..3bd3584 100644 --- a/src/command/session.rs +++ b/src/command/session.rs @@ -1,4 +1,5 @@ //! commands accessible from within a session +use std::fs::read_to_string; use pico_args::Arguments; use tmux_interface::{ @@ -8,7 +9,10 @@ use tmux_interface::{ use crate::{ error, flag, util }; +const TMP_ROOT: &str = "/tmp/remux_root"; + pub fn switch(pargs: &mut Arguments) { + util::terminal_enforce(); // refuse to run outside a session util::session_enforce("switch"); @@ -32,3 +36,17 @@ pub fn switch(pargs: &mut Arguments) { .output().ok(); } +pub fn root() { + util::session_enforce("root"); + + let exec = commands::Run::new().shell_command("printf '#{session_path}' > ".to_string() + TMP_ROOT); + Tmux::new() + .add_command(exec) + .output().ok(); + + if let Ok(text) = read_to_string(TMP_ROOT) { + println!("{text}"); + std::fs::remove_file(TMP_ROOT).ok(); + } +} + diff --git a/src/command/share.rs b/src/command/share.rs index 028d9ca..81f23a4 100644 --- a/src/command/share.rs +++ b/src/command/share.rs @@ -15,6 +15,8 @@ use tmux_interface::{ use crate::{ error, flag, util }; pub fn attach(pargs: &mut Arguments) { + // must be run from terminal + util::terminal_enforce(); // don't allow unflagged nests util::prevent_nest(); @@ -59,6 +61,7 @@ pub fn attach(pargs: &mut Arguments) { } pub fn detach(pargs: &mut Arguments) { + util::terminal_enforce(); // get target or fallback let args = pargs.clone().finish(); let target: String; @@ -142,6 +145,7 @@ pub fn list() { } pub fn new(pargs: &mut Arguments) { + util::terminal_enforce(); // don't allow unflagged nesting util::prevent_nest(); diff --git a/src/help.rs b/src/help.rs index 1c78b45..f3180ac 100644 --- a/src/help.rs +++ b/src/help.rs @@ -91,6 +91,14 @@ flags: -n, --nest Create the session inside another session. -t, --target