From 7096b7b5a5a647bf3d6d946fd022236cf16f9914 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Wed, 25 Mar 2015 19:33:39 +1300 Subject: Include system-wide ssh config in completion Also, let the shell do the complaining if the file can't be read --- bash/bashrc.d/ssh.bash | 22 ++++++++++------------ 1 file 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") ) -- cgit v1.2.3