fc3a3c72b17c0e12ea85094cd8b2575ccf1f2d44

Author
Robby Russell <robby@planetargon.com>
Committer
Robby Russell <robby@planetargon.com>
Date

Message

Only using the contents of .ssh/known_hosts when the file exists for ssh/scp auto-completion. Closes issue #20

Diff

 1diff --git a/lib/completion.zsh b/lib/completion.zsh
 2index deeb52824e8df33653704b67cc28bf431a9e225a..c231ee21e2ff1d051177526d1403900670efcb5b 100644
 3--- a/lib/completion.zsh
 4+++ b/lib/completion.zsh
 5@@ -22,7 +22,7 @@ else
 6 fi
 7 
 8 zstyle ':completion:*' list-colors ''
 9-zstyle ':completion:*' hosts $( sed 's/[, ].*$//' $HOME/.ssh/known_hosts )
10+
11 
12 unsetopt MENU_COMPLETE
13 #setopt AUTO_MENU
14@@ -35,7 +35,12 @@ zstyle ':completion:*:*:*:*:*' menu yes select
15 
16 zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01'
17 zstyle ':completion:*:*:*:*:processes' command "ps -u `whoami` -o pid,user,comm -w -w"
18-zstyle ':completion:*:*:(ssh|scp):*:*' hosts `sed 's/^\([^ ,]*\).*$/\1/' ~/.ssh/known_hosts`
19+
20+# Load known hosts file for auto-completion with ssh and scp commands
21+if [ -f ~/.ssh/known_hosts ]; then
22+  zstyle ':completion:*' hosts $( sed 's/[, ].*$//' $HOME/.ssh/known_hosts )
23+  zstyle ':completion:*:*:(ssh|scp):*:*' hosts `sed 's/^\([^ ,]*\).*$/\1/' ~/.ssh/known_hosts`
24+fi
25 
26 # Complete on history
27 # zstyle ':completion:*:history-words' stop yes