#compdef tail

autoload -U is-at-least

_tail() {
    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[@]}" : \
'-c+[tail-help-bytes]: :_default' \
'--bytes=[tail-help-bytes]: :_default' \
'-f+[tail-help-follow]' \
'--follow=[tail-help-follow]' \
'-n+[tail-help-lines]: :_default' \
'--lines=[tail-help-lines]: :_default' \
'--pid=[tail-help-pid]:PID:_default' \
'-s+[tail-help-sleep-interval]:N:_default' \
'--sleep-interval=[tail-help-sleep-interval]:N:_default' \
'--max-unchanged-stats=[tail-help-max-unchanged-stats]:N:_default' \
'-q[tail-help-quiet]' \
'--quiet[tail-help-quiet]' \
'--silent[tail-help-quiet]' \
'-v[tail-help-verbose]' \
'--verbose[tail-help-verbose]' \
'-z[tail-help-zero-terminated]' \
'--zero-terminated[tail-help-zero-terminated]' \
'--use-polling[tail-help-polling-linux]' \
'--retry[tail-help-retry]' \
'-F[tail-help-follow-retry]' \
'--presume-input-pipe[]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
'*::files:_files' \
&& ret=0
}

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

if [ "$funcstack[1]" = "_tail" ]; then
    _tail "$@"
else
    compdef _tail tail
fi
