[zsh] parse ~/.ssh/config with a zsh script instead of awk as well

This commit is contained in:
Dmytro Meleshko 2021-02-13 17:51:25 +02:00
parent 412015d374
commit 789d9caefd

View file

@ -40,9 +40,12 @@ zstyle ':completion:*:processes' force-list always
_completion_get_hosts() { _completion_get_hosts() {
print localhost print localhost
if [[ -f ~/.ssh/config ]]; then local line
awk "match(\$0, /^Host[[:blank:]]*/) { print substr(\$0, RLENGTH+1); }" ~/.ssh/config < ~/.ssh/config while IFS= read -r line; do
fi if [[ "$line" =~ '^Host[[:blank:]]+(.*)[[:blank:]]*' ]]; then
print -- "${match[1]}"
fi
done
} }
zstyle -e ':completion:*:hosts' hosts 'reply=("${(@f)$(_completion_get_hosts)}")' zstyle -e ':completion:*:hosts' hosts 'reply=("${(@f)$(_completion_get_hosts)}")'