#compdef stat

autoload -U is-at-least

_stat() {
    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[@]}" : \
'-c+[stat-help-format]:FORMAT:_default' \
'--format=[stat-help-format]:FORMAT:_default' \
'--printf=[stat-help-printf]:FORMAT:_default' \
'-L[stat-help-dereference]' \
'--dereference[stat-help-dereference]' \
'-f[stat-help-file-system]' \
'--file-system[stat-help-file-system]' \
'-t[stat-help-terse]' \
'--terse[stat-help-terse]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
'::files:_files' \
&& ret=0
}

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

if [ "$funcstack[1]" = "_stat" ]; then
    _stat "$@"
else
    compdef _stat stat
fi
