comp_include _filedir _get_cword


_longopt()
{
    local cur opt

    cur=`_get_cword`

    if [[ "$cur" == --*=* ]]; then
        opt=${cur%%=*}
        # cut backslash that gets inserted before '=' sign
        opt=${opt%\\*}
        cur=${cur#*=}
        _filedir
        COMPREPLY=( $( compgen -P "$opt=" -W '${COMPREPLY[@]}' -- $cur))
        return 0
    fi

    if [[ "$cur" == -* ]]; then
        COMPREPLY=( $( $1 --help 2>&1 | sed -e '/--/!d' \
                -e 's/.*\(--[-A-Za-z0-9]\+=\?\).*/\1/' | \
                   command grep "^$cur" | sort -u ) )
    elif [[ "$1" == @(mk|rm)dir ]]; then
        _filedir -d
    else
        _filedir
    fi
}
