#compdef cut

autoload -U is-at-least

_cut() {
    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+[filter byte columns from the input source]:LIST: ' \
'--bytes=[filter byte columns from the input source]:LIST: ' \
'-c+[alias for character mode]:LIST: ' \
'--characters=[alias for character mode]:LIST: ' \
'-d+[specify the delimiter character that separates fields in the input source. Defaults to Tab.]:DELIM: ' \
'--delimiter=[specify the delimiter character that separates fields in the input source. Defaults to Tab.]:DELIM: ' \
'-f+[filter field columns from the input source]:LIST: ' \
'--fields=[filter field columns from the input source]:LIST: ' \
'--output-delimiter=[in field mode, replace the delimiter in output lines with this option'\''s argument]:NEW_DELIM: ' \
'-w[Use any number of whitespace (Space, Tab) to separate fields in the input source (FreeBSD extension).]' \
'--complement[invert the filter - instead of displaying only the filtered columns, display all but those columns]' \
'-s[in field mode, only print lines which contain the delimiter]' \
'--only-delimited[in field mode, only print lines which contain the delimiter]' \
'-z[instead of filtering columns based on line, filter columns based on \\0 (NULL character)]' \
'--zero-terminated[instead of filtering columns based on line, filter columns based on \\0 (NULL character)]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
'::file:_files' \
&& ret=0
}

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

if [ "$funcstack[1]" = "_cut" ]; then
    _cut "$@"
else
    compdef _cut cut
fi
