ssh completion using .ssh/config
authorAndy Shen <andy@shenie.info>
Sat, 4 Dec 2010 00:03:33 +0000 (11:03 +1100)
committerAndy Shen <andy@shenie.info>
Sat, 4 Dec 2010 00:03:33 +0000 (11:03 +1100)
completion/ssh.completion.bash [new file with mode: 0644]

diff --git a/completion/ssh.completion.bash b/completion/ssh.completion.bash
new file mode 100644 (file)
index 0000000..7691333
--- /dev/null
@@ -0,0 +1,13 @@
+#!/bin/bash
+# Bash completion support for ssh.
+
+export COMP_WORDBREAKS=${COMP_WORDBREAKS/\:/}
+
+_sshcomplete() {
+    if [ -f $HOME/.ssh/config ]; then
+        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]}))
+        return 0
+    fi
+}
+
+complete -o default -o nospace -F _sshcomplete ssh