diff --git a/zsh.changes b/zsh.changes index 100c45d..f772e2c 100644 --- a/zsh.changes +++ b/zsh.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Mon Mar 3 15:52:59 UTC 2025 - Paolo Perego + +- Applied solution for boo#1227119. In case you configured hostnames in + ~/.ssh/config file, now TAB completion is working as expected. + ------------------------------------------------------------------- Mon Mar 3 13:41:20 UTC 2025 - Paolo Perego diff --git a/zshrc b/zshrc index 6c46660..0034c91 100644 --- a/zshrc +++ b/zshrc @@ -311,5 +311,20 @@ if test -t && type -p tty > /dev/null 2>&1 ; then export GPG_TTY fi +# Correct hostname tab completion when relevant names are configured in $HOME/.ssh/config file. +# https://bugzilla.suse.com/show_bug.cgi?id=1227119 +# Taken from: https://serverfault.com/questions/170346/how-to-edit-command-completion-for-ssh-on-zsh/170481#170481 +h=() +if [[ -r ~/.ssh/config ]]; then + h=($h ${${${(@M)${(f)"$(cat ~/.ssh/config)"}:#Host *}#Host }:#*[*?]*}) +fi +if [[ -r ~/.ssh/known_hosts ]]; then + h=($h ${${${(f)"$(cat ~/.ssh/known_hosts{,2} || true)"}%%\ *}%%,*}) 2>/dev/null +fi +if [[ $#h -gt 0 ]]; then + zstyle ':completion:*:ssh:*' hosts $h + zstyle ':completion:*:slogin:*' hosts $h +fi + # Read custom system-wide config if exists test -s /etc/zsh.zshrc.local && . /etc/zsh.zshrc.local