Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am using zsh with oh-my-zsh. Unfortunately, oh-my-zsh does not use file ~/.ssh/config for hostname auto-completion (see Issue #1009, for instance).

This could easily archived by the following code:

[ -r ~/.ssh/config ] && _ssh_config=($(cat ~/.ssh/config | sed -ne 's/Host[=\t ]//p')) || _ssh_config=()
zstyle ':completion:*:hosts' hosts $_ssh_config

However, if I add the above commands to my ~/.zshrc file, all other sources for hostnames (like ~/.ssh/known_hosts), which are defined in file ~/.oh-my-zsh/lib/completion.zsh, are overridden.

How can I append new completion rules for ':completion:*:hosts' in my ~/.zshrc file?

share|improve this question
add comment

3 Answers

up vote 0 down vote accepted

I think you need to retrieve the existing items and append yours.

zstyle -s ':completion:*:hosts' hosts _ssh_config
[[ -r ~/.ssh/config ]] && _ssh_config+=($(cat ~/.ssh/config | sed -ne 's/Host[=\t ]//p'))
zstyle ':completion:*:hosts' hosts $_ssh_config
share|improve this answer
    
Thanks, zstyle -s was the missing piece. –  Martin Oct 18 '12 at 5:08
add comment

The best option appears be to just use zsh's defaults.

See my pull request for oh-my-zsh at https://github.com/robbyrussell/oh-my-zsh/pull/1498

share|improve this answer
add comment

You may want to replace oh-my-zsh with the much-better written and maintained https://github.com/sorin-ionescu/prezto which uses default zsh completions and this external module https://github.com/zsh-users/zsh-completions

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.