blob: 30fd65d6b7bb44bce256b2f9c485405d68d95e4d [file] [log] [blame]
Andy Shene0d85822010-12-04 11:03:33 +11001#!/bin/bash
2# Bash completion support for ssh.
3
4export COMP_WORDBREAKS=${COMP_WORDBREAKS/\:/}
5
6_sshcomplete() {
Florian Baumann13edf322010-12-06 16:01:06 +01007
8 # parse all defined hosts from .ssh/config
9 if [ -r $HOME/.ssh/config ]; then
10 COMPREPLY=($(compgen -W "$(grep ^Host $HOME/.ssh/config | awk '{print $2}' )" -- ${COMP_WORDS[COMP_CWORD]}))
Andy Shene0d85822010-12-04 11:03:33 +110011 fi
Florian Baumann13edf322010-12-06 16:01:06 +010012
13 # parse all hosts found in .ssh/known_hosts
14 if [ -r $HOME/.ssh/known_hosts ]; then
15 if grep -v -q -e '^ ssh-rsa' $HOME/.ssh/known_hosts ; then
16 COMPREPLY=( $COMPREPLY $(compgen -W "$( awk '{print $1}' $HOME/.ssh/known_hosts | cut -d, -f 1 | sed -e 's/\[//g' | sed -e 's/\]//g' | cut -d: -f1 | grep -v ssh-rsa)" -- ${COMP_WORDS[COMP_CWORD]} ))
17 fi
18 fi
19
20 return 0
Andy Shene0d85822010-12-04 11:03:33 +110021}
22
23complete -o default -o nospace -F _sshcomplete ssh