Compare commits
No commits in common. "40cacce0be3cd3b594b283607743254f83d7e298" and "a15bee37c63987e9920ae471a3a44575d1d8767e" have entirely different histories.
40cacce0be
...
a15bee37c6
5 changed files with 5 additions and 45 deletions
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "remux"
|
||||
version = "0.1.0"
|
||||
version = "0.0.4"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
@ -11,10 +11,3 @@ ratatui = { version = "0.20.1", features = [ "termion" ] }
|
|||
termion = "2.0.1"
|
||||
tmux_interface = "0.2.1"
|
||||
|
||||
[profile.release]
|
||||
opt-level = "s"
|
||||
lto = true
|
||||
debug = false
|
||||
codegen-units = 1
|
||||
panic = "abort"
|
||||
|
||||
|
|
|
@ -105,17 +105,14 @@ pub fn help(pargs: &mut Arguments) {
|
|||
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"]);
|
||||
|
||||
// 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();
|
||||
let window = args.get(1);
|
||||
|
||||
// focus window if provided
|
||||
if window.is_some() {
|
||||
let target = window.unwrap().to_string_lossy();
|
||||
let tmux = TmuxCommand::new();
|
||||
|
@ -125,7 +122,6 @@ pub fn attach(pargs: &mut Arguments) {
|
|||
.output().ok();
|
||||
}
|
||||
|
||||
// command
|
||||
let tmux = TmuxCommand::new();
|
||||
let exists = tmux
|
||||
.has_session()
|
||||
|
@ -135,7 +131,6 @@ pub fn attach(pargs: &mut Arguments) {
|
|||
|
||||
let mut attach = tmux.attach_session();
|
||||
|
||||
// handle optional flags
|
||||
if read_only { attach.read_only(); }
|
||||
if detach_other { attach.detach_other(); }
|
||||
|
||||
|
@ -145,12 +140,10 @@ pub fn attach(pargs: &mut Arguments) {
|
|||
}
|
||||
|
||||
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();
|
||||
|
||||
// command
|
||||
let tmux = TmuxCommand::new();
|
||||
let exists = tmux
|
||||
.has_session()
|
||||
|
@ -165,15 +158,11 @@ pub fn detach(pargs: &mut Arguments) {
|
|||
}
|
||||
|
||||
pub fn has(pargs: &mut Arguments) {
|
||||
// get optional flag
|
||||
let quiet = pargs.contains(["-q", "--quiet"]);
|
||||
|
||||
// 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();
|
||||
|
||||
// command
|
||||
let tmux = TmuxCommand::new();
|
||||
let exists = tmux
|
||||
.has_session()
|
||||
|
@ -182,25 +171,19 @@ pub fn has(pargs: &mut Arguments) {
|
|||
|
||||
let success = exists.success();
|
||||
|
||||
// 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());
|
||||
|
@ -223,17 +206,11 @@ pub fn list() {
|
|||
pub fn new(pargs: &mut Arguments) {
|
||||
use pico_args::Error;
|
||||
|
||||
// show nest message
|
||||
util::prevent_nest();
|
||||
|
||||
// get optional flag
|
||||
let target_dir: Result<String, Error> = pargs.value_from_str(["-t", "--target"]);
|
||||
|
||||
// get target and error out if not provided
|
||||
let args = pargs.clone().finish();
|
||||
if args.len() < 1 { error::missing_target(); }
|
||||
|
||||
// get target session and optional command
|
||||
let title = args.get(0).unwrap().to_string_lossy();
|
||||
let command = args.get(1);
|
||||
|
||||
|
|
10
src/error.rs
10
src/error.rs
|
@ -1,32 +1,22 @@
|
|||
use std::process::exit;
|
||||
|
||||
/// no subcommand that matches user input; code 1
|
||||
pub fn no_subcommand(subcommand: String) {
|
||||
println!("remux: no command match for \"{subcommand}\"");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/// target session not found; code 2
|
||||
pub fn no_target(target: String) {
|
||||
println!("remux: no session \"{target}\" exists");
|
||||
exit(2);
|
||||
}
|
||||
/// no sessions exist; code 2
|
||||
pub fn no_sessions() {
|
||||
println!("remux: no sessions running");
|
||||
println!("use 'remux n <title>' to create a new session");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
/// help topic doesn't exist; code 3
|
||||
pub fn no_help(topic: String) {
|
||||
println!("remux: no help for \"{topic}\"");
|
||||
exit(3);
|
||||
}
|
||||
|
||||
/// user provided no target; code 4
|
||||
pub fn missing_target() {
|
||||
println!("remux: no target provided");
|
||||
exit(4);
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@ fn main() {
|
|||
|
||||
let subcommand = args.subcommand().unwrap();
|
||||
|
||||
//let tmuxvar = var("TMUX");
|
||||
|
||||
match subcommand.as_deref() {
|
||||
Some("h" | "help")
|
||||
=> command::help(&mut args),
|
||||
|
|
|
@ -8,7 +8,6 @@ use tmux_interface::{
|
|||
variables::session::session::SESSION_ALL
|
||||
};
|
||||
|
||||
/// return a Vec of all sessions or None
|
||||
pub fn get_sessions() -> Option<Vec<Session>> {
|
||||
let i_sessions = Sessions::get(SESSION_ALL);
|
||||
if i_sessions.is_err() { return None; }
|
||||
|
@ -18,7 +17,6 @@ pub fn get_sessions() -> Option<Vec<Session>> {
|
|||
Some(sessions.unwrap().0)
|
||||
}
|
||||
|
||||
/// 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() != "" {
|
||||
|
|
Loading…
Reference in a new issue