Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: zsh does not offer ssh host from config



On Sat, Dec 10, 2022 at 12:32 PM Roman Perepelitsa
<roman.perepelitsa@xxxxxxxxx> wrote:
>
> [...] switched to my current setup where the ssh
> config contains all remote machines (I generate it with a script). I
> really like the ability to list all machines with a TAB.

I've started using this:

zstyle -e ':completion:*:(ssh|scp):*' hosts 'reply=(
    ${(Mu)${(M)=history:#ssh*}:#[^/]##.*} \
    ${=${${(f)"$(cat {/etc/ssh_,~/.ssh/known_}hosts(|2)(N) \
                     /dev/null)"}%%[#| ]*}//,/ }
    ${=${(f)"$(cat /etc/hosts(|)(N) <<(ypcat hosts 2>/dev/null))"}%%\#*}
    )'

That retrieves
 - all hosts mentioned in ssh commands in the current shell history
 - all hosts in known_hosts and known_hosts2 (ignoring hashed hostnames)
 - anything available from the local and network host configurations

My current complaint is that the hosts style is used in preference to
the my-accounts style, so I can't complete user names that are
prefixes of host names.




Messages sorted by: Reverse Date, Date, Thread, Author