#compdef sized

autoload -U is-at-least

_sized() {
    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[@]}" : \
'-m+[Minimum size filter (e.g. "10MB", "1gb")]:MIN_SIZE:_default' \
'--min-size=[Minimum size filter (e.g. "10MB", "1gb")]:MIN_SIZE:_default' \
'-n+[Limit the number of results per table]:NUMBER:_default' \
'--number=[Limit the number of results per table]:NUMBER:_default' \
'--sort=[Sort by columns (e.g. "type\:asc,size\:dsc"). defaults to size\:dsc. Columns\: name, type, size (disk usage), apparent (logical), blocks]:SORT:_default' \
'-d+[Depth to traverse (0 = only immediate children)]:DEPTH:_default' \
'--depth=[Depth to traverse (0 = only immediate children)]:DEPTH:_default' \
'-j+[Number of threads to use (defaults to available logical CPUs)]:THREADS:_default' \
'--threads=[Number of threads to use (defaults to available logical CPUs)]:THREADS:_default' \
'--completions=[Generate shell completions]:COMPLETIONS:(bash elvish fish powershell zsh)' \
'--format=[Output format]:FORMAT:(text csv json)' \
'--save=[Save output to file (optional filename, defaults to timestamped name)]::SAVE:_files' \
'--precision=[Precision for size output (decimal places)]:PRECISION:_default' \
'--units=[Unit system to use]:UNITS:(binary decimal)' \
'--generate-man-page=[Generate man page to the specified output directory]:GENERATE_MAN_PAGE:_files' \
'-v[Print version]' \
'--version[Print version]' \
'-a[Show apparent size (logical file length) in addition to disk usage]' \
'--apparent[Show apparent size (logical file length) in addition to disk usage]' \
'(--path-relative)-f[Display full absolute paths]' \
'(--path-relative)--path-full[Display full absolute paths]' \
'--path-relative[Display paths relative to current directory (default)]' \
'-x[Stay on the target'\''s filesystem instead of descending into other mounts]' \
'--one-file-system[Stay on the target'\''s filesystem instead of descending into other mounts]' \
'-i[Respect .gitignore and .ignore files]' \
'--ignore[Respect .gitignore and .ignore files]' \
'-c[Show comparison between total and non-ignored files]' \
'--compare[Show comparison between total and non-ignored files]' \
'-h[Print help]' \
'--help[Print help]' \
'::path -- Directory to analyze:_files' \
&& ret=0
}

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

if [ "$funcstack[1]" = "_sized" ]; then
    _sized "$@"
else
    compdef _sized sized
fi
