1#compdef fmt gfmt
2
3local variant
4local -a args
5local copt="[preserve indentation of first two lines]"
6local wopt="[specify maximum line width]:width [75]"
7local sopt="[don't join short lines\: split only]"
8
9args=( -A "-*" "(1 2)-w+$wopt" '*:file:_files' )
10_pick_variant -r variant gnu=GNU $OSTYPE --version
11case $variant in
12  gnu)
13    args=(
14      '(-c --crown-margin)'{-c,--crown-margin}$copt
15      '(-w --width)'{-w+,--width=}$wopt
16      '(-p --prefix)'{-p+,--prefix=}'[only reformat lines with specified prefix]:prefix'
17      '(-s --split-only)'{-s,--split-only}$sopt
18      '(-t --tagged-paragraph)'{-t,--tagged-paragraph}'[indentation of first line different from second]'
19      '(-u --uniform-spacing)'{-u,--uniform-spacing}'[use one space between words, two after sentences]'
20      '(-g --goal)'{-g,--goal=}'[specify goal width]:goal width [93% of width]'
21      '(- *)--help[display help information]'
22      '(- *)--version[display version information]'
23      '*:file:_files'
24    )
25  ;;
26  solaris*)
27    args=(
28      "-c$copt"
29      "-s$sopt"
30    )
31  ;;
32  netbsd*)
33    args+=(
34      '-C[center the text]'
35      '(1 2)-g+[specify goal width]:goal width'
36      '(1 2)-m+[specify maximum width]:maximum width'
37      '-r[format all lines]'
38    )
39  ;|
40  darwin*|dragonfly*|freebsd*|openbsd*)
41    args+=(
42      '-c[center the text line by line]'
43      '-m[sensible formatting of mail header lines]'
44      '-n[format lines beginning with a . (dot) character]'
45      "-p[change in indentation doesn't start new paragraph]"
46      '-s[collapse whitespace inside lines]'
47      '-d+[specify sentence-ending characters]:sentence ends [.?!]'
48      '-l+[replace initial spaces with tabs]:tab width [8]'
49      '-t+[specify tab width of input files]:tab width [8]'
50    )
51  ;& # fall-through
52  netbsd*)
53    args+=( ':: :_guard "[0-9]#" goal width' )
54    (( ${(M)#words[1,CURRENT-1]:#[0-9]##} )) && args+=(
55      ':: :_guard "[0-9]#" maximum width'
56    )
57  ;;
58esac
59
60_arguments -s -S $args
61