Compare commits
No commits in common. "a81226c79cf42630344ab6201148420118851eb3" and "99531e785be71e6088fd6076f777f989d7deb308" have entirely different histories.
a81226c79c
...
99531e785b
4 changed files with 4 additions and 30 deletions
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "remux"
|
name = "remux"
|
||||||
version = "0.1.2"
|
version = "0.1.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
|
@ -30,15 +30,8 @@ pub fn missing_target() {
|
||||||
exit(4);
|
exit(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// non-terminal environment prevention; code 5
|
|
||||||
pub fn not_terminal() {
|
pub fn not_terminal() {
|
||||||
println!("remux: not running from a terminal");
|
println!("remux: not running from a terminal");
|
||||||
exit(5);
|
exit(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// tried to nest while not in a session; code 6
|
|
||||||
pub fn not_nesting() {
|
|
||||||
println!("remux: cannot use nesting flag outside a TMUX session");
|
|
||||||
exit(6);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
23
src/main.rs
23
src/main.rs
|
@ -1,7 +1,4 @@
|
||||||
use std::{
|
use std::io::{ stdout, IsTerminal };
|
||||||
env::{ set_var, var },
|
|
||||||
io::{ stdout, IsTerminal }
|
|
||||||
};
|
|
||||||
|
|
||||||
use pico_args::Arguments;
|
use pico_args::Arguments;
|
||||||
|
|
||||||
|
@ -15,10 +12,9 @@ use help::{ help, version };
|
||||||
static VERSION: &str = env!("CARGO_PKG_VERSION");
|
static VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// collect args
|
|
||||||
let mut args = Arguments::from_env();
|
let mut args = Arguments::from_env();
|
||||||
|
|
||||||
// consume flags
|
|
||||||
if args.contains(["-h", "--help"]) {
|
if args.contains(["-h", "--help"]) {
|
||||||
help(&mut args);
|
help(&mut args);
|
||||||
return;
|
return;
|
||||||
|
@ -29,20 +25,10 @@ fn main() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let nesting = args.contains(["-n", "--nest"]);
|
|
||||||
let tmux_var = var("TMUX").ok();
|
|
||||||
if nesting {
|
|
||||||
if tmux_var.is_none() {
|
|
||||||
error::not_nesting();
|
|
||||||
}
|
|
||||||
set_var("TMUX", "");
|
|
||||||
}
|
|
||||||
|
|
||||||
if !stdout().is_terminal() { error::not_terminal(); }
|
if !stdout().is_terminal() { error::not_terminal(); }
|
||||||
|
|
||||||
let subcommand = args.subcommand().unwrap();
|
let subcommand = args.subcommand().unwrap();
|
||||||
|
|
||||||
// invoke subcommand function
|
|
||||||
match subcommand.as_deref() {
|
match subcommand.as_deref() {
|
||||||
Some("h" | "help")
|
Some("h" | "help")
|
||||||
=> help(&mut args),
|
=> help(&mut args),
|
||||||
|
@ -66,10 +52,5 @@ fn main() {
|
||||||
_
|
_
|
||||||
=> error::no_subcommand(subcommand.unwrap())
|
=> error::no_subcommand(subcommand.unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
// re-set TMUX var if we unset it for nest mode
|
|
||||||
if nesting {
|
|
||||||
set_var("TMUX", tmux_var.unwrap());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ pub fn get_sessions() -> Option<Vec<Session>> {
|
||||||
pub fn prevent_nest() {
|
pub fn prevent_nest() {
|
||||||
let tmux = var("TMUX").ok();
|
let tmux = var("TMUX").ok();
|
||||||
if tmux.is_some() && tmux.unwrap() != "" {
|
if tmux.is_some() && tmux.unwrap() != "" {
|
||||||
println!("Sessions should be nested with care; unset TMUX or use the '-n' flag to allow.");
|
println!("Sessions should be nested with care; unset TMUX to allow.");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue