From b835b3d9ce5613987e9eba13e6b352f870483d8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Havlas?= Date: Fri, 25 Mar 2016 23:29:33 +0100 Subject: [PATCH] Added support for multiple aliases/hosts in single line for ssh completion and plugin --- completion/available/ssh.completion.bash | 4 ++-- plugins/available/ssh.plugin.bash | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/completion/available/ssh.completion.bash b/completion/available/ssh.completion.bash index 19a52991..1ab08000 100644 --- a/completion/available/ssh.completion.bash +++ b/completion/available/ssh.completion.bash @@ -14,7 +14,7 @@ _sshcomplete() { # parse all defined hosts from .ssh/config if [ -r "$HOME/.ssh/config" ]; then - COMPREPLY=($(compgen -W "$(grep ^Host "$HOME/.ssh/config" | awk '{print $2}' )" ${OPTIONS}) ) + COMPREPLY=($(compgen -W "$(grep ^Host "$HOME/.ssh/config" | awk '{for (i=2; i<=NF; i++) print $i}' )" ${OPTIONS}) ) fi # parse all hosts found in .ssh/known_hosts @@ -26,7 +26,7 @@ _sshcomplete() { # parse hosts defined in /etc/hosts if [ -r /etc/hosts ]; then - COMPREPLY=( ${COMPREPLY[@]} $(compgen -W "$( grep -v '^[[:space:]]*$' /etc/hosts | grep -v '^#' | awk '{print $2}' )" ${OPTIONS}) ) + COMPREPLY=( ${COMPREPLY[@]} $(compgen -W "$( grep -v '^[[:space:]]*$' /etc/hosts | grep -v '^#' | awk '{for (i=2; i<=NF; i++) print $i}' )" ${OPTIONS}) ) fi return 0 diff --git a/plugins/available/ssh.plugin.bash b/plugins/available/ssh.plugin.bash index 4e17206c..f670b98c 100644 --- a/plugins/available/ssh.plugin.bash +++ b/plugins/available/ssh.plugin.bash @@ -15,5 +15,5 @@ function sshlist() { about 'list hosts defined in ssh config' group 'ssh' - awk '$1 ~ /Host$/ { print $2 }' ~/.ssh/config + awk '$1 ~ /Host$/ {for (i=2; i<=NF; i++) print $i}' ~/.ssh/config }