Permalink
Browse files

ssh completion using .ssh/config

  • Loading branch information...
1 parent c00bde6 commit e0d8582c0b3ba1f551ff7c60d4363a2fe2f6b428 Andy Shen committed Dec 4, 2010
Showing with 13 additions and 0 deletions.
  1. +13 −0 completion/ssh.completion.bash
View
13 completion/ssh.completion.bash
@@ -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

0 comments on commit e0d8582

Please sign in to comment.