#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+[treat each number LO through HI as an input line]:LO-HI:_default' \
'()--input-range=[treat each number LO through HI as an input line]:LO-HI:_default' \
'*-n+[output at most COUNT lines]:COUNT:_default' \
'*--head-count=[output at most COUNT lines]:COUNT:_default' \
'-o+[write result to FILE instead of standard output]:FILE:_files' \
'--output=[write result to FILE instead of standard output]:FILE:_files' \
'(--random-source)--random-seed=[seed with STRING for reproducible output]:STRING:' \
'--random-source=[get random bytes from FILE]:FILE:_files' \
'(-i --input-range)-e[treat each ARG as an input line]' \
'(-i --input-range)--echo[treat each ARG as an input line]' \
'-r[output lines can be repeated]' \
'--repeat[output lines can be repeated]' \
'-z[line delimiter is NUL, not newline]' \
'--zero-terminated[line delimiter is NUL, not newline]' \
'-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
