#compdef cat

autoload -U is-at-least

_cat() {
    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[@]}" : \
'-A[cat-help-show-all]' \
'--show-all[cat-help-show-all]' \
'-b[cat-help-number-nonblank]' \
'--number-nonblank[cat-help-number-nonblank]' \
'-e[cat-help-show-nonprinting-ends]' \
'-E[cat-help-show-ends]' \
'--show-ends[cat-help-show-ends]' \
'-n[cat-help-number]' \
'--number[cat-help-number]' \
'-s[cat-help-squeeze-blank]' \
'--squeeze-blank[cat-help-squeeze-blank]' \
'-t[cat-help-show-nonprinting-tabs]' \
'-T[cat-help-show-tabs]' \
'--show-tabs[cat-help-show-tabs]' \
'-v[cat-help-show-nonprinting]' \
'--show-nonprinting[cat-help-show-nonprinting]' \
'-u[cat-help-ignored-u]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
'::file:_files' \
&& ret=0
}

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

if [ "$funcstack[1]" = "_cat" ]; then
    _cat "$@"
else
    compdef _cat cat
fi
