1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
use std::{
collections::HashSet,
io::{stdout, Write},
};
use clap::Parser;
use tokio::sync::mpsc;
#[derive(Debug, Clone, Parser)]
pub struct Config {
/// Tmux socket name
#[arg(short, long, default_value = "ssh")]
pub socket: String,
/// Exclude host from output (can be specified multiple times)
#[arg(short, long)]
pub exclude: Vec<sshr::Host>,
}
#[tokio::main]
async fn main() -> Result<(), std::io::Error> {
let config = Config::parse();
let (tx, mut rx) = mpsc::channel(100);
tokio::spawn(sshr::tmux::sessions(tx.clone(), config.socket));
tokio::spawn(sshr::netlink::neighbours(tx.clone()));
drop(tx);
let mut output: HashSet<sshr::Host> = HashSet::from_iter(config.exclude.into_iter());
let mut stdout = stdout();
while let Some(host) = rx.recv().await {
if output.insert(host.clone()) {
writeln!(stdout, "{host}")?;
}
}
Ok(())
}
|