Multi (file)source SSH host tab-completion

complete -W "$( { awk '/^Host / { print $2 }' ~/.ssh/config | egrep -v '\*|,' echo $( grep '^ssh ' .bash_history | sort -u | sed 's/^ssh //' ) while IFS=' ,' read host t; do echo $host; done < ~/.ssh/known_hosts ;} )" ssh
This is a multi-sourced hostname tab completion command you can put in your .bashrc (or your .bash_profile on a MAC). This will not only your .ssh/config, it will parse ALL of the following files for hostnames: .ssh/config .ssh/known_hosts .bash_history (I realize this could be prettied up by defining and calling the function, instead of implicitly referencing it, but this was more breif)
Sample Output
[user@host ~]$ ssh 10.160.<TAB>   

2012-02-28 18:08:53

What Others Think

seomind · 4 weeks and 4 days ago
This is really a nice and informative, containing all information and also has a great impact on the new technology. Thanks for sharing it,">Visit Website
seomind · 4 weeks and 4 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: