Andy Shen | e0d8582 | 2010-12-04 11:03:33 +1100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # Bash completion support for ssh. |
| 3 | |
| 4 | export COMP_WORDBREAKS=${COMP_WORDBREAKS/\:/} |
| 5 | |
| 6 | _sshcomplete() { |
| 7 | if [ -f $HOME/.ssh/config ]; then |
| 8 | COMPREPLY=($(compgen -W "`ruby -e"puts open('${HOME}/.ssh/config', 'r') { |f| f.readlines }.find_all { |l| l =~ /^Host/ }.inject([]) { |hosts, line| hosts << line[5..-1].split }.flatten.sort.uniq"`" -- ${COMP_WORDS[COMP_CWORD]})) |
| 9 | return 0 |
| 10 | fi |
| 11 | } |
| 12 | |
| 13 | complete -o default -o nospace -F _sshcomplete ssh |