about summary refs log tree commit diff
path: root/Completion/User/_pbm
blob: 9bcbef933e6af5d1bbb99ab55d96006d1aac6734 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#compdef -p p[bgpn]m*

local pat opts ret=1

# No other completion functions, please.

_compskip=all

if (( ! $+_pbm_options )); then

  # Most of the stuff is done by table lookup in these arrays.

  typeset -gA _pbm_options _pbm_arg_options

  # Options with arguments, per command.

  _pbm_arg_options=(
    pbmreduce 'value'
    pbmtext 'font:_files:-g:*.(#i)pbm'
    pbmtolj 'resolution'
    pbmtolps 'dpi'
    pbmtomacp 'l r t b'
    pgmcrater 'number height ysize width xsize gamma'
    pgmkernel 'weight'
    pgmnorm 'bpercent bvalue wpercent wvalue'
    pgmoil 'n'
    pgmtexture 'd'
    pgmtopbm 'value'
    pgmtoppm 'map:_files:-g:*.(#i)ppm'
    ppmbrighten 's v'
    ppmdither 'dim red green blue'
    ppmforge 'dimension hour inclination tilt mesh power glaciers ice saturation seed stars xsize width ysize height'
    ppmnorm 'bpercent bvalue wpercent wvalue'
    ppmquant 'map:_files:-g:*.(#i)ppm'
    ppmtoacad 'background aspect'
    ppmtoicr 'windowname expand display'
    ppmtomitsu 'sharpness:compadd:1:2:3:4 enlarge:compadd:1:2:3 media:compadd:A:A4:AS:A4S copy:compadd:1:2:3:4:5:6:7:8:9'
    ppmtopj 'gamma xpos ypos back:compadd:dark:lite render:compadd:none:snap:bw:dither:diffuse:monodither:monodiffuse:clusterdither:monoclusterdither'
    ppmtopjxl 'gamma xshift yshift xsize width xscale ysize height yscale'
    ppmtouil 'name'
    ppmtoxpm 'name'
    pnmalias 'fgcolor:_colors bgcolor:_colors weight'
    pnmcomp 'xoff yoff alpha:_files:-g:*.(#i)pgm'
    pnmhistmap 'max'
    pnmindex 'size across colors'
    pnmmargin 'color:_colors'
    pnmscale 'xsize width ysize height xscale yscale xysize'
    pnmtoddif 'resolution'
    pnmtofits 'min max'
    pnmtops 'scale dpi width height'
    pnmtosgi 'imagename'
    pnmtotiff 'predictor rowsperstrip'
    pnmtoxwd 'pseudodepth'
  )

  # Options without arguments.

  _pbm_options=(
    pbmclean 'connect'
    pbmmake 'white black gray'
    pbmmask 'expand'
    pbmreduce 'floyd fs threshold'
    pbmtoepsi 'bbonly'
    pgmenhance '1 2 3 4 5 6 7 8 9'
    pgmramp 'lr tb rectangle ellipse'
    pgmtopbm 'floyd fs threshold dither8 d8 cluster3 c3 cluster4 c4 cluster8 c8'
    ppmbrighten 'n'
    ppmdist 'intensity frequency'
    ppmforge 'clouds night'
    ppmpat 'gingham2 g2 gingham3 g3 madras tartan poles squig camo anticamo'
    ppmquant 'floyd fs'
    ppmqvga 'd q v'
    ppmtoacad 'dxb poly white 8'
    ppmtobmp 'os2 windows'
    ppmtogif 'interlace'
    ppmtoicr 'rle'
    ppmtoilbm 'hamif'
    ppmtomap 'sort square'
    ppmtomitsu 'dpi300 tiny'
    ppmtopj 'rle center'
    ppmtopjxl 'nopack presentation dark diffuse cluster dither'
    ppmtosixel 'raw margin'
    ppmtotga 'mono cmap rgb norle'
    pnmalias 'bonly fonly balias falias'
    pnmarith 'add subtract multiply'
    pnmcat 'white black leftright lr topbottom tb jtop jbottom jleft jright'
    pnmcomp 'invert'
    pnmcrop 'white black'
    pnmflip 'leftright lr topbottom tb transpose xy rotate90 r90 ccw rotate270 r270 cw rotate180 r180'
    pnmhistmap 'black white verbose'
    pnmindex 'black'
    pnmmargin 'white black'
    pnmpad 'white black'
    pnmpaste 'replace or and xor'
    pnmrotate 'noantialias'
    pnmshear 'noantialias'
    pnmtops 'turn noturn rle runlength'
    pnmtorast 'standard rle'
    pnmtosgi 'verbatim rle'
    pnmtotiff 'none packbits lzw g3 g4 2d fill msb2lsb lsb2msb'
    pnmtoxwd 'directcolor'
  )
fi

opts=( $=_pbm_arg_options[$words[1]] )
if (( $#opts )); then

  # This Command has options with arguments. The options are already in
  # `opts'. Now we see if we are after one of these options on the line.

  local after="$opts[(I)${words[CURRENT-1][2,-1]}(|:*)]"

  if (( after )); then

    # We are. If the string contains a colon, anything after it is a 
    # colon-separated list of words. We just execute this list of words
    # as a command with its arguments.

    if [[ "$opts[$after]" = *:* ]]; then
      after="${${opts[after]#*:}//:/ }"
      [[ -z "$after" ]] || $=after 
    fi
    return
  fi

  # Otherwise we just add the option names.

  compadd -J options - -${^=opts%%:*}
fi

# And the names of the options without arguments.

opts=( $=_pbm_options[$words[1]] )
(( $#opts )) && compadd -J options - -${^=opts}

# A small special case here: the first argument of `ppmmake' is a
# color. More of these could be added.

if [[ "$words[1]" = ppmmake && CURRENT -eq 2 ]]; then
  _colors
  return
fi

# Generate the filenames.

if [[ "$words[1]" = pnm* ]]; then
  pat='*.(#i)p[bgp]m'
else
  pat="*.(#i)${words[1][1,3]}"
fi

_path_files -J files -g "$pat" || _files -J files -g '*.(#i)p[bgp]m'