#compdef csplit

autoload -U is-at-least

_csplit() {
    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+[use sprintf FORMAT instead of %02d]:FORMAT:_default' \
'--suffix-format=[use sprintf FORMAT instead of %02d]:FORMAT:_default' \
'-f+[use PREFIX instead of '\''xx'\'']:PREFIX:_default' \
'--prefix=[use PREFIX instead of '\''xx'\'']:PREFIX:_default' \
'-n+[use specified number of digits instead of 2]:DIGITS:_default' \
'--digits=[use specified number of digits instead of 2]:DIGITS:_default' \
'-k[do not remove output files on errors]' \
'--keep-files[do not remove output files on errors]' \
'--suppress-matched[suppress the lines matching PATTERN]' \
'-q[do not print counts of output file sizes]' \
'-s[do not print counts of output file sizes]' \
'--quiet[do not print counts of output file sizes]' \
'--silent[do not print counts of output file sizes]' \
'-z[remove empty output files]' \
'--elide-empty-files[remove empty output files]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
':file:_files' \
':pattern:_default' \
&& ret=0
}

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

if [ "$funcstack[1]" = "_csplit" ]; then
    _csplit "$@"
else
    compdef _csplit csplit
fi
