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