Having Bash complete hostnames when SSH’ing to a host is very useful. I use the following on my computers that don’t have useful completion support:
KNOWN_HOSTS_LIST=$(echo `sed -e 's/^ *//' -e '/^#/d' -e 's/[, ].*//' -e '/[/d' ~/.ssh/known_hosts | sort -u`)
complete -W "$KNOWN_HOSTS_LIST" ping
complete -W "$KNOWN_HOSTS_LIST" ssh
complete -W "$KNOWN_HOSTS_LIST" telnet
complete -W "$KNOWN_HOSTS_LIST" traceroute
complete -c -f command sudo
complete -o dirnames cd
If running Debian or Ubuntu, install the bash-completion package to pick up more useful completions.
This entry was posted by shane on March 23, 2011 at 12:41 pm, and is filed under SysAdmin. Follow any responses to this post through RSS 2.0.
You can leave a response or trackback from your own site.
Your email address will not be published. Required fields are marked *
Save my name, email, and website in this browser for the next time I comment.
Notify me of follow-up comments by email.
Notify me of new posts by email.