diff --git a/src/ssh.rs b/src/ssh.rs index 130424d..8cfbb73 100644 --- a/src/ssh.rs +++ b/src/ssh.rs @@ -61,9 +61,9 @@ pub fn parse_config(raw_path: &String) -> Result> { let hosts = ssh_config::Parser::new() .parse_file(path)? .apply_patterns() + .apply_name_to_empty_hostname() .merge_same_hosts() .iter() - .filter(|host| host.get(&ssh_config::EntryType::Hostname).is_some()) .map(|host| Host { name: host .get_patterns() diff --git a/src/ssh_config/host.rs b/src/ssh_config/host.rs index 38c807f..20e1f0a 100644 --- a/src/ssh_config/host.rs +++ b/src/ssh_config/host.rs @@ -92,6 +92,9 @@ impl Host { #[allow(clippy::module_name_repetitions)] pub trait HostVecExt { + /// Apply the name entry to the hostname entry if the hostname entry is empty. + fn apply_name_to_empty_hostname(&mut self) -> &mut Self; + /// Merges the hosts with the same entries into one host. fn merge_same_hosts(&mut self) -> &mut Self; @@ -103,6 +106,17 @@ pub trait HostVecExt { } impl HostVecExt for Vec { + fn apply_name_to_empty_hostname(&mut self) -> &mut Self { + for host in self.iter_mut() { + if host.get(&EntryType::Hostname).is_none() { + let name = host.patterns.first().unwrap().clone(); + host.update((EntryType::Hostname, name.clone())); + } + } + + self + } + fn merge_same_hosts(&mut self) -> &mut Self { for i in (0..self.len()).rev() { for j in (0..i).rev() {