Skip to content

Instantly share code, notes, and snippets.

@jsonUK
Created June 14, 2018 15:06
Show Gist options
  • Save jsonUK/0ea33f8f42fa2578823e96a071d72ec7 to your computer and use it in GitHub Desktop.
Save jsonUK/0ea33f8f42fa2578823e96a071d72ec7 to your computer and use it in GitHub Desktop.
Tab auto-complete your ssh configs in your terminal on scp ssh etc.
# Tab autocomplete ssh hosts
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment