diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2015-03-25 19:33:39 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2015-03-25 19:33:39 +1300 |
commit | 7096b7b5a5a647bf3d6d946fd022236cf16f9914 (patch) | |
tree | f1f703ea40081652a620a49f5bddcd207d15779f | |
parent | Change if-elseif chain to a switch-case (diff) | |
download | dotfiles-7096b7b5a5a647bf3d6d946fd022236cf16f9914.tar.gz dotfiles-7096b7b5a5a647bf3d6d946fd022236cf16f9914.zip |
Include system-wide ssh config in completion
Also, let the shell do the complaining if the file can't be read
-rw-r--r-- | bash/bashrc.d/ssh.bash | 22 |
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") ) |