use std::collections::HashMap; use clap::Parser; use sshr::{Config, History, Session, SessionSource, Timestamp, Tmux}; fn main() -> anyhow::Result<()> { let config = Config::parse(); tracing_subscriber::fmt::fmt() .with_max_level(&config.verbosity) .without_time() .init(); if config.list { list_sessions(config) } else { switch(config.target) } } fn list_sessions(config: Config) -> anyhow::Result<()> { let mut sessions: HashMap = HashMap::new(); let tmux = Tmux::new(config.socket_name); sessions = tmux.update(sessions)?; if let Some(history_file) = config.history_file.or_else(History::default_path) { if history_file.exists() { sessions = History::new(history_file).update(sessions)?; } } let mut sessions: Vec = sessions .into_iter() .map(|(name, timestamp)| Session { name, timestamp }) .collect(); sessions.sort(); for session in sessions { println!("{session}"); } Ok(()) } fn switch(_target: Option) -> anyhow::Result<()> { todo!() }