SSH Autocomplete

So many of a time you see an article about ssh autocomplete that reads your known_hosts file. Well that great and all but what about just reading your ssh config file for all your pre-configured hosts. Well here is the code to do it. Just add it to your ~/.bash_profile or ~/.bashrc file.


if [ -r ~/.ssh/config ]; then
complete -W "$(echo `if [ -r ~/.ssh/config ]; then cat ~/.ssh/config; fi | grep Host | cut -f 2 -d ' ' | uniq`;)" ssh
fi

This entry was posted in Computer Systems and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>