use anyhow::Context; use clap::Parser; use sshr::{Config, HostName, Hosts, KnownHosts, Sessions, Stdout}; fn main() -> anyhow::Result<()> { let config = Config::parse(); tracing_subscriber::fmt::fmt() .with_max_level(&config.verbosity) .without_time() .init(); let mut sessions = Sessions::new(config.sessions); if config.enabled.localhost() { let hostname = HostName::get().context("Failed to get hostname of localhost")?; sessions.extend(hostname); } if config.enabled.tmux() { let tmux_sessions = config.tmux.list().context("Failed to list tmux sessions")?; sessions.extend(tmux_sessions); } if config.enabled.ssh() { let known_hosts = KnownHosts::open().context("Failed to read KnownHost file")?; sessions.extend(known_hosts); } if config.enabled.hosts() { let hosts = Hosts::open().context("Failed to read /etc/hosts")?; sessions.extend(hosts); } if config.enabled.history() { match config.history.read() { Ok(h) => sessions.extend(h), Err(err) if err.kind() == std::io::ErrorKind::NotFound => { tracing::warn!("Skipping non-existant history file") } Err(err) => return Err(err).context("Failed to read history file"), } } if config.history.update { sessions.write_sessions(config.history)?; } sessions .write_sessions(Stdout::new(config.stdio)) .context("Failed to write to stdout") }