aboutsummaryrefslogblamecommitdiff
path: root/bash/bashrc.d/ssh.bash
blob: 40327b4303c7f80205c91e6f5dc5db0aaa9b7058 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
                                                           
        
 
                                                             
                  

                                                              



                                             
                                      
                        
        

                               

                                                               
                                         
        
 
                                                
 
# Completion for ssh/sftp/ssh-copy-id with config hostnames
_ssh() {

    # 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
    for host in "${hosts[@]}" ; do
        [[ $host == "${COMP_WORDS[COMP_CWORD]}"* ]] || continue
        COMPREPLY[${#COMPREPLY[@]}]=$host
    done
}
complete -F _ssh -o default ssh sftp ssh-copy-id