#compdef pr

autoload -U is-at-least

_pr() {
    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[@]}" : \
'--pages=[Begin and stop printing with page FIRST_PAGE\[\:LAST_PAGE\]]:FIRST_PAGE[:LAST_PAGE]:_default' \
'-h+[Use the string header to replace the file name                 in the header line.]:STRING:_default' \
'--header=[Use the string header to replace the file name                 in the header line.]:STRING:_default' \
'-D+[Use '\''date'\''-style FORMAT for the header date.]:FORMAT:_default' \
'--date-format=[Use '\''date'\''-style FORMAT for the header date.]:FORMAT:_default' \
'-n+[Provide width digit line numbering.  The default for width,                 if not specified, is 5.  The number occupies the first width column                 positions of each text column or each line of -m output.  If char                 (any non-digit character) is given, it is appended to the line number                 to separate it from whatever follows.  The default for char is a \`<tab>\`.                 Line numbers longer than width columns are truncated.]:[char][width]:_default' \
'--number-lines=[Provide width digit line numbering.  The default for width,                 if not specified, is 5.  The number occupies the first width column                 positions of each text column or each line of -m output.  If char                 (any non-digit character) is given, it is appended to the line number                 to separate it from whatever follows.  The default for char is a \`<tab>\`.                 Line numbers longer than width columns are truncated.]:[char][width]:_default' \
'-N+[start counting with NUMBER at 1st line of first page printed]:NUMBER:_default' \
'--first-line-number=[start counting with NUMBER at 1st line of first page printed]:NUMBER:_default' \
'-l+[Override the 66-line default (default number of lines of text 56,                 and with -F 63) and reset the page length to lines.  If lines is not                 greater than the sum  of  both the  header  and trailer depths (in lines),                 the pr utility shall suppress both the header and trailer, as if the -t                 option were in effect.]:PAGE_LENGTH:_default' \
'--length=[Override the 66-line default (default number of lines of text 56,                 and with -F 63) and reset the page length to lines.  If lines is not                 greater than the sum  of  both the  header  and trailer depths (in lines),                 the pr utility shall suppress both the header and trailer, as if the -t                 option were in effect.]:PAGE_LENGTH:_default' \
'-w+[Set the width of the line to width column positions for multiple                 text-column output only. If the -w option is not specified and the -s option                 is not specified, the default width shall be 72. If the -w option is not specified                 and the -s option is specified, the default width shall be 512.]:width:_default' \
'--width=[Set the width of the line to width column positions for multiple                 text-column output only. If the -w option is not specified and the -s option                 is not specified, the default width shall be 72. If the -w option is not specified                 and the -s option is specified, the default width shall be 512.]:width:_default' \
'-W+[set page width to PAGE_WIDTH (72) characters always,                 truncate lines, except -J option is set, no interference                 with -S or -s]:width:_default' \
'--page-width=[set page width to PAGE_WIDTH (72) characters always,                 truncate lines, except -J option is set, no interference                 with -S or -s]:width:_default' \
'--column=[Produce multi-column output that is arranged in column columns                 (the default shall be 1) and is written down each column  in  the order in which                 the text is received from the input file. This option should not be used with -m.                 The options -e and -i shall be assumed for multiple text-column output.  Whether                 or not text columns are produced with identical vertical lengths is unspecified,                 but a text column shall never exceed the length of the page (see the -l option).                 When used with -t, use the minimum number of lines to write the output.]:column:_default' \
'-s+[Separate text columns by the single character char instead of by the                 appropriate number of \`<space>\`s (default for char is the \`<tab>\` character).]::char:_default' \
'--separator=[Separate text columns by the single character char instead of by the                 appropriate number of \`<space>\`s (default for char is the \`<tab>\` character).]::char:_default' \
'-S+[separate columns by STRING,                 without -S\: Default separator \`<TAB>\` with -J and \`<space>\`                 otherwise (same as -S\\" \\"), no effect on column options]::string:_default' \
'--sep-string=[separate columns by STRING,                 without -S\: Default separator \`<TAB>\` with -J and \`<space>\`                 otherwise (same as -S\\" \\"), no effect on column options]::string:_default' \
'-o+[Each line of output shall be preceded by offset \`<space>\`s. If the -o                 option is not specified, the default offset shall be zero. The space taken is                 in addition to the output line width (see the -w option below).]:margin:_default' \
'--indent=[Each line of output shall be preceded by offset \`<space>\`s. If the -o                 option is not specified, the default offset shall be zero. The space taken is                 in addition to the output line width (see the -w option below).]:margin:_default' \
'-e+[expand input CHARs (TABs) to tab WIDTH (8)]:[CHAR][WIDTH]:_default' \
'--expand-tabs=[expand input CHARs (TABs) to tab WIDTH (8)]:[CHAR][WIDTH]:_default' \
'-d[Produce output that is double spaced. An extra \`<newline>\`                 character is output following every \`<newline>\` found in the input.]' \
'--double-space[Produce output that is double spaced. An extra \`<newline>\`                 character is output following every \`<newline>\` found in the input.]' \
'-t[Write neither the five-line identifying header nor the five-line                 trailer usually supplied for each page. Quit writing after the last line                  of each file without spacing to the end of the page.]' \
'--omit-header[Write neither the five-line identifying header nor the five-line                 trailer usually supplied for each page. Quit writing after the last line                  of each file without spacing to the end of the page.]' \
'-T[omit page headers and trailers, eliminate any pagination                 by form feeds set in input files]' \
'--omit-pagination[omit page headers and trailers, eliminate any pagination                 by form feeds set in input files]' \
'-r[omit warning when a file cannot be opened]' \
'--no-file-warnings[omit warning when a file cannot be opened]' \
'-F[Use a \`<form-feed>\` for new pages, instead of the default behavior that                 uses a sequence of \`<newline>\`s.]' \
'--form-feed[Use a \`<form-feed>\` for new pages, instead of the default behavior that                 uses a sequence of \`<newline>\`s.]' \
'-a[Modify the effect of the - column option so that the columns are filled                 across the page in a  round-robin  order (for example, when column is 2, the                 first input line heads column 1, the second heads column 2, the third is the                 second line in column 1, and so on).]' \
'--across[Modify the effect of the - column option so that the columns are filled                 across the page in a  round-robin  order (for example, when column is 2, the                 first input line heads column 1, the second heads column 2, the third is the                 second line in column 1, and so on).]' \
'-b[]' \
'-m[Merge files. Standard output shall be formatted so the pr utility                 writes one line from each file specified by a file operand, side by side                 into text columns of equal fixed widths, in terms of the number of column                 positions. Implementations shall support merging of at least nine file operands.]' \
'--merge[Merge files. Standard output shall be formatted so the pr utility                 writes one line from each file specified by a file operand, side by side                 into text columns of equal fixed widths, in terms of the number of column                 positions. Implementations shall support merging of at least nine file operands.]' \
'-J[merge full lines, turns off -W line truncation, no column                 alignment, --sep-string\[=STRING\] sets separators]' \
'--help[Print help information]' \
'-V[Print version]' \
'--version[Print version]' \
'::files:_files' \
&& ret=0
}

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

if [ "$funcstack[1]" = "_pr" ]; then
    _pr "$@"
else
    compdef _pr pr
fi
