From e155f9a75bc56fad6e84cd4543af5d7c60680762 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Fri, 17 May 2024 13:12:22 +0900 Subject: [PATCH] perf(completions/ssh): filter known_hosts in awk --- completions/ssh.completion.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/completions/ssh.completion.sh b/completions/ssh.completion.sh index af60615..f477593 100644 --- a/completions/ssh.completion.sh +++ b/completions/ssh.completion.sh @@ -52,13 +52,15 @@ function _omb_completion_ssh { local known_hosts_file for known_hosts_file in ~/.ssh/known_hosts /etc/ssh/ssh_known_hosts; do if [[ -r $known_hosts_file ]]; then - if grep -v -q -e '^ ssh-rsa' "$known_hosts_file"; then - known_hosts_files+=("$known_hosts_file") - fi + known_hosts_files+=("$known_hosts_file") fi done if ((${#known_hosts_files[@]} != 0)); then - COMPREPLY+=($(compgen -W "$(awk '{print $1}' "${known_hosts_files[@]}" | grep -v ^\| | cut -d, -f 1 | sed -e 's/\[//g' | sed -e 's/\]//g' | cut -d: -f1 | grep -v ssh-rsa)" "${options[@]}")) + COMPREPLY+=($(compgen -W "$(awk ' + $1 !~ /^\|/ { + gsub(/[][]|[,:].*/, "", $1); + if ($1 !~ /ssh-rsa/) print $1; + }' "${known_hosts_files[@]}")" "${options[@]}")) fi # parse hosts defined in /etc/hosts