Browse code

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

Robby Russell authored on 08/11/2009 at 23:34:02
Showing 1 changed files
... ...
@@ -22,7 +22,7 @@ else
22 22
 fi
23 23
 
24 24
 zstyle ':completion:*' list-colors ''
25
-zstyle ':completion:*' hosts $( sed 's/[, ].*$//' $HOME/.ssh/known_hosts )
25
+
26 26
 
27 27
 unsetopt MENU_COMPLETE
28 28
 #setopt AUTO_MENU
... ...
@@ -35,7 +35,12 @@ zstyle ':completion:*:*:*:*:*' menu yes select
35 35
 
36 36
 zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01'
37 37
 zstyle ':completion:*:*:*:*:processes' command "ps -u `whoami` -o pid,user,comm -w -w"
38
-zstyle ':completion:*:*:(ssh|scp):*:*' hosts `sed 's/^\([^ ,]*\).*$/\1/' ~/.ssh/known_hosts`
38
+
39
+# Load known hosts file for auto-completion with ssh and scp commands
40
+if [ -f ~/.ssh/known_hosts ]; then
41
+  zstyle ':completion:*' hosts $( sed 's/[, ].*$//' $HOME/.ssh/known_hosts )
42
+  zstyle ':completion:*:*:(ssh|scp):*:*' hosts `sed 's/^\([^ ,]*\).*$/\1/' ~/.ssh/known_hosts`
43
+fi
39 44
 
40 45
 # Complete on history
41 46
 # zstyle ':completion:*:history-words' stop yes