summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs60
1 files changed, 58 insertions, 2 deletions
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!()
}