aboutsummaryrefslogtreecommitdiff
path: root/bash/bashrc.d/ssh.bash
diff options
context:
space:
mode:
Diffstat (limited to 'bash/bashrc.d/ssh.bash')
-rw-r--r--bash/bashrc.d/ssh.bash22
1 files changed, 10 insertions, 12 deletions
diff --git a/bash/bashrc.d/ssh.bash b/bash/bashrc.d/ssh.bash
index 3a847dc4..91d83e35 100644
--- a/bash/bashrc.d/ssh.bash
+++ b/bash/bashrc.d/ssh.bash
@@ -11,20 +11,18 @@ scp() {
_ssh() {
local word=${COMP_WORDS[COMP_CWORD]}
- # Bail if the configuration file is illegible
- local config=$HOME/.ssh/config
- if [[ ! -r $config ]] ; then
- return 1
- fi
-
- # Read hostnames from the file, no asterisks
+ # Read hostnames from existent config files, no asterisks
local -a hosts
- local option value
- while read -r option value _ ; do
- if [[ $option == Host && $value != *'*'* ]] ; then
- hosts=("${hosts[@]}" "$value")
+ local config option value
+ for config in "$HOME"/.ssh/config /etc/ssh/ssh_config ; do
+ if [[ -e $config ]] ; then
+ while read -r option value _ ; do
+ if [[ $option == Host && $value != *'*'* ]] ; then
+ hosts=("${hosts[@]}" "$value")
+ fi
+ done < "$config"
fi
- done < "$config"
+ done
# Generate completion reply
COMPREPLY=( $(compgen -W "${hosts[*]}" -- "$word") )