#compdef nl

autoload -U is-at-least

_nl() {
    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[@]}" \
'-b+[use STYLE for numbering body lines]:STYLE: ' \
'--body-numbering=[use STYLE for numbering body lines]:STYLE: ' \
'-d+[use CC for separating logical pages]:CC: ' \
'--section-delimiter=[use CC for separating logical pages]:CC: ' \
'-f+[use STYLE for numbering footer lines]:STYLE: ' \
'--footer-numbering=[use STYLE for numbering footer lines]:STYLE: ' \
'-h+[use STYLE for numbering header lines]:STYLE: ' \
'--header-numbering=[use STYLE for numbering header lines]:STYLE: ' \
'-i+[line number increment at each line]:NUMBER: ' \
'--line-increment=[line number increment at each line]:NUMBER: ' \
'-l+[group of NUMBER empty lines counted as one]:NUMBER: ' \
'--join-blank-lines=[group of NUMBER empty lines counted as one]:NUMBER: ' \
'-n+[insert line numbers according to FORMAT]:FORMAT:(ln rn rz)' \
'--number-format=[insert line numbers according to FORMAT]:FORMAT:(ln rn rz)' \
'-s+[add STRING after (possible) line number]:STRING: ' \
'--number-separator=[add STRING after (possible) line number]:STRING: ' \
'-v+[first line number on each logical page]:NUMBER: ' \
'--starting-line-number=[first line number on each logical page]:NUMBER: ' \
'-w+[use NUMBER columns for line numbers]:NUMBER: ' \
'--number-width=[use NUMBER columns for line numbers]:NUMBER: ' \
'--help[Print help information.]' \
'-p[do not reset line numbers at logical pages]' \
'--no-renumber[do not reset line numbers at logical pages]' \
'-V[Print version]' \
'--version[Print version]' \
'::file:_files' \
&& ret=0
}

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

if [ "$funcstack[1]" = "_nl" ]; then
    _nl "$@"
else
    compdef _nl nl
fi
