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

    # Read hostnames from existent config files, no asterisks
    local -a hosts
    local config option value
    for config in "$HOME"/.ssh/config /etc/ssh/ssh_config ; do
        [[ -e $config ]] || continue
        while read -r option value _ ; do
            [[ $option == Host ]] || continue
            [[ $value != *'*'* ]] || continue
            hosts[${#hosts[@]}]=$value
        done < "$config"
    done

    # Generate completion reply
    local host
    for host in "${hosts[@]}" ; do
        [[ $host == "${COMP_WORDS[COMP_CWORD]}"* ]] || continue
        COMPREPLY[${#COMPREPLY[@]}]=$host
    done
}