aboutsummaryrefslogtreecommitdiff
path: root/bash/bash_completion.d/_ssh_config_hosts.bash
diff options
context:
space:
mode:
Diffstat (limited to 'bash/bash_completion.d/_ssh_config_hosts.bash')
-rw-r--r--bash/bash_completion.d/_ssh_config_hosts.bash43
1 files changed, 19 insertions, 24 deletions
diff --git a/bash/bash_completion.d/_ssh_config_hosts.bash b/bash/bash_completion.d/_ssh_config_hosts.bash
index 3f937a2a..0959f52b 100644
--- a/bash/bash_completion.d/_ssh_config_hosts.bash
+++ b/bash/bash_completion.d/_ssh_config_hosts.bash
@@ -1,31 +1,26 @@
# Complete ssh_config(5) hostnames
_ssh_config_hosts() {
- # Iterate through words from a subshell
- local ci comp
- while read -r comp ; do
- COMPREPLY[ci++]=$comp
- done < <(
+ # Iterate through SSH client config paths
+ local config
+ for config in "$HOME"/.ssh/config /etc/ssh/ssh_config ; do
+ [[ -e $config ]] || continue
- # Iterate through SSH client config paths
- for config in "$HOME"/.ssh/config /etc/ssh/ssh_config ; do
- [[ -e $config ]] || continue
+ # Read 'Host' options and their first value from file
+ local option value ci
+ while read -r option value _ ; do
+ [[ $option == Host ]] || continue
- # Read 'Host' options and their first value from file
- while read -r option value _ ; do
- [[ $option == Host ]] || continue
+ # Check host value
+ case $value in
+ # No empties
+ '') ;;
+ # No wildcards
+ *'*'*) ;;
+ # Found a match; print it
+ "$2"*) COMPREPLY[ci++]=$value ;;
+ esac
- # Check host value
- case $value in
- # No empties
- ('') ;;
- # No wildcards
- (*'*'*) ;;
- # Found a match; print it
- ("$2"*) printf '%s\n' "$value" ;;
- esac
-
- done < "$config"
- done
- )
+ done < "$config"
+ done
}