4

I upgraded my macbook to OSX Catalina recently. Ever since that upgrade my zsh autocomplete (tab completion) for ssh is really slow (previously, it was reasonably fast, e.g. autocomplete would happen in a few seconds). Some details that I think are relevant:

  1. I have a ~/.ssh/config file with ~2000 hosts configured
  2. When I type ssh x <TAB> things seem to hang, typing ctrl-C says Killed by signal in _ssh_hosts after 22s so it seems that my _ssh_hosts script is the problem

Any tips on how to debug this? Or alternate _ssh_hosts function I could use?

Kurt
  • 151
  • 2
  • 9
  • The autocompletion for `ssh` reparses your config file every time, rather than caching the results in memory the first time. – chepner Jan 28 '20 at 13:27
  • I wrote up an answer for a [similar question](https://stackoverflow.com/q/59713037/1126841) that refactors your `ssh` file into multiple files, one per host. That's probably less helpful for you, as 2000 individual host-specific config files may present its own problem. – chepner Jan 28 '20 at 13:30

1 Answers1

8

I've put together a solution that works for me using zstyle thanks to this email thread

My solution was to make my ~/.zshrc contain the following

function refresh_ssh_autocomplete () {
    host_list=($(cat ~/.ssh/config | grep 'Host '  | awk '{s = s $2 " "} END {print s}'))
    zstyle ':completion:*:(ssh|scp|sftp):*' hosts $host_list
}
refresh_ssh_autocomplete

Kurt
  • 151
  • 2
  • 9