浏览代码

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

Robby Russell 15 年之前
父节点
当前提交
fc3a3c72b1
共有 1 个文件被更改,包括 7 次插入2 次删除
  1. 7 2
      lib/completion.zsh

+ 7 - 2
lib/completion.zsh

@@ -22,7 +22,7 @@ else
 fi
 
 zstyle ':completion:*' list-colors ''
-zstyle ':completion:*' hosts $( sed 's/[, ].*$//' $HOME/.ssh/known_hosts )
+
 
 unsetopt MENU_COMPLETE
 #setopt AUTO_MENU
@@ -35,7 +35,12 @@ zstyle ':completion:*:*:*:*:*' menu yes select
 
 zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01'
 zstyle ':completion:*:*:*:*:processes' command "ps -u `whoami` -o pid,user,comm -w -w"
-zstyle ':completion:*:*:(ssh|scp):*:*' hosts `sed 's/^\([^ ,]*\).*$/\1/' ~/.ssh/known_hosts`
+
+# Load known hosts file for auto-completion with ssh and scp commands
+if [ -f ~/.ssh/known_hosts ]; then
+  zstyle ':completion:*' hosts $( sed 's/[, ].*$//' $HOME/.ssh/known_hosts )
+  zstyle ':completion:*:*:(ssh|scp):*:*' hosts `sed 's/^\([^ ,]*\).*$/\1/' ~/.ssh/known_hosts`
+fi
 
 # Complete on history
 # zstyle ':completion:*:history-words' stop yes