#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+[Number of bytes to print]: :_default' \
'--bytes=[Number of bytes to print]: :_default' \
'-f+[Print the file as it grows]:: :(descriptor name)' \
'--follow=[Print the file as it grows]:: :(descriptor name)' \
'-n+[Number of lines to print]: :_default' \
'--lines=[Number of lines to print]: :_default' \
'--pid=[With -f, terminate after process ID, PID dies]:PID:_default' \
'-s+[Number of seconds to sleep between polling the file when running with -f]:N:_default' \
'--sleep-interval=[Number of seconds to sleep between polling the file when running with -f]:N:_default' \
'--max-unchanged-stats=[Reopen a FILE which has not changed size after N (default 5) iterations to see if it has been unlinked or renamed (this is the usual case of rotated log files); This option is meaningful only when polling (i.e., with --use-polling) and when --follow=name]:N:_default' \
'-q[Never output headers giving file names]' \
'--quiet[Never output headers giving file names]' \
'--silent[Never output headers giving file names]' \
'-v[Always output headers giving file names]' \
'--verbose[Always output headers giving file names]' \
'-z[Line delimiter is NUL, not newline]' \
'--zero-terminated[Line delimiter is NUL, not newline]' \
'--use-polling[Disable '\''inotify'\'' support and use polling instead]' \
'--retry[Keep trying to open a file if it is inaccessible]' \
'-F[Same as --follow=name --retry]' \
'--debug[indicate which --follow implementation is used]' \
'--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
