blob: e84d9ad0460aff3a73d47df324ab902595ddeff1 (
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
|
#compdef lp lpr lpq lprm lpoptions lpstat lpinfo lpadmin
_lp_get_printer()
{
# No reason to call _lp_get_printer when service == lpstat or lpinfo. Others
# matched below.
case $service in
(lpr|lpq|lprm)
[[ "$words" == (#I)*-P* ]] && printer="${${words##*(#I)-P( |)}%% *}"
;;
(lp)
[[ "$words" == (#I)*-d* ]] && printer="${${words##*(#I)-d( |)}%% *}"
;;
(lpadmin)
[[ "$words" == (#I)*-p* ]] && printer="${${words##*(#I)-p( |)}%% *}"
;;
(lpoptions)
[[ "$words" == (#I)*-(d|p)* ]] && \
printer="${${words##*(#I)-(d|p)( |)}%% *}"
;;
esac
}
_lp_job_options()
{
local expl printer
local -a lopts_with_args lopts_no_args desc_opts
# Generic options (from lp manual page)
lopts_with_args=(collate job-{hold-until,priority,sheets} media
number-up{,-layout} orientation-requested outputorder page-border
page-ranges sides)
lopts_no_args=(fit-to-page mirror)
if [[ $service == 'lpadmin' ]]; then
# Extra options from lpadmin man page.
lopts_with_args+=(cupsIPPSupplies cupsSNMPSupplies job-k-limit
job-page-limit job-quota-period job-sheets-default name name-default
port-monitor printer-error-policy printer-is-shared printer-op-policy)
fi
_lp_get_printer
[[ -n "$printer" ]] && printer=(-p $printer)
# The program specified by the style list-printer-options should list jobs in
# the same style as lpoptions -l.
if compset -P 1 '*='; then
# List values for the option
case ${IPREFIX%=} in
(media)
compadd "$@" a4 letter legal
;;
(orientation-requested)
desc_opts=(
'4:rotated 90 degrees counter-clockwise'
'5:rotated 90 degrees clockwise'
'6:rotated 180 degrees')
_describe "orientation requested" desc_opts
;;
(sides)
compadd "$@" one-sided two-sided-{long,short}-edge
;;
(number-up)
_description -V option-o-1 expl "pages per sheet"
compadd "$expl[@]" 2 4 6 9 16
;;
(number-up-layout)
_description -V option-o-1 expl "layout"
compadd "$expl[@]" btlr btrl lrbt lrtb rlbt rltb tblr tbrl
;;
(cupsIPPSupplies|cupsSNMPSupplies|printer-is-shared)
compadd "$@" true false
;;
(printer-error-policy)
compadd "$@" abort-job retry-job retry-current-job stop-printer
;;
(Duplex|BRDuplex)
desc_opts=(
"DuplexTumble:flip short side"
"DuplexNoTumble:flip long side"
"None")
_describe "duplex options" desc_opts
;;
(*)
compadd "$@" \
$(_call_program list-printer-options lpoptions $printer -l | \
grep "^${IPREFIX%=}" | cut -d: -f2 | tr -d \* )
;;
esac
else
# List options
local eq_suffix
# Don't add an '=' suffix when completing lpoptions -r
if [[ $service == lpoptions && $words[CURRENT-1] == "-r" ]]; then
eq_suffix=()
else
eq_suffix=(-S '=')
fi
_description lpopts expl "generic printer options"
compadd "$expl[@]" $eq_suffix $lopts_with_args
compadd "$expl[@]" $lopts_no_args
_description printeropts expl "printer specific options"
compadd "$expl[@]" $eq_suffix \
$(_call_program list-printer-options \
lpoptions $printer -l | cut -d/ -f1)
fi
}
_lp_list_jobs()
{
local ret=1 printer shown
local -a list disp strs
_lp_get_printer
[[ -n "$printer" ]] && printer=(-P $printer)
list=( ${(M)"${(f@)$(_call_program jobs lpq $printer 2> /dev/null)}":#[0-9]*} )
if (( $#list )); then
_tags users jobs
while _tags; do
if _requested users; then
strs=( "${(@)${(@)list##[^ ]##[ ]##[^ ]##[ ]##}%%[ ]*}" )
if [[ -z "$shown" ]] &&
zstyle -T ":completion:${curcontext}:users" verbose;
then
disp=(-ld list)
shown=yes
else
disp=()
fi
_all_labels users expl user compadd "$disp[@]" -a strs ||
_users && ret=0
fi
if _requested jobs; then
strs=( "${(@)${(@)list##[^ ]##[ ]##[^ ]##[ ]##[^ ]##[ ]##}%%[ ]*}" )
if [[ -z "$shown" ]] &&
zstyle -T ":completion:${curcontext}:jobs" verbose; then
disp=(-ld list)
shown=yes
else
disp=()
fi
_all_labels jobs expl job compadd "$disp[@]" -a strs && ret=0
fi
(( ret )) || return 0
done
else
_message 'no print jobs'
fi
return 1
}
_lp()
{
case $service in
(lpq)
_arguments \
'-E[Force encryption]' \
'-U:username (for connection to server):_users' \
'-h:alternate server:_hosts' \
'(-a)-P+[Destination printer]:printers:_printers' \
'(-P)-a[All printers]' \
'-l[Long listing]' \
'*:poll interval (+seconds):'
;;
(lprm)
_arguments \
'-E[Force encryption]' \
'-U:username (for connection to server):_users' \
'-h:alternate server:_hosts' \
'-P+[Destination printer]:printers:_printers' \
'*:job ids:_lp_list_jobs'
;;
(lpoptions)
_arguments \
'-E[Force encryption]' \
'-U:username (for connection to server):_users' \
'-h:alternate server:_hosts' \
'(-p -l -r -x)-d+[Set default printer]:printers:_printers' \
'(-l -x)*-o:job options:_lp_job_options' \
'(-d -x)-p+[Destination printer for options]:printers:_printers' \
'(-d -o -r -x)-l[List options]' \
'(-d -l -x)*-r:remove option:_lp_job_options' \
'(-d -l -r -o)-x+[Remove all options]:printers:_printers'
;;
(lpstat)
_arguments \
'-E[Force encryption]' \
'-R[Shows print job ranking]' \
'-U:username (for connection to server):_users' \
'-W:which jobs:(completed not-completed)' \
'-a+[Show accepting state]:printers:_printers' \
'-c:printer classes:' \
'-d[Show current default destination]' \
'-h:hostname (alternate server):_hosts' \
'-l[Long listing]' \
'-o+[Destinations]:printers:_printers' \
'-p+:printers:_printers' \
'-r[CUPS server running status]' \
'-s[Status summary]' \
'-t[All status info]' \
'-u[List jobs by users]:users:_users' \
'-v+[Show devices]:printers:_printers'
;;
(lpr)
_arguments \
'-E[Force encryption]' \
'-H:hostname (alternate server):_hosts' \
'(-C -J -T)'-{C,J,T}':job name:' \
'-P+[Destination printer]:printers:_printers' \
'-U:username (for connection to server):_users' \
'-#[Copies]:copies (1--100):' \
'-h[Disables banner printing]' \
'-l[Raw file]' \
'-m[Send an email on job completion]' \
'*-o:print job options:_lp_job_options' \
'-p[Format with shaded header incl. date, time etc.]' \
'-q[Hold job for printing.]' \
'-r[Delete files after printing]' \
'*:PS/PDF files:_pspdf'
;;
(lp)
_arguments \
'-E[Force encryption]' \
'-U[Username (for connection to server)]:username:_users' \
'-c[(OBSOLETE) copy to spool dir before printing]' \
'-d+[Destination printer]:printers:_printers' \
'-h:hostname (alternate server):_hosts' \
'-i[Job id to modify]:job id:' \
'-m[Send an email on job completion]' \
'-n[Copies]:copies (1--100):' \
'*-o:print job options:_lp_job_options' \
'-q[Job priority -- 1 (lowest) to 100 (highest)]:priority:' \
"-s[Don't report resulting job IDs]" \
'-t[Sets the job name]:job name:' \
'-u[Job submission username]:username:_users' \
'-H[Time to print]:print time (or enter hh\:mm):(hold immediate restart resume)' \
'-P:page range list:' \
'*:PS/PDF files:_pspdf'
;;
(lpinfo)
_arguments \
'-E[Force encryption]' \
'-U[Username (for connection to server)]:username:_users' \
'-h:hostname (alternate server):_hosts' \
'-l[Shows a "long" listing of devices or drivers]' \
{--exclude-schemes,--include-schemes}'[Device/PPD schemes to filter from results]:scheme-list:' \
'(-v --timeout)--device-id[IEEE-1284 device ID to match]:device-id-string:' \
'(-v --timeout)--language:locale:' \
'(-v --timeout)--product[Product to match]:name:' \
'(-v --timeout)--make-and-model[Make and model to match]:name:' \
'(-v --timeout)-m[List available drivers]' \
'(-m --device-id --language --make-and-model --product)--timeout[Timeout when listing devices with -v]:timeout (seconds):' \
'(-m --device-id --language --make-and-model --product)-v[List available devices]'
;;
(lpadmin)
_arguments \
'-E[Force encryption/Enable destination]' \
'-U[Username (for connection to server)]:username:_users' \
'-h:hostname (alternate server):_hosts' \
'(-p -R -x -o)-d+[Default printer]:printers:_printers' \
'(-d -x)-p+[Configure printer]:printers:_printers' \
'(-p -R -d -o)-x+[Delete printer]:printers:_printers' \
'(-x -d)-R[Name-default]:name-default:' \
'-c:printer classes:' \
'-m:model:' \
'(-x -d)*-o:options:_lp_job_options' \
'-r[Remove from class]:class:' \
'-u[Access policy]:access policy:' \
'-v[Device-uri of printer queue]:device-uri:' \
'-D[Text description of destination]:info:' \
'-L[Location of the printer]:location:' \
'-P[PPD file to use]:PPD file:_files "*.(#i)ppd(-.)"'
esac
}
_lp "$@"
|