From aba802e77d094936b2bee8a453cd2266da0fa9e1 Mon Sep 17 00:00:00 2001 From: Valerie Date: Wed, 6 Mar 2024 15:54:41 -0500 Subject: [PATCH 01/27] upgraded tmux_interface to 0.3.2 and restructured command module --- Cargo.toml | 4 +- src/command.rs | 170 ------------------------------------------- src/command/mod.rs | 4 + src/command/share.rs | 170 +++++++++++++++++++++++++++++++++++++++++++ src/flag.rs | 11 +++ src/main.rs | 17 +++-- src/util.rs | 25 ++++--- 7 files changed, 209 insertions(+), 192 deletions(-) delete mode 100644 src/command.rs create mode 100644 src/command/mod.rs create mode 100644 src/command/share.rs create mode 100644 src/flag.rs diff --git a/Cargo.toml b/Cargo.toml index baafae3..6d24041 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "remux" -version = "0.2.0" +version = "0.3.0" edition = "2021" authors = [ "Valerie Wolfe " ] description = "A friendly command shortener for tmux" @@ -15,7 +15,7 @@ path = "src/main.rs" [dependencies] pico-args = { version = "0.5.0", features = [ "combined-flags", "eq-separator" ] } termion = "2.0.1" -tmux_interface = "0.2.1" +tmux_interface = "0.3.2" [profile.release] opt-level = 's' diff --git a/src/command.rs b/src/command.rs deleted file mode 100644 index 984f857..0000000 --- a/src/command.rs +++ /dev/null @@ -1,170 +0,0 @@ -use std::{ - env::current_dir, - ffi::OsString, - process::exit -}; - -use pico_args::Arguments; -use termion::{ color, style }; -use tmux_interface::TmuxCommand; - -use crate::error; -use crate::util; - -pub fn attach(pargs: &mut Arguments) { - util::prevent_nest(); - - // get optional flags - let read_only = pargs.contains(["-r", "--readonly"]); - let detach_other = pargs.contains(["-d", "--detach"]); - - // collect target and window arguments - let args = pargs.clone().finish(); - let target: String; - let window: Option<&OsString>; - if args.len() < 1 { - // missing name will attempt to fall back to repository - target = util::repo_fallback(); - if !util::session_exists(target.clone()) { error::missing_target(); } - window = None; - } else { - target = args.get(0).unwrap().to_string_lossy().to_string(); - window = args.get(1); - } - - // focus window if provided - if window.is_some() { - let target = window.unwrap().to_string_lossy(); - TmuxCommand::new() - .select_window() - .target_window(target) - .output().ok(); - } - - // make sure the target session exists - let exists = util::session_exists(target.clone()); - if !exists { error::no_target(target.clone()); } - - // build command - let mut attach = TmuxCommand::new().attach_session(); - - // handle optional flags - if read_only { attach.read_only(); } - if detach_other { attach.detach_other(); } - - // run command - attach - .target_session(target) - .output().ok(); -} - -pub fn detach(pargs: &mut Arguments) { - // get target and error out if not provided - let args = pargs.clone().finish(); - if args.len() < 1 { error::missing_target(); } - let target = args.get(0).unwrap().to_string_lossy(); - - // make sure the target session exists - let exists = util::session_exists(target.clone()); - if !exists { error::no_target(target.clone()); } - - // build command and run - TmuxCommand::new() - .detach_client() - .target_session(target) - .output().ok(); -} - -pub fn has(pargs: &mut Arguments) { - // get optional flag - let quiet = pargs.contains(["-q", "--quiet"]); - - // collect target argument - let args = pargs.clone().finish(); - let target: String; - if args.len() < 1 { - // missing name will attempt to fall back to repository - target = util::repo_fallback(); - } else { - target = args.get(0).unwrap().to_string_lossy().to_string(); - } - - // run command - let success = util::session_exists(target.clone()); - - // handle optional flag - // inverted; print text if NOT quiet - if !quiet { println!("session \"{target}\" {}.", if success { "exists" } else { "does not exist" }); } - - // exit codes for scripts to use - exit( if success { 0 } else { 1 }); -} - -pub fn list() { - // get session list - let sessions = util::get_sessions().unwrap_or(Vec::new()); - - // handle empty case - if sessions.len() == 0 { - println!("no sessions"); - return; - } - - // iterate over pretty print - println!("sessions:"); - for session in sessions.into_iter() { - let group = session.group.unwrap_or("[untitled]".to_string()); - let id = session.id.unwrap(); - let attached = session.attached.unwrap_or(0) > 0; - - println!( - " {group} ({bold}{blue}{id}{reset}) {bold}{green}{attach_sym}{reset}", - // values - attach_sym = if attached { "󰌹" } else {""}, - // formatting - bold = style::Bold, - blue = color::Fg(color::Blue), - green = color::Fg(color::LightGreen), - reset = style::Reset - ); - } -} - -pub fn new(pargs: &mut Arguments) { - use pico_args::Error; - - // show nest message - util::prevent_nest(); - - // get optional flag - let target_dir: Result = pargs.value_from_str(["-t", "--target"]); - - // get target and error out if not provided - let args = pargs.clone().finish(); - - // collect name and command arguments - let title: String; - let command: Option<&OsString>; - if args.len() < 1 { - // missing name will attempt to fall back to repository - title = util::repo_fallback(); - command = None; - } else { - title = args.get(0).unwrap().to_string_lossy().to_string(); - command = args.get(1); - } - - // build command - let mut new = TmuxCommand::new().new_session(); - - // handle shell command argument - if command.is_some() { new.shell_command(command.unwrap().to_string_lossy()); } - - // run command - new - .group_name(title) - .attach() - .start_directory(target_dir.unwrap_or(current_dir().unwrap().to_string_lossy().to_string())) - .output().ok(); -} - diff --git a/src/command/mod.rs b/src/command/mod.rs new file mode 100644 index 0000000..8b5d2e6 --- /dev/null +++ b/src/command/mod.rs @@ -0,0 +1,4 @@ + +pub mod share; +//pub mod session; + diff --git a/src/command/share.rs b/src/command/share.rs new file mode 100644 index 0000000..0de817b --- /dev/null +++ b/src/command/share.rs @@ -0,0 +1,170 @@ +//! globally available tmux commands. +use std::{ + ffi::OsString, + process::exit +}; + +use pico_args::{ Arguments, Error }; +use termion::{ color, style }; +use tmux_interface::{ + Tmux, + commands +}; + +use crate::{ error, flag, util }; + +pub fn attach(pargs: &mut Arguments) { + // don't allow unflagged nests + util::prevent_nest(); + + // consume optional flags + let read_only = pargs.contains(flag::READ_ONLY); + let detach_other = pargs.contains(flag::DETACHED); + + let args = pargs.clone().finish(); + let target: String; + let window: Option<&OsString>; + if args.len() < 1 { + // missing name will attempt to fall back to repository + target = util::repo_fallback(); + if !util::session_exists(target.clone()) { error::missing_target(); } + window = None; + } else { + target = args.get(0).unwrap().to_string_lossy().to_string(); + window = args.get(1); + } + + // make sure the session exists + let exists = util::session_exists(target.clone()); + if !exists { error::no_target(target.clone()); } + + // build attach command + let mut attach = commands::AttachSession::new(); + attach = attach.target_session(target); + if read_only { attach.read_only = true; } + if detach_other { attach.detach_other = true; } + + let select_window: Option; + if let Some(window) = window { + let mut command = commands::SelectWindow::new(); + command.target_window = Some(window.to_string_lossy()); + select_window = Some(command); + } else { select_window = None; } + + // build dispatch + let mut tmux = Tmux::new().add_command(attach); + if let Some(select_window) = select_window { tmux = tmux.add_command(select_window); } + tmux.output().ok(); +} + +pub fn detach(pargs: &mut Arguments) { + // get target or fallback + let args = pargs.clone().finish(); + let target: String; + if args.len() < 1 { + target = util::repo_fallback(); + } else { + target = args.get(0).unwrap().to_string_lossy().to_string(); + } + + // make sure the session exists + let exists = util::session_exists(target.clone()); + if !exists { error::no_target(target.clone()); } + + // build and dispatch + let detach = commands::DetachClient::new() + .target_session(target); + Tmux::new() + .add_command(detach) + .output().ok(); +} + +pub fn has(pargs: &mut Arguments) { + // consume optional flags + let quiet = pargs.contains(flag::QUIET); + + // get target or fallback + let args = pargs.clone().finish(); + let target: String; + if args.len() < 1 { + target = util::repo_fallback(); + } else { + target = args.get(0).unwrap().to_string_lossy().to_string(); + } + + // run command + let success = util::session_exists(target.clone()); + + // print if not quiet + if !quiet { + println!("session \"{target}\" {}.", + if success { "exists" } + else { "does not exist" } + ); + } + + // emit exit code + exit( if success { 0 } else { 1 }); +} + +pub fn list() { + // get session list + let sessions = util::get_sessions().unwrap_or(Vec::new()); + + // handle empty case + if sessions.len() == 0 { + println!("no sessions"); + return; + } + + // pretty print session list + println!("sessions:"); + for session in sessions.into_iter() { + let group = session.group.unwrap_or("[untitled]".to_string()); + let id = session.id.unwrap(); + let attached = session.attached.unwrap_or(0) > 0; + + println!( + " {group} ({bold}{blue}{id}{reset}) {bold}{green}{attach_sym}{reset}", + // value + attach_sym = if attached { "\u{F0339}" } else { "" }, + // formatting + bold = style::Bold, + blue = color::Fg(color::Blue), + green = color::Fg(color::LightGreen), + reset = style::Reset + ); + } +} + +pub fn new(pargs: &mut Arguments) { + // don't allow unflagged nesting + util::prevent_nest(); + + // get optional flag + let target_dir: Result = pargs.value_from_str(flag::TARGET); + + // get target or fallback + let args = pargs.clone().finish(); + let title: String; + let command: Option<&OsString>; + if args.len() < 1 { + // attempt repo fallback + title = util::repo_fallback(); + command = None; + } else { + title = args.get(0).unwrap().to_string_lossy().to_string(); + command = args.get(1); + } + + let mut new = commands::NewSession::new(); + new = new.group_name(title); + if let Some(command) = command { new.shell_command = Some(command.to_string_lossy()); } + if let Ok(target_dir) = target_dir { new = new.start_directory(target_dir); } + + Tmux::new() + .add_command(new) + + .output().ok(); +} + diff --git a/src/flag.rs b/src/flag.rs new file mode 100644 index 0000000..92056f3 --- /dev/null +++ b/src/flag.rs @@ -0,0 +1,11 @@ + +type Flag = [&'static str;2]; + +pub static DETACHED: Flag = ["-d", "--detached"]; +pub static HELP: Flag = ["-h", "--help"]; +pub static NEST: Flag = ["-n", "--nest"]; +pub static QUIET: Flag = ["-q", "--quiet"]; +pub static READ_ONLY: Flag = ["-r", "--read-only"]; +pub static TARGET: Flag = ["-t", "--target"]; +pub static VERSION: Flag = ["-v", "--version"]; + diff --git a/src/main.rs b/src/main.rs index 4757ee0..4276941 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,6 +7,7 @@ use pico_args::Arguments; mod command; mod error; +mod flag; mod help; mod util; @@ -19,17 +20,17 @@ fn main() { let mut args = Arguments::from_env(); // consume flags - if args.contains(["-h", "--help"]) { + if args.contains(flag::HELP) { help(&mut args); return; } - if args.contains(["-v", "--version"]) { + if args.contains(flag::VERSION) { version(); return; } - let nesting = args.contains(["-n", "--nest"]); + let nesting = args.contains(flag::NEST); let tmux_var = var("TMUX").ok(); if nesting { if tmux_var.is_none() { @@ -48,20 +49,20 @@ fn main() { => help(&mut args), Some("a" | "attach") - => command::attach(&mut args), + => command::share::attach(&mut args), Some("d" | "detach") - => command::detach(&mut args), + => command::share::detach(&mut args), Some("has") - => command::has(&mut args), + => command::share::has(&mut args), None | Some("l" | "ls" | "list") - => command::list(), + => command::share::list(), Some("n" | "new") - => command::new(&mut args), + => command::share::new(&mut args), _ => error::no_subcommand(subcommand.unwrap()) diff --git a/src/util.rs b/src/util.rs index e5ced2f..c99302b 100644 --- a/src/util.rs +++ b/src/util.rs @@ -5,20 +5,20 @@ use std::{ }; use tmux_interface::{ - Session, Sessions, TmuxCommand, - variables::session::session::SESSION_ALL + Session, Tmux, + + commands, + variables::session::SessionsCtl }; use crate::error; /// return a Vec of all sessions or None pub fn get_sessions() -> Option> { - let i_sessions = Sessions::get(SESSION_ALL); - if i_sessions.is_err() { return None; } - let sessions = i_sessions.ok(); - if sessions.is_none() { return None; } - - Some(sessions.unwrap().0) + let sessions = SessionsCtl::new().get_all(); + if let Ok(sessions) = sessions { + return Some(sessions.0); + } else { return None; } } /// show the tmux nest text if env var is not unset @@ -32,10 +32,11 @@ pub fn prevent_nest() { /// check whether a target session exists pub fn session_exists>(target: S) -> bool { - TmuxCommand::new() - .has_session() - .target_session(target.into()) - .output().unwrap() + let has_session = commands::HasSession::new() + .target_session(target.into()); + Tmux::new().add_command(has_session) + .status() + .unwrap() .success() } From 63335916d92bd90fa024accaff40efe7c9a12dbc Mon Sep 17 00:00:00 2001 From: Valerie Date: Wed, 6 Mar 2024 15:59:40 -0500 Subject: [PATCH 02/27] updated README --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f895e1d..c1f6369 100644 --- a/README.md +++ b/README.md @@ -41,9 +41,9 @@ remux n -n foo ``` -If you're working in a git repository, the `attach`, `has`, and `new` commands -can be used without a session title, and the repository directory name will be -used instead. +If you're working in a git repository, the `attach`, `detach`, `has`, and `new` +commands can be used without a session title, and the repository directory name +will be used instead. ## Dependencies From 9c814c43f4ac53d92bea42ad1dc36654579e472d Mon Sep 17 00:00:00 2001 From: Valerie Date: Wed, 6 Mar 2024 16:05:53 -0500 Subject: [PATCH 03/27] updated README --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c1f6369..9b57ef8 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,10 @@ A tmux wrapper and command shortener written in Rust. ReMux's goal is to wrap tmux commands to be both shorter, and oriented around session names instead of session IDs. +To further simplify developer usage, the `attach`, `detach`, `has`, and `new` +commands can be used without a target field, and will default to the name of +the Git repository root directory, if one is found. + In their shortest forms, *every* ReMux command is as short or shorter than its equivalent tmux command: @@ -41,10 +45,6 @@ remux n -n foo ``` -If you're working in a git repository, the `attach`, `detach`, `has`, and `new` -commands can be used without a session title, and the repository directory name -will be used instead. - ## Dependencies ReMux depends on [tmux](https://github.com/tmux/tmux). From be593c82e75a80f8ba65308fd8b1766e1a4708c2 Mon Sep 17 00:00:00 2001 From: Valerie Date: Wed, 6 Mar 2024 16:12:54 -0500 Subject: [PATCH 04/27] list attach symbol is now configurable --- README.md | 4 ++++ src/command/share.rs | 10 +++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9b57ef8..ee793c7 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,10 @@ using an AUR package manager such as 0; println!( - " {group} ({bold}{blue}{id}{reset}) {bold}{green}{attach_sym}{reset}", - // value - attach_sym = if attached { "\u{F0339}" } else { "" }, + " {group} ({bold}{blue}{id}{reset}) {bold}{green}{attach}{reset}", + // values + attach = if attached { attach_symbol.clone() } else { "".to_string() }, // formatting bold = style::Bold, blue = color::Fg(color::Blue), From 41a64f039f8112f5b80a7e66bbecf2634d914846 Mon Sep 17 00:00:00 2001 From: Valerie Date: Thu, 7 Mar 2024 16:54:16 -0500 Subject: [PATCH 05/27] revised incorrect help text for 'new' and 'attach' commands --- src/help.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/help.rs b/src/help.rs index a5841cc..0e7b14c 100644 --- a/src/help.rs +++ b/src/help.rs @@ -40,7 +40,7 @@ args: flags: -d, --detach Detach other attached clients from the session -n, --nest Attach the session inside another session. - -r, --readonly Attach the session as read-only"), + -r, --read-only Attach the session as read-only"), Some("d" | "detach") => @@ -81,6 +81,7 @@ println!("remux new Create a new tmux session. usage: remux new [flags] [command] + remux n [flags] <title> [command] args: <title> The title of the new session From 5c3fb7df3f3d22c03ea982c6f0904e631e06dcfd Mon Sep 17 00:00:00 2001 From: Valerie <sleeplessval@gmail.com> Date: Thu, 7 Mar 2024 17:10:45 -0500 Subject: [PATCH 06/27] created switch command --- src/command/mod.rs | 2 +- src/command/session.rs | 31 +++++++++++++++++++++++++++++++ src/main.rs | 3 +++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/command/session.rs diff --git a/src/command/mod.rs b/src/command/mod.rs index 8b5d2e6..54859f3 100644 --- a/src/command/mod.rs +++ b/src/command/mod.rs @@ -1,4 +1,4 @@ pub mod share; -//pub mod session; +pub mod session; diff --git a/src/command/session.rs b/src/command/session.rs new file mode 100644 index 0000000..4f6028b --- /dev/null +++ b/src/command/session.rs @@ -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(); +} + diff --git a/src/main.rs b/src/main.rs index 4276941..f610b1e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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()) } From b00e15a0377d911f50015418a7f2a6e5a8b1cb0f Mon Sep 17 00:00:00 2001 From: Valerie <sleeplessval@gmail.com> Date: Fri, 8 Mar 2024 10:04:24 -0500 Subject: [PATCH 07/27] switch command now must run in-session --- src/command/session.rs | 7 +++++-- src/command/share.rs | 7 +++---- src/error.rs | 6 ++++++ src/util.rs | 9 +++++++++ 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/command/session.rs b/src/command/session.rs index 4f6028b..47c9da9 100644 --- a/src/command/session.rs +++ b/src/command/session.rs @@ -9,20 +9,23 @@ use tmux_interface::{ 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); - let detach_other = pargs.contains(flag::DETACHED); + //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(); - 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); + if read_only { switch.read_only = true; } Tmux::new() .add_command(switch) diff --git a/src/command/share.rs b/src/command/share.rs index 6b1e68e..e46150b 100644 --- a/src/command/share.rs +++ b/src/command/share.rs @@ -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.output().ok(); + tmux.disable_echo().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) - .output().ok(); + .disable_echo().output().ok(); } pub fn has(pargs: &mut Arguments) { @@ -168,7 +168,6 @@ pub fn new(pargs: &mut Arguments) { Tmux::new() .add_command(new) - - .output().ok(); + .disable_echo().output().ok(); } diff --git a/src/error.rs b/src/error.rs index e610de9..194245f 100644 --- a/src/error.rs +++ b/src/error.rs @@ -37,3 +37,9 @@ 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); +} + diff --git a/src/util.rs b/src/util.rs index c99302b..f6bca95 100644 --- a/src/util.rs +++ b/src/util.rs @@ -30,11 +30,20 @@ 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() From 4615777cae3baa37bd92ab78e87dd6336b39f5ad Mon Sep 17 00:00:00 2001 From: Valerie <sleeplessval@gmail.com> Date: Fri, 8 Mar 2024 10:23:02 -0500 Subject: [PATCH 08/27] added help topic for switch --- src/help.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/help.rs b/src/help.rs index 0e7b14c..1c78b45 100644 --- a/src/help.rs +++ b/src/help.rs @@ -91,6 +91,21 @@ 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()) } From 882e130121b3c7bcba6ad2b0df10ddb189d472de Mon Sep 17 00:00:00 2001 From: Valerie <sleeplessval@gmail.com> Date: Fri, 8 Mar 2024 10:26:00 -0500 Subject: [PATCH 09/27] fixed tmux dispatch echoing command information --- src/command/share.rs | 7 +++---- src/util.rs | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/command/share.rs b/src/command/share.rs index 6b1e68e..e46150b 100644 --- a/src/command/share.rs +++ b/src/command/share.rs @@ -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.output().ok(); + tmux.disable_echo().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) - .output().ok(); + .disable_echo().output().ok(); } pub fn has(pargs: &mut Arguments) { @@ -168,7 +168,6 @@ pub fn new(pargs: &mut Arguments) { Tmux::new() .add_command(new) - - .output().ok(); + .disable_echo().output().ok(); } diff --git a/src/util.rs b/src/util.rs index c99302b..e8d8831 100644 --- a/src/util.rs +++ b/src/util.rs @@ -35,6 +35,7 @@ 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() From 782fb694d027e46133229de436ece9bf87cb9db7 Mon Sep 17 00:00:00 2001 From: Valerie <sleeplessval@gmail.com> Date: Fri, 8 Mar 2024 13:50:27 -0500 Subject: [PATCH 10/27] removed disable_echo flag from commands that don't support it --- src/command/share.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/command/share.rs b/src/command/share.rs index e46150b..1bf96ab 100644 --- a/src/command/share.rs +++ b/src/command/share.rs @@ -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,6 @@ pub fn new(pargs: &mut Arguments) { Tmux::new() .add_command(new) - .disable_echo().output().ok(); + .output().ok(); } From e017d57a539cfee3dbf422d53ad2c0026e70633c Mon Sep 17 00:00:00 2001 From: Valerie <sleeplessval@gmail.com> Date: Mon, 10 Jun 2024 12:01:15 -0400 Subject: [PATCH 11/27] initial implementation of root command and made some commands allow being thrown through pipes --- src/command/session.rs | 18 ++++++++++++++++++ src/command/share.rs | 4 ++++ src/help.rs | 8 ++++++++ src/main.rs | 10 ++++------ src/util.rs | 6 ++++++ 5 files changed, 40 insertions(+), 6 deletions(-) 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 <dir> Sets the target directory for the new session."), + Some("root") + => +println!("remux root +Print the session path (#{{session_path}}) to standard output. +Must be run from inside a session. + +usage: remux root"), + Some("s" | "switch") => println!("remux switch diff --git a/src/main.rs b/src/main.rs index f610b1e..d4883f7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,4 @@ -use std::{ - env::{ set_var, var }, - io::{ stdout, IsTerminal } -}; +use std::env::{ set_var, var }; use pico_args::Arguments; @@ -39,8 +36,6 @@ fn main() { set_var("TMUX", ""); } - if !stdout().is_terminal() { error::not_terminal(); } - let subcommand = args.subcommand().unwrap(); // invoke subcommand function @@ -64,6 +59,9 @@ fn main() { Some("n" | "new") => command::share::new(&mut args), + Some("root") + => command::session::root(), + Some("s" | "switch") => command::session::switch(&mut args), diff --git a/src/util.rs b/src/util.rs index f6bca95..2042764 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1,5 +1,6 @@ use std::{ env::{ current_dir, var }, + io::{ stdout, IsTerminal }, path::PathBuf, process::exit }; @@ -49,6 +50,11 @@ pub fn session_exists<S: Into<String>>(target: S) -> bool { .success() } +/// enforce a command is being run in a terminal +pub fn terminal_enforce() { + if !stdout().is_terminal() { error::not_terminal(); } +} + /// attempt to return the repo name or exit pub fn repo_fallback() -> String { let repo = repo_root(current_dir().unwrap()); From 2e28acc3c386c678fb0c4f3a51a8880c571411dc Mon Sep 17 00:00:00 2001 From: Valerie <sleeplessval@gmail.com> Date: Mon, 10 Jun 2024 12:01:15 -0400 Subject: [PATCH 12/27] version bump --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 6d24041..69d5081 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "remux" -version = "0.3.0" +version = "0.3.1" edition = "2021" authors = [ "Valerie Wolfe <sleeplessval@gmail.com>" ] description = "A friendly command shortener for tmux" From 21f7b72298ffdd8a94f4fd228b1b4d4c0058a659 Mon Sep 17 00:00:00 2001 From: Valerie <sleeplessval@gmail.com> Date: Mon, 10 Jun 2024 12:01:15 -0400 Subject: [PATCH 13/27] removed incompatible disable_echo from session exist check --- src/util.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/util.rs b/src/util.rs index 2042764..d37dd74 100644 --- a/src/util.rs +++ b/src/util.rs @@ -44,7 +44,6 @@ 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() From 92d001018607f33185c189286b9932b769d670a1 Mon Sep 17 00:00:00 2001 From: Valerie <sleeplessval@gmail.com> Date: Mon, 10 Jun 2024 12:01:15 -0400 Subject: [PATCH 14/27] renamed detach flag and added detach support to 'new' --- src/command/share.rs | 4 +++- src/flag.rs | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/command/share.rs b/src/command/share.rs index 81f23a4..c9c28d9 100644 --- a/src/command/share.rs +++ b/src/command/share.rs @@ -22,7 +22,7 @@ pub fn attach(pargs: &mut Arguments) { // consume optional flags let read_only = pargs.contains(flag::READ_ONLY); - let detach_other = pargs.contains(flag::DETACHED); + let detach_other = pargs.contains(flag::DETACH); let args = pargs.clone().finish(); let target: String; @@ -150,6 +150,7 @@ pub fn new(pargs: &mut Arguments) { util::prevent_nest(); // get optional flag + let detached = pargs.contains(flag::DETACH); let target_dir: Result<String, Error> = pargs.value_from_str(flag::TARGET); // get target or fallback @@ -168,6 +169,7 @@ pub fn new(pargs: &mut Arguments) { let mut new = commands::NewSession::new(); new = new.group_name(title); if let Some(command) = command { new.shell_command = Some(command.to_string_lossy()); } + if detached { new.detached = true; } if let Ok(target_dir) = target_dir { new = new.start_directory(target_dir); } Tmux::new() diff --git a/src/flag.rs b/src/flag.rs index 92056f3..4c7066d 100644 --- a/src/flag.rs +++ b/src/flag.rs @@ -1,7 +1,7 @@ type Flag = [&'static str;2]; -pub static DETACHED: Flag = ["-d", "--detached"]; +pub static DETACH: Flag = ["-d", "--detach"]; pub static HELP: Flag = ["-h", "--help"]; pub static NEST: Flag = ["-n", "--nest"]; pub static QUIET: Flag = ["-q", "--quiet"]; From c8800a7f53ab309aa991d91267c687b89239ee65 Mon Sep 17 00:00:00 2001 From: Valerie <sleeplessval@gmail.com> Date: Mon, 10 Jun 2024 12:01:15 -0400 Subject: [PATCH 15/27] created env module --- src/env.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/env.rs diff --git a/src/env.rs b/src/env.rs new file mode 100644 index 0000000..4c828bc --- /dev/null +++ b/src/env.rs @@ -0,0 +1,10 @@ +use std::env::{ set_var, var }; + +pub type ENV_VAR = (&'static str, &'static str); + +pub static ATTACH_SYMBOL: ENV_VAR = ("ATTACH_SYMBOL", "*"); + +pub fn env_var(var: ENV_VAR) -> String { + var(var.0).unwrap_or(var.1.to_string()) +} + From a07ae193b5b2645267b98fc35c0cdcec86f84256 Mon Sep 17 00:00:00 2001 From: Valerie <sleeplessval@gmail.com> Date: Mon, 10 Jun 2024 12:02:02 -0400 Subject: [PATCH 16/27] moved environment variable code to a new module --- src/command/share.rs | 10 +++++++--- src/env.rs | 12 +++++++----- src/main.rs | 1 + src/util.rs | 12 +++++++----- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/command/share.rs b/src/command/share.rs index c9c28d9..43fea42 100644 --- a/src/command/share.rs +++ b/src/command/share.rs @@ -1,6 +1,5 @@ //! globally available tmux commands. use std::{ - env::var, ffi::OsString, process::exit }; @@ -12,7 +11,12 @@ use tmux_interface::{ commands }; -use crate::{ error, flag, util }; +use crate::{ + env::{ self, env_var }, + error, + flag, + util +}; pub fn attach(pargs: &mut Arguments) { // must be run from terminal @@ -122,7 +126,7 @@ pub fn list() { } // get attached session symbol - let attach_symbol = var("REMUX_ATTACH_SYMBOL").unwrap_or("*".to_string()); + let attach_symbol = env_var(env::ATTACH_SYMBOL); // pretty print session list println!("sessions:"); diff --git a/src/env.rs b/src/env.rs index 4c828bc..b5fd791 100644 --- a/src/env.rs +++ b/src/env.rs @@ -1,10 +1,12 @@ -use std::env::{ set_var, var }; +use std::env::var; -pub type ENV_VAR = (&'static str, &'static str); +pub type EnvVar = (&'static str, &'static str); -pub static ATTACH_SYMBOL: ENV_VAR = ("ATTACH_SYMBOL", "*"); +pub static ATTACH_SYMBOL: EnvVar = ("ATTACH_SYMBOL", "*"); -pub fn env_var(var: ENV_VAR) -> String { - var(var.0).unwrap_or(var.1.to_string()) +pub fn env_var(envvar: EnvVar) -> String { + var(envvar.0).unwrap_or(envvar.1.to_string()) } +pub fn tmux() -> bool { !var("TMUX").unwrap_or("".to_string()).is_empty() } + diff --git a/src/main.rs b/src/main.rs index d4883f7..a1c9cf1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ use std::env::{ set_var, var }; use pico_args::Arguments; mod command; +mod env; mod error; mod flag; mod help; diff --git a/src/util.rs b/src/util.rs index d37dd74..fd6e953 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1,5 +1,5 @@ use std::{ - env::{ current_dir, var }, + env::current_dir, io::{ stdout, IsTerminal }, path::PathBuf, process::exit @@ -12,7 +12,10 @@ use tmux_interface::{ variables::session::SessionsCtl }; -use crate::error; +use crate::{ + env, + error +}; /// return a Vec of all sessions or None pub fn get_sessions() -> Option<Vec<Session>> { @@ -24,10 +27,9 @@ pub fn get_sessions() -> Option<Vec<Session>> { /// show the tmux nest text if env var is not unset pub fn prevent_nest() { - let tmux = var("TMUX").ok(); - if tmux.is_some() && tmux.unwrap() != "" { + if env::tmux() { println!("Sessions should be nested with care; unset TMUX or use the '-n' flag to allow."); - exit(1); + exit(6); } } From b3403ffa3614f21a2be8fdc29177f2817b5f3810 Mon Sep 17 00:00:00 2001 From: Valerie <sleeplessval@gmail.com> Date: Mon, 10 Jun 2024 12:02:57 -0400 Subject: [PATCH 17/27] wrote help topic for env vars --- src/help.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/help.rs b/src/help.rs index f3180ac..89efe40 100644 --- a/src/help.rs +++ b/src/help.rs @@ -25,7 +25,10 @@ commands: Use 'remux help <command>' to see detailed help text for each command."), - Some("a" | "attach") + +// COMMAND HELP + + Some("a" | "attach") => println!("remux attach Attach to an existing session. @@ -114,7 +117,19 @@ args: flags: -r, --read-only Attach the target session as read-only."), - // not found + +// TOPIC HELP + + Some("env" | "vars") + => +println!("remux environment variables + +REMUX_ATTACH_SYMBOL + Changes the symbol displayed for attached sessions displayed + by the 'list' command. + Default: '*'"), + + // not found _ => error::no_help(topic.unwrap()) } } From d8aaf7feedec2f241930d4ecb12c0e3d8cd428c3 Mon Sep 17 00:00:00 2001 From: Valerie <sleeplessval@gmail.com> Date: Mon, 10 Jun 2024 12:02:57 -0400 Subject: [PATCH 18/27] corrected name of ATTACH_SYMBOL env var --- src/env.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/env.rs b/src/env.rs index b5fd791..d0f79a4 100644 --- a/src/env.rs +++ b/src/env.rs @@ -2,7 +2,7 @@ use std::env::var; pub type EnvVar = (&'static str, &'static str); -pub static ATTACH_SYMBOL: EnvVar = ("ATTACH_SYMBOL", "*"); +pub static ATTACH_SYMBOL: EnvVar = ("REMUX_ATTACH_SYMBOL", "*"); pub fn env_var(envvar: EnvVar) -> String { var(envvar.0).unwrap_or(envvar.1.to_string()) From 681e7427bae21156bd6fee3fa481727fc7055a95 Mon Sep 17 00:00:00 2001 From: Valerie <sleeplessval@gmail.com> Date: Mon, 10 Jun 2024 12:02:57 -0400 Subject: [PATCH 19/27] updated help text to include topics --- src/help.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/help.rs b/src/help.rs index 89efe40..fb9e701 100644 --- a/src/help.rs +++ b/src/help.rs @@ -16,14 +16,17 @@ A command wrapper for tmux written in Rust. usage: remux <command> [<args>] commands: - help Show help text for remux or a specific command + help Show help text for remux, a command, or a help topic. attach Attach to an existing tmux session detach Detach clients from a tmux session has Check if a tmux session exists list Pretty-print all tmux sessions new Create a new tmux session -Use 'remux help <command>' to see detailed help text for each command."), +Use 'remux help <command>' to see detailed help text for each command. + +help topics: + env Environment variables"), // COMMAND HELP From 62d72735da3c9bd63f727f0743d28bde505e6aba Mon Sep 17 00:00:00 2001 From: Valerie <sleeplessval@gmail.com> Date: Mon, 10 Jun 2024 12:02:57 -0400 Subject: [PATCH 20/27] added REMUX_WINDOW_NAME var for add command --- src/command/share.rs | 6 +++++- src/env.rs | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/command/share.rs b/src/command/share.rs index 43fea42..a89fa5f 100644 --- a/src/command/share.rs +++ b/src/command/share.rs @@ -153,10 +153,13 @@ pub fn new(pargs: &mut Arguments) { // don't allow unflagged nesting util::prevent_nest(); - // get optional flag + // get optional flags let detached = pargs.contains(flag::DETACH); let target_dir: Result<String, Error> = pargs.value_from_str(flag::TARGET); + // get environment variables + let window_name = env_var(env::NEW_WINDOW_NAME); + // get target or fallback let args = pargs.clone().finish(); let title: String; @@ -175,6 +178,7 @@ pub fn new(pargs: &mut Arguments) { if let Some(command) = command { new.shell_command = Some(command.to_string_lossy()); } if detached { new.detached = true; } if let Ok(target_dir) = target_dir { new = new.start_directory(target_dir); } + if !window_name.is_empty() { new.window_name = Some(window_name.into()); } Tmux::new() .add_command(new) diff --git a/src/env.rs b/src/env.rs index d0f79a4..a5b4450 100644 --- a/src/env.rs +++ b/src/env.rs @@ -2,7 +2,8 @@ use std::env::var; pub type EnvVar = (&'static str, &'static str); -pub static ATTACH_SYMBOL: EnvVar = ("REMUX_ATTACH_SYMBOL", "*"); +pub static ATTACH_SYMBOL: EnvVar = ("REMUX_ATTACH_SYMBOL", "*"); +pub static NEW_WINDOW_NAME: EnvVar = ("REMUX_NEW_WINDOW", ""); pub fn env_var(envvar: EnvVar) -> String { var(envvar.0).unwrap_or(envvar.1.to_string()) From d776129b3ee9fb0b72b69a6c39c7528a7bf01699 Mon Sep 17 00:00:00 2001 From: Valerie <sleeplessval@gmail.com> Date: Mon, 10 Jun 2024 12:02:57 -0400 Subject: [PATCH 21/27] added help text for REMUX_NEW_WINDOW env var --- src/help.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/help.rs b/src/help.rs index fb9e701..6ff28e0 100644 --- a/src/help.rs +++ b/src/help.rs @@ -130,7 +130,12 @@ println!("remux environment variables REMUX_ATTACH_SYMBOL Changes the symbol displayed for attached sessions displayed by the 'list' command. - Default: '*'"), + Default: '*' + +REMUX_NEW_WINDOW + Provides a default window name when creating a session with + the 'new' command, if not empty. + Default: ''"), // not found _ => error::no_help(topic.unwrap()) From 21eda336241985f10f18d664ed70f9340d551100 Mon Sep 17 00:00:00 2001 From: Valerie <sleeplessval@gmail.com> Date: Mon, 10 Jun 2024 12:02:57 -0400 Subject: [PATCH 22/27] default window name now sets correctly --- src/command/share.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/command/share.rs b/src/command/share.rs index a89fa5f..9d1d927 100644 --- a/src/command/share.rs +++ b/src/command/share.rs @@ -178,10 +178,16 @@ pub fn new(pargs: &mut Arguments) { if let Some(command) = command { new.shell_command = Some(command.to_string_lossy()); } if detached { new.detached = true; } if let Ok(target_dir) = target_dir { new = new.start_directory(target_dir); } - if !window_name.is_empty() { new.window_name = Some(window_name.into()); } - Tmux::new() - .add_command(new) - .output().ok(); + let mut tmux = Tmux::new().add_command(new); + + // rename window if var not empty + if !window_name.is_empty() { + let auto_name = commands::RenameWindow::new() + .new_name(window_name); + tmux = tmux.add_command(auto_name); + } + + tmux.output().ok(); } From 28a7fc44f9911196823ffff840b9e4ed118aea17 Mon Sep 17 00:00:00 2001 From: Valerie <sleeplessval@gmail.com> Date: Mon, 10 Jun 2024 12:02:57 -0400 Subject: [PATCH 23/27] switched session enforce to new tmux detection helper --- src/util.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/util.rs b/src/util.rs index fd6e953..c3ca71f 100644 --- a/src/util.rs +++ b/src/util.rs @@ -35,10 +35,7 @@ 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); - } + if !env::tmux() { error::not_in_session(cmd); } } /// check whether a target session exists From 19b12c682d2a533c2e4577a7e16efc721fb19dbb Mon Sep 17 00:00:00 2001 From: Valerie <sleeplessval@gmail.com> Date: Mon, 10 Jun 2024 12:02:57 -0400 Subject: [PATCH 24/27] updated README --- README.md | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ee793c7..cd4690d 100644 --- a/README.md +++ b/README.md @@ -17,10 +17,10 @@ shorter than its equivalent tmux command: ```sh # new session -tmux new-session -t foo +tmux new-s -t foo remux n foo -# lists +# list sessions tmux ls remux l remux @@ -30,11 +30,11 @@ tmux a -t foo remux a foo # has -tmux has -t foo +tmux h -t foo remux has foo # detach -tmux detach-client -t foo +tmux det -t foo remux d foo # nesting sessions with '-n' flag @@ -43,6 +43,15 @@ remux a -n foo TMUX='' tmux new-session -t foo remux n -n foo +# switch to another session +tmux swi -t foo +rmux s foo + +# cd to session path +tmux run 'printf "#{session_path}" > /tmp/tmux_root' +cd `cat /tmp/tmux_root` +cd `rmux root` + ``` ## Dependencies From 26f6fd5dd09846a0da1dfde7524c6960ce5756e4 Mon Sep 17 00:00:00 2001 From: Valerie <sleeplessval@gmail.com> Date: Mon, 10 Jun 2024 12:02:57 -0400 Subject: [PATCH 25/27] made nest prevent message more helpful --- src/util.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util.rs b/src/util.rs index c3ca71f..986af11 100644 --- a/src/util.rs +++ b/src/util.rs @@ -28,7 +28,7 @@ pub fn get_sessions() -> Option<Vec<Session>> { /// show the tmux nest text if env var is not unset pub fn prevent_nest() { if env::tmux() { - println!("Sessions should be nested with care; unset TMUX or use the '-n' flag to allow."); + println!("To nest sessions, use the -n flag."); exit(6); } } From 1320b6f122dea8d3b1010318e5fe0e34933e13ad Mon Sep 17 00:00:00 2001 From: Valerie <sleeplessval@gmail.com> Date: Mon, 10 Jun 2024 12:02:57 -0400 Subject: [PATCH 26/27] 'h' is now shortened version of 'has' instead of help --- README.md | 2 +- src/help.rs | 3 ++- src/main.rs | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index cd4690d..2d8cd2a 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ remux a foo # has tmux h -t foo -remux has foo +remux h foo # detach tmux det -t foo diff --git a/src/help.rs b/src/help.rs index 6ff28e0..1cb3103 100644 --- a/src/help.rs +++ b/src/help.rs @@ -59,12 +59,13 @@ usage: remux detach <session> args: <session> The session name to detach clients from"), - Some("has") + Some("h" | "has") => println!("remux has Check if the target session exists. usage: remux has [flags] <session> + rmux h [flags] session args: <session> The session to check for diff --git a/src/main.rs b/src/main.rs index a1c9cf1..bb72006 100644 --- a/src/main.rs +++ b/src/main.rs @@ -41,7 +41,7 @@ fn main() { // invoke subcommand function match subcommand.as_deref() { - Some("h" | "help") + Some("help") => help(&mut args), Some("a" | "attach") @@ -50,7 +50,7 @@ fn main() { Some("d" | "detach") => command::share::detach(&mut args), - Some("has") + Some("h" | "has") => command::share::has(&mut args), None | From 0fc6cd66c68ebbd687989f9d9aa7ad2bf4cd31c0 Mon Sep 17 00:00:00 2001 From: Valerie <sleeplessval@gmail.com> Date: Mon, 10 Jun 2024 12:03:40 -0400 Subject: [PATCH 27/27] renamed 'root' command to 'path' --- README.md | 6 +++--- src/command/session.rs | 6 +++--- src/help.rs | 8 ++++++-- src/main.rs | 4 ++-- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 2d8cd2a..a96eb7a 100644 --- a/README.md +++ b/README.md @@ -48,9 +48,9 @@ tmux swi -t foo rmux s foo # cd to session path -tmux run 'printf "#{session_path}" > /tmp/tmux_root' -cd `cat /tmp/tmux_root` -cd `rmux root` +tmux run 'printf "#{session_path}" > /tmp/tmux_path' +cd `cat /tmp/tmux_path` +cd `rmux p` ``` diff --git a/src/command/session.rs b/src/command/session.rs index 3bd3584..ca33fa5 100644 --- a/src/command/session.rs +++ b/src/command/session.rs @@ -9,7 +9,7 @@ use tmux_interface::{ use crate::{ error, flag, util }; -const TMP_ROOT: &str = "/tmp/remux_root"; +const TMP_ROOT: &str = "/tmp/remux_path"; pub fn switch(pargs: &mut Arguments) { util::terminal_enforce(); @@ -36,8 +36,8 @@ pub fn switch(pargs: &mut Arguments) { .output().ok(); } -pub fn root() { - util::session_enforce("root"); +pub fn path() { + util::session_enforce("path"); let exec = commands::Run::new().shell_command("printf '#{session_path}' > ".to_string() + TMP_ROOT); Tmux::new() diff --git a/src/help.rs b/src/help.rs index 1cb3103..56d68b9 100644 --- a/src/help.rs +++ b/src/help.rs @@ -23,6 +23,9 @@ commands: list Pretty-print all tmux sessions new Create a new tmux session + path print session path (session) + switch switch to another session (session) + Use 'remux help <command>' to see detailed help text for each command. help topics: @@ -100,11 +103,12 @@ flags: Some("root") => -println!("remux root +println!("remux path Print the session path (#{{session_path}}) to standard output. Must be run from inside a session. -usage: remux root"), +usage: remux path + remux p"), Some("s" | "switch") => diff --git a/src/main.rs b/src/main.rs index bb72006..e94a42e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -60,8 +60,8 @@ fn main() { Some("n" | "new") => command::share::new(&mut args), - Some("root") - => command::session::root(), + Some("p" | "path") + => command::session::path(), Some("s" | "switch") => command::session::switch(&mut args),