#!/bin/bash

_hdfs_complete()
{
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    words=$(IFS=$' '; echo "${COMP_WORDS[@]:0:COMP_CWORD+1}")
    opts=$(${COMP_WORDS[0]} complete "$words")

    if [[ $opts == "_FILE_" ]]
    then
      COMPREPLY=( $(compgen -o default -- ${cur}) )
    else
      COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
    fi

    if [[ $COMPREPLY != "" && $COMPREPLY != */ && $COMP_POINT == ${#COMP_LINE} ]]
    then
      COMPREPLY="$COMPREPLY "
    fi

    return 0
}

complete -o nospace -F _hdfs_complete hdfs
