#compdef du

autoload -U is-at-least

_du() {
    typeset -A opt_args
    typeset -a _arguments_options
    local ret=1

    if is-at-least 5.2; then
        _arguments_options=(-s -S -C)
    else
        _arguments_options=(-s -C)
    fi

    local context curcontext="$curcontext" state line
    _arguments "${_arguments_options[@]}" : \
'-B+[du-help-block-size]:SIZE:_default' \
'--block-size=[du-help-block-size]:SIZE:_default' \
'-d+[du-help-max-depth]:N:_default' \
'--max-depth=[du-help-max-depth]:N:_default' \
'-t+[du-help-threshold]:SIZE:_default' \
'--threshold=[du-help-threshold]:SIZE:_default' \
'*--exclude=[du-help-exclude]:PATTERN:_default' \
'*-X+[du-help-exclude-from]:FILE:_files' \
'*--exclude-from=[du-help-exclude-from]:FILE:_files' \
'*--files0-from=[du-help-files0-from]:FILE:_files' \
'--time=[du-help-time]' \
'--time-style=[du-help-time-style]:STYLE:_default' \
'--help[du-help-print-help]' \
'-a[du-help-all]' \
'--all[du-help-all]' \
'--apparent-size[du-help-apparent-size]' \
'-b[du-help-bytes]' \
'--bytes[du-help-bytes]' \
'-c[du-help-total]' \
'--total[du-help-total]' \
'-h[du-help-human-readable]' \
'--human-readable[du-help-human-readable]' \
'--inodes[du-help-inodes]' \
'-k[du-help-block-size-1k]' \
'-l[du-help-count-links]' \
'--count-links[du-help-count-links]' \
'-L[du-help-dereference]' \
'--dereference[du-help-dereference]' \
'-D[du-help-dereference-args]' \
'-H[du-help-dereference-args]' \
'--dereference-args[du-help-dereference-args]' \
'-P[du-help-no-dereference]' \
'--no-dereference[du-help-no-dereference]' \
'-m[du-help-block-size-1m]' \
'-0[du-help-null]' \
'--null[du-help-null]' \
'-S[du-help-separate-dirs]' \
'--separate-dirs[du-help-separate-dirs]' \
'-s[du-help-summarize]' \
'--summarize[du-help-summarize]' \
'--si[du-help-si]' \
'-x[du-help-one-file-system]' \
'--one-file-system[du-help-one-file-system]' \
'-v[du-help-verbose]' \
'--verbose[du-help-verbose]' \
'-V[Print version]' \
'--version[Print version]' \
'::FILE:_files' \
&& ret=0
}

(( $+functions[_du_commands] )) ||
_du_commands() {
    local commands; commands=()
    _describe -t commands 'du commands' commands "$@"
}

if [ "$funcstack[1]" = "_du" ]; then
    _du "$@"
else
    compdef _du du
fi
