# vncviewer(1) completion


comp_include _get_cword _known_hosts


_vncviewer()
{
    local cur prev
    local -a config
    
    COMPREPLY=()
    cur=`_get_cword`
    prev=${COMP_WORDS[COMP_CWORD-1]}

    case "$prev" in
    -via)
       _known_hosts -a
       ;;
    *)
       # ssh into the the server, find and ping the broadcast address, then
       # sort and show the results.
       COMPREPLY=( $( ssh -o 'Batchmode yes' $prev \
              "ping -bnc 4 255.255.255.255" 2>/dev/null | \
              awk -F ' ' '{print $4}' | \
              sort -n | uniq | egrep '[0-9]+\.[0-9]+\.' 2>/dev/null ) )
    esac
                                   
    return 0
} # _vncviewer()
