[zsh] fix hosts completion when ssh config doesn't exist

This commit is contained in:
Dmytro Meleshko 2019-09-25 18:04:32 +03:00
parent 16b40e1982
commit a3c85fa826

View file

@ -38,4 +38,11 @@ zstyle ':completion:*:processes' command "ps xo pid,user,cmd"
zstyle ':completion:*:processes-names' command "ps xho comm=" zstyle ':completion:*:processes-names' command "ps xho comm="
zstyle ':completion:*:processes' force-list always zstyle ':completion:*:processes' force-list always
zstyle -e ':completion:*:hosts' hosts 'reply=("${(@f)$(awk "match(\$0, /^Host[[:blank:]]*/) { print substr(\$0, RLENGTH+1); }" ~/.ssh/config)}")' _completion_get_hosts() {
print localhost
if [[ -f ~/.ssh/config ]]; then
awk "match(\$0, /^Host[[:blank:]]*/) { print substr(\$0, RLENGTH+1); }" ~/.ssh/config
fi
}
zstyle -e ':completion:*:hosts' hosts 'reply=("${(@f)$(_completion_get_hosts)}")
'