diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 13 | ||||
-rw-r--r-- | src/main.rs | 60 |
2 files changed, 71 insertions, 2 deletions
diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..d465d78 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,13 @@ +pub use config::Config; + +mod config { + use clap::Parser; + + #[derive(Debug, Clone, Parser)] + pub struct Config { + pub target: Option<String>, + + #[arg(short, long)] + pub list: bool, + } +} diff --git a/src/main.rs b/src/main.rs index 5dd30d1..ebd0526 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,59 @@ -fn main() { - println!("Hello World!") +use std::{process::Command, time::Duration}; + +use clap::Parser; +use serde::Deserialize; +use sshr::Config; + +fn main() -> anyhow::Result<()> { + let config = Config::parse(); + + if config.list { + list() + } else { + switch(config.target) + } +} + +#[derive(Debug, Deserialize)] +struct Session { + pub name: String, + pub created: u64, + pub attached: u64, +} + +fn list() -> anyhow::Result<()> { + let sessions = tmux_sessions()?; + + for session in sessions { + println!("{session:?}"); + } + + Ok(()) +} + +fn tmux_sessions() -> anyhow::Result<Vec<Session>> { + let format = indoc::indoc! {r##"[ + #{S: Session( + name: "#S", + created: #{session_created}, + attached: #{session_last_attached} + ),} + ]"##}; + + let output = Command::new("tmux") + .arg("-L") + .arg("ssh") + .arg("display") + .arg("-p") + .arg(format) + .output()?; + + match std::str::from_utf8(&output.stdout)? { + "" => Ok(Vec::new()), + s => ron::from_str(s).map_err(Into::into), + } +} + +fn switch(_target: Option<String>) -> anyhow::Result<()> { + todo!() } |