Categories
SysAdmin

Simple Bash Completions

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.