#compdef shuf

autoload -U is-at-least

_shuf() {
    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[@]}" : \
'()-i+[shuf-help-input-range]:LO-HI:_default' \
'()--input-range=[shuf-help-input-range]:LO-HI:_default' \
'*-n+[shuf-help-head-count]:COUNT:_default' \
'*--head-count=[shuf-help-head-count]:COUNT:_default' \
'-o+[shuf-help-output]:FILE:_files' \
'--output=[shuf-help-output]:FILE:_files' \
'--random-source=[shuf-help-random-source]:FILE:_files' \
'(-i --input-range)-e[shuf-help-echo]' \
'(-i --input-range)--echo[shuf-help-echo]' \
'-r[shuf-help-repeat]' \
'--repeat[shuf-help-repeat]' \
'-z[shuf-help-zero-terminated]' \
'--zero-terminated[shuf-help-zero-terminated]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
'::file-or-args:_files' \
&& ret=0
}

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

if [ "$funcstack[1]" = "_shuf" ]; then
    _shuf "$@"
else
    compdef _shuf shuf
fi
