BASH SSH host completion
I tried the bash completion stuff, and found a single thing I liked, ssh completion. Most of the other stuff just annoyed me… a lot (and was mostly useless, at least for me). I first looked at the code in the bash completion for ssh completion, but it was imho too large to stuff into my .bashrc, so I wrote a small perl one-liner that did the trick.
complete -C "/usr/bin/perl -e 'my \$match = \$ARGV[1] ? \$ARGV[1] : \”.*\”; open(my \$INPUT,\”< \”,\”$HOME/.ssh/config\”); foreach(> \$INPUT<) {next unless s/^\s*Host\s+//;chomp;foreach(split(/\s+/)) { print \”\$_\\n\” if(/^\$match/ and not /^\d/ and not /\*/);}}’” ssh
Stuff that into ~/.bashrc and off you go. It completes based upon hosts in ~/.ssh/config
May 14th, 2007 at 15:57
This doesn’t work for me. it doesn’t do anything when I press tab. However before I use this command it does work. NB. the quotes are wrong for c/p because they’re fancy unicode.
May 15th, 2007 at 14:58
ssh space then tab should work. If it works before using this then you don’t need this :), this is mostly if it doesn’t work.
Perhaps some of the quotes got messed up.
Also, this completion only completes host from ~/.ssh/config - not /etc/hosts
May 13th, 2008 at 06:44
Obviously you need non-hashed hostnames in /etc/ssh/ssh_config and change HashKnownHosts to No