aboutsummaryrefslogtreecommitdiff
path: root/bash/bash_completion.d/_ssh_config_hosts.bash
blob: 0959f52b41535308f661024d87ac17432d14385e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Complete ssh_config(5) hostnames
_ssh_config_hosts() {

    # Iterate through SSH client config paths
    local config
    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

            # Check host value
            case $value in
                # No empties
                '') ;;
                # No wildcards
                *'*'*) ;;
                # Found a match; print it
                "$2"*) COMPREPLY[ci++]=$value ;;
            esac

        done < "$config"
    done
}