From 7df13688df4d00bf0658b69114c1c7d187f3f624 Mon Sep 17 00:00:00 2001 From: Paul Frederiksen Date: Thu, 11 Sep 2025 15:38:19 -0400 Subject: [PATCH] fix: merge SSH hosts from .ssh/config with known_hosts Fixes #2737 - Modified common-aliases plugin to merge hosts from .ssh/config with known_hosts instead of overriding them - This ensures .ssh/config hosts take priority over /etc/hosts entries - Maintains backward compatibility by including both sources - Uses sort -u to remove duplicates while preserving order The issue was that the common-aliases plugin was overriding the SSH plugin's host completion configuration, causing /etc/hosts entries to take priority over .ssh/config entries when completing SSH hostnames. Now both sources are merged, giving users access to all configured hosts while maintaining the expected priority order. --- plugins/common-aliases/common-aliases.plugin.zsh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/common-aliases/common-aliases.plugin.zsh b/plugins/common-aliases/common-aliases.plugin.zsh index 3139b821a..af79f1779 100644 --- a/plugins/common-aliases/common-aliases.plugin.zsh +++ b/plugins/common-aliases/common-aliases.plugin.zsh @@ -87,4 +87,5 @@ if is-at-least 4.2.0; then fi # Make zsh know about hosts already accessed by SSH -zstyle -e ':completion:*:(ssh|scp|sftp|rsh|rsync):hosts' hosts 'reply=(${=${${(f)"$(cat {/etc/ssh_,~/.ssh/known_}hosts(|2)(N) /dev/null)"}%%[# ]*}//,/ })' +# Merge with existing hosts from .ssh/config instead of overriding +zstyle -e ':completion:*:(ssh|scp|sftp|rsh|rsync):hosts' hosts 'reply=(${=${${(f)"$(cat {/etc/ssh_,~/.ssh/known_}hosts(|2)(N) /dev/null)"}%%[# ]*}//,/ } ${(f)"$(cat ~/.ssh/config 2>/dev/null | grep -E "^Host " | awk '"'"'{for (i=2; i<=NF; i++) print $i}'"'"' | grep -v '"'"'^*'"'"' | sed '"'"'s/\.*\*$//'"'"')"} | sort -u)'