Skip to content

Instantly share code, notes, and snippets.

@vortexau
Last active July 6, 2017 04:02
Show Gist options
  • Save vortexau/7d9f7a32ee3643269db7dab9629bd87f to your computer and use it in GitHub Desktop.
Save vortexau/7d9f7a32ee3643269db7dab9629bd87f to your computer and use it in GitHub Desktop.
# Custom hosts completion from included SSH configs:
zstyle -e ':completion:*:hosts' hosts 'reply=(
${=${=${=${${(f)"$(cat {/etc/ssh_,~/.ssh/known_}hosts(|2)(N) 2>/dev/null)"}%%[#| ]*}//\]:[0-9]*/ }//,/ }//\[/ }
${=${(f)"$(cat /etc/hosts(|)(N) <<(ypcat hosts 2>/dev/null))"}%%\#*}
${=${${${${(@M)${(f)"$(cat ~/.ssh/config 2>/dev/null)"}:#Host *}#Host }:#*\**}:#*\?*}}
${=${${${${(@M)${(f)"$(cat ~/.ssh/config.d/* 2>/dev/null)"}:#Host *}#Host }:#*\**}:#*\?*}}
)'
# The last line above supports reading from files inside a local SSH configuration directory. It pulls
# all configured hosts and allows them to be used for tab completion.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment