#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:_default' \
'*--bytes=[filter byte columns from the input source]:LIST:_default' \
'*-c+[alias for character mode]:LIST:_default' \
'*--characters=[alias for character mode]:LIST:_default' \
'-d+[specify the delimiter character that separates fields in the input source. Defaults to Tab.]:DELIM:_default' \
'--delimiter=[specify the delimiter character that separates fields in the input source. Defaults to Tab.]:DELIM:_default' \
'*-f+[filter field columns from the input source]:LIST:_default' \
'*--fields=[filter field columns from the input source]:LIST:_default' \
'-O+[in field mode, replace the delimiter in output lines with this option'\''s argument]:NEW_DELIM:_default' \
'--output-delimiter=[in field mode, replace the delimiter in output lines with this option'\''s argument]:NEW_DELIM:_default' \
'-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)]' \
'-n[(ignored)]' \
'-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
