2024-06-10 12:01:15 -04:00
|
|
|
use std::env::{ set_var, var };
|
2023-04-06 13:34:32 -04:00
|
|
|
|
|
|
|
use pico_args::Arguments;
|
|
|
|
|
|
|
|
mod command;
|
2024-06-10 12:02:02 -04:00
|
|
|
mod env;
|
2023-04-14 16:38:34 -04:00
|
|
|
mod error;
|
2024-03-06 15:54:41 -05:00
|
|
|
mod flag;
|
2024-01-23 16:45:58 -05:00
|
|
|
mod help;
|
2023-04-06 13:34:32 -04:00
|
|
|
mod util;
|
|
|
|
|
2024-02-04 16:11:32 -05:00
|
|
|
use help::{ help, version };
|
|
|
|
|
|
|
|
static VERSION: &str = env!("CARGO_PKG_VERSION");
|
2024-01-23 16:45:58 -05:00
|
|
|
|
2023-04-06 13:34:32 -04:00
|
|
|
fn main() {
|
2024-02-04 16:07:24 -05:00
|
|
|
// collect args
|
2023-04-06 13:34:32 -04:00
|
|
|
let mut args = Arguments::from_env();
|
|
|
|
|
2024-02-04 16:07:24 -05:00
|
|
|
// consume flags
|
2024-03-06 15:54:41 -05:00
|
|
|
if args.contains(flag::HELP) {
|
2024-01-23 16:45:58 -05:00
|
|
|
help(&mut args);
|
2023-06-19 12:55:45 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-03-06 15:54:41 -05:00
|
|
|
if args.contains(flag::VERSION) {
|
2024-02-04 16:11:32 -05:00
|
|
|
version();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-03-06 15:54:41 -05:00
|
|
|
let nesting = args.contains(flag::NEST);
|
2024-02-04 16:07:24 -05:00
|
|
|
let tmux_var = var("TMUX").ok();
|
|
|
|
if nesting {
|
|
|
|
if tmux_var.is_none() {
|
|
|
|
error::not_nesting();
|
|
|
|
}
|
|
|
|
set_var("TMUX", "");
|
|
|
|
}
|
2023-06-19 12:55:45 -04:00
|
|
|
|
2023-04-06 13:34:32 -04:00
|
|
|
let subcommand = args.subcommand().unwrap();
|
|
|
|
|
2024-02-04 16:07:24 -05:00
|
|
|
// invoke subcommand function
|
2023-04-06 13:34:32 -04:00
|
|
|
match subcommand.as_deref() {
|
2024-06-10 12:02:57 -04:00
|
|
|
Some("help")
|
2024-01-23 16:45:58 -05:00
|
|
|
=> help(&mut args),
|
2023-04-06 13:34:32 -04:00
|
|
|
|
2023-04-20 15:31:22 -04:00
|
|
|
Some("a" | "attach")
|
2024-03-06 15:54:41 -05:00
|
|
|
=> command::share::attach(&mut args),
|
2023-04-06 13:34:32 -04:00
|
|
|
|
2023-05-01 10:50:47 -04:00
|
|
|
Some("d" | "detach")
|
2024-03-06 15:54:41 -05:00
|
|
|
=> command::share::detach(&mut args),
|
2023-05-01 10:50:47 -04:00
|
|
|
|
2024-06-10 12:02:57 -04:00
|
|
|
Some("h" | "has")
|
2024-03-06 15:54:41 -05:00
|
|
|
=> command::share::has(&mut args),
|
2023-04-14 16:38:34 -04:00
|
|
|
|
2023-04-20 15:31:22 -04:00
|
|
|
None |
|
|
|
|
Some("l" | "ls" | "list")
|
2024-03-06 15:54:41 -05:00
|
|
|
=> command::share::list(),
|
2023-04-06 13:34:32 -04:00
|
|
|
|
2023-04-20 15:31:22 -04:00
|
|
|
Some("n" | "new")
|
2024-03-06 15:54:41 -05:00
|
|
|
=> command::share::new(&mut args),
|
2023-04-06 13:34:32 -04:00
|
|
|
|
2024-06-10 12:01:15 -04:00
|
|
|
Some("root")
|
|
|
|
=> command::session::root(),
|
|
|
|
|
2024-03-07 17:10:45 -05:00
|
|
|
Some("s" | "switch")
|
|
|
|
=> command::session::switch(&mut args),
|
|
|
|
|
2023-04-20 15:31:22 -04:00
|
|
|
_
|
|
|
|
=> error::no_subcommand(subcommand.unwrap())
|
2023-04-06 13:34:32 -04:00
|
|
|
}
|
2024-02-04 16:07:24 -05:00
|
|
|
|
2024-02-04 16:14:34 -05:00
|
|
|
// re-set TMUX var if we unset it for nest mode
|
2024-02-04 16:07:24 -05:00
|
|
|
if nesting {
|
|
|
|
set_var("TMUX", tmux_var.unwrap());
|
|
|
|
}
|
2023-04-06 13:34:32 -04:00
|
|
|
}
|
|
|
|
|