#compdef uniq

autoload -U is-at-least

_uniq() {
    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[@]}" : \
'-D+[print all duplicate lines. Delimiting is done with blank lines. \[default\: none\]]::delimit-method:(none prepend separate)' \
'--all-repeated=[print all duplicate lines. Delimiting is done with blank lines. \[default\: none\]]::delimit-method:(none prepend separate)' \
'(-d --repeated -D --all-repeated -u --unique -c --count)--group=[show all items, separating groups with an empty line. \[default\: separate\]]::group-method:(separate prepend append both)' \
'-w+[compare no more than N characters in lines]:N:_default' \
'--check-chars=[compare no more than N characters in lines]:N:_default' \
'-s+[avoid comparing the first N characters]:N:_default' \
'--skip-chars=[avoid comparing the first N characters]:N:_default' \
'-f+[avoid comparing the first N fields]:N:_default' \
'--skip-fields=[avoid comparing the first N fields]:N:_default' \
'-c[prefix lines by the number of occurrences]' \
'--count[prefix lines by the number of occurrences]' \
'-i[ignore differences in case when comparing]' \
'--ignore-case[ignore differences in case when comparing]' \
'-d[only print duplicate lines]' \
'--repeated[only print duplicate lines]' \
'-u[only print unique lines]' \
'--unique[only print unique lines]' \
'-z[end lines with 0 byte, not newline]' \
'--zero-terminated[end lines with 0 byte, not newline]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
'*::files:_files' \
&& ret=0
}

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

if [ "$funcstack[1]" = "_uniq" ]; then
    _uniq "$@"
else
    compdef _uniq uniq
fi
