Debian Codegraph @

docs/completion_commands.rst

raw
1 Completion Commands
2 ===================
3
4 .. contents::
5 :local:
6 :depth: 1
7
8 .. list-table::
9 :header-rows: 1
10 :widths: 30 70
11
12 * - Command
13 - Description
14 * - :ref:`none`
15 - No completion, but specifies that an argument is required
16 * - :ref:`integer`
17 - Complete an integer
18 * - :ref:`float`
19 - Complete a floating point number
20 * - :ref:`combine`
21 - Combine multiple completion commands
22 * - :ref:`file`
23 - Complete a file
24 * - :ref:`directory`
25 - Complete a directory
26 * - :ref:`choices`
27 - Complete from a set of values
28 * - :ref:`value_list`
29 - Complete a list
30 * - :ref:`exec`
31 - Complete by the output of a command or function
32 * - :ref:`exec_fast`
33 - Complete by the output of a command or function (fast and unsafe)
34 * - :ref:`exec_internal`
35 - Complete by a function that uses the shell's internal completion mechanisms
36 * - :ref:`range`
37 - Complete a range of integers
38 * - :ref:`signal`
39 - Complete a signal
40 * - :ref:`hostname`
41 - Complete a hostname
42 * - :ref:`process`
43 - Complete a process
44 * - :ref:`pid`
45 - Complete a PID
46 * - :ref:`command`
47 - Complete a command
48 * - :ref:`user`
49 - Complete a user
50 * - :ref:`group`
51 - Complete a group
52 * - :ref:`service`
53 - Complete a SystemD service
54 * - :ref:`variable`
55 - Complete a shell variable
56 * - :ref:`environment`
57 - Complete an environment variable
58
59 .. _none:
60
61 none
62 ----
63
64 Disables autocompletion for this option but still marks it as requiring an argument.
65
66 Without specifying ``complete``, the option would not take an argument.
67
68 .. code-block:: yaml
69
70 prog: "example"
71 options:
72 - option_strings: ["--none"]
73 complete: ["none"]
74
75 .. _integer:
76
77 integer
78 -------
79
80 Complete an integer.
81
82 **NOTE:** This completion currently serves as documentation and does not provide actual functionality.
83
84 If you want to complete a range of integers, see :ref:`range`.
85
86 .. code-block:: yaml
87
88 prog: "example"
89 options:
90 - option_strings: ["--integer"]
91 complete: ["integer"]
92
93 .. _float:
94
95 float
96 -----
97
98 Complete a floating point number.
99
100 **NOTE:** This completion currently serves as documentation and does not provide actual functionality.
101
102 .. code-block:: yaml
103
104 prog: "example"
105 options:
106 - option_strings: ["--float"]
107 complete: ["float"]
108
109 .. _combine:
110
111 combine
112 -------
113
114 Combine two or more completion commands.
115
116 .. code-block:: yaml
117
118 prog: "example"
119 options:
120 - option_strings: ["--combine"]
121 complete: ["combine", [["user"], ["pid"]]]
122
123 .. _file:
124
125 file
126 ----
127
128 Complete a file.
129
130 You can restrict completion to a specific directory by adding ``{"directory": ...}``.
131
132 .. code-block:: yaml
133
134 prog: "example"
135 options:
136 - option_strings: ["--file"]
137 complete: ["file"]
138 - option_strings: ["--file-tmp"]
139 complete: ["file", {"directory": "/tmp"}]
140
141 Example:
142
143 .. code-block:: console
144
145 $ example --file=<TAB>
146 dir1/ dir2/ file1 file2
147
148 .. _directory:
149
150 directory
151 ---------
152
153 Complete a directory.
154
155 You can restrict completion to a specific directory by adding ``{"directory": ...}``.
156
157 .. code-block:: yaml
158
159 prog: "example"
160 options:
161 - option_strings: ["--directory"]
162 complete: ["directory"]
163 - option_strings: ["--directory-tmp"]
164 complete: ["directory", {"directory": "/tmp"}]
165
166 Example:
167
168 .. code-block:: console
169
170 $ example --directory=<TAB>
171 dir1/ dir2/
172
173 .. _choices:
174
175 choices
176 -------
177
178 Complete a list of items.
179
180 Items can be a list or a dictionary.
181
182 If a dictionary is supplied, the keys are used as items and the values are used
183 as description.
184
185 .. code-block:: yaml
186
187 prog: "example"
188 options:
189 - option_strings: ["--choices-1"]
190 complete: ["choices", ["Item 1", "Item 2"]]
191 - option_strings: ["--choices-2"]
192 complete: ["choices", {"Item 1": "Description 1", "Item 2": "Description 2"}]
193
194 Example:
195
196 .. code-block:: console
197
198 $ example --choices-2=<TAB>
199 Item 1 (Description 1) Item 2 (Description 2)
200
201 .. _value_list:
202
203 value_list
204 ----------
205
206 Complete one or more items from a list of items. Similar to ``mount -o``.
207
208 Arguments with assignable values (``mount -o uid=1000``) aren't supported.
209
210 Arguments are supplied by adding ``{"values": ...}``.
211
212 A separator can be supplied by adding ``{"separator": ...}`` (the default is `","`).
213
214 .. code-block:: yaml
215
216 prog: "example"
217 options:
218 - option_strings: ["--value-list-1"]
219 complete: ["value_list", {"values": ["exec", "noexec"]}]
220 - option_strings: ["--value-list-2"]
221 complete: ["value_list", {"values": {"one": "Description 1", "two": "Description 2"}}]
222
223 Example:
224
225 .. code-block:: console
226
227 $ example --value-list-1=<TAB>
228 exec noexec
229 $ example --value-list-1=exec,<TAB>
230 exec noexec
231 $ example --value-list-2=<TAB>
232 one -- Description 1
233 two -- Description 2
234
235 .. _exec:
236
237 exec
238 ----
239
240 Execute a command and parse the output.
241
242 The output must be in form of::
243
244 <item_1>\t<description_1>\n
245 <item_2>\t<description_2>\n
246 [...]
247
248 An item and its description are delimited by a tabulator.
249
250 These pairs are delimited by a newline.
251
252 .. code-block:: yaml
253
254 prog: "example"
255 options:
256 - option_strings: ["--exec"]
257 complete: ["exec", "printf '%s\\t%s\\n' 'Item 1' 'Description 1' 'Item 2' 'Description 2'"]
258
259 Example:
260
261 .. code-block:: console
262
263 $ example --exec=<TAB>
264 Item 1 (Description 1) Item 2 (Description 2)
265
266 .. _exec_fast:
267
268 exec_fast
269 ---------
270
271 Faster version of exec for handling large amounts of data.
272
273 This implementation requires that the items of the parsed output do not include
274 special shell characters or whitespace.
275
276 .. code-block:: yaml
277
278 prog: "example"
279 options:
280 - option_strings: ["--exec-fast"]
281 complete: ["exec_fast", "printf '%s\\t%s\\n' 1 one 2 two"]
282
283 .. _exec_internal:
284
285 exec_internal
286 -------------
287
288 Execute a function that internally modifies the completion state.
289
290 This is useful if a more advanced completion is needed.
291
292 .. code-block:: yaml
293
294 prog: "example"
295 options:
296 - option_strings: ["--exec-internal"]
297 complete: ["exec_internal", "my_completion_func"]
298
299 Examples:
300
301 Bash::
302
303 my_completion_func() {
304 COMPREPLY=( $(compgen -W "foo bar baz") )
305 }
306
307 Zsh::
308
309 my_completion_func() {
310 local items=( foo bar baz )
311 _describe '' items
312 }
313
314 Fish::
315
316 function my_completion_func
317 printf '%s\n' foo bar baz
318 end
319
320 .. _range:
321
322 range
323 -----
324
325 Complete a range of integers.
326
327 .. code-block:: yaml
328
329 prog: "example"
330 options:
331 - option_strings: ["--range-1"]
332 complete: ["range", 1, 9]
333 - option_strings: ["--range-2"]
334 complete: ["range", 1, 9, 2]
335
336 Example:
337
338 .. code-block:: console
339
340 $ example --range-1=<TAB>
341 1 2 3 4 5 6 7 8 9
342 $ example --range-2=<TAB>
343 1 3 5 7 9
344
345 .. _signal:
346
347 signal
348 ------
349
350 Complete signal names (INT, KILL, TERM, etc.).
351
352 .. code-block:: yaml
353
354 prog: "example"
355 options:
356 - option_strings: ["--signal"]
357 complete: ["signal"]
358
359 Example:
360
361 .. code-block:: console
362
363 $ example --signal=<TAB>
364 ABRT -- Process abort signal
365 ALRM -- Alarm clock
366 BUS -- Access to an undefined portion of a memory object
367 [...]
368
369 .. _hostname:
370
371 hostname
372 --------
373
374 Complete a hostname.
375
376 .. code-block:: yaml
377
378 prog: "example"
379 options:
380 - option_strings: ["--hostname"]
381 complete: ["hostname"]
382
383 Example:
384
385 .. code-block:: console
386
387 $ example --hostname=<TAB>
388 localhost
389
390 .. _process:
391
392 process
393 -------
394
395 Complete a process name.
396
397 .. code-block:: yaml
398
399 prog: "example"
400 options:
401 - option_strings: ["--process"]
402 complete: ["process"]
403
404 Example:
405
406 .. code-block:: console
407
408 $ example --process=s<TAB>
409 scsi_eh_0 scsi_eh_1 sudo systemd [...]
410
411 .. _pid:
412
413 pid
414 ---
415
416 Complete a PID.
417
418 .. code-block:: yaml
419
420 prog: "example"
421 options:
422 - option_strings: ["--pid"]
423 complete: ["pid"]
424
425 Example:
426
427 .. code-block:: console
428
429 $ example --pid=<TAB>
430 1 13 166 19 [...]
431
432 .. _command:
433
434 command
435 -------
436
437 Complete a command.
438
439 .. code-block:: yaml
440
441 prog: "example"
442 options:
443 - option_strings: ["--command"]
444 complete: ["command"]
445
446 Example:
447
448 .. code-block:: console
449
450 $ example --command=bas<TAB>
451 base32 base64 basename basenc bash bashbug
452
453 .. _user:
454
455 user
456 ----
457
458 Complete a username.
459
460 .. code-block:: yaml
461
462 prog: "example"
463 options:
464 - option_strings: ["--user"]
465 complete: ["user"]
466
467 Example:
468
469 .. code-block:: console
470
471 $ example --user=<TAB>
472 avahi bin braph [...]
473
474 .. _group:
475
476 group
477 -----
478
479 Complete a group.
480
481 .. code-block:: yaml
482
483 prog: "example"
484 options:
485 - option_strings: ["--group"]
486 complete: ["group"]
487
488 Example:
489
490 .. code-block:: console
491
492 $ example --group=<TAB>
493 adm audio avahi [...]
494
495 .. _service:
496
497 service
498 -------
499
500 Complete a SystemD service.
501
502 .. code-block:: yaml
503
504 prog: "example"
505 options:
506 - option_strings: ["--service"]
507 complete: ["service"]
508
509 Example:
510
511 .. code-block:: console
512
513 $ example --service=<TAB>
514 TODO
515
516 .. _variable:
517
518 variable
519 --------
520
521 Complete a shell variable name.
522
523 To complete an environment variable, use :ref:`environment`.
524
525 .. code-block:: yaml
526
527 prog: "example"
528 options:
529 - option_strings: ["--variable"]
530 complete: ["variable"]
531
532 Example:
533
534 .. code-block:: console
535
536 $ example --variable=HO<TAB>
537 HOME HOSTNAME HOSTTYPE
538
539 .. _environment:
540
541 environment
542 -----------
543
544 Complete a shell environment variable name.
545
546 .. code-block:: yaml
547
548 prog: "example"
549 options:
550 - option_strings: ["--environment"]
551 complete: ["environment"]
552
553 Example:
554
555 .. code-block:: console
556
557 $ example --environment=X<TAB>
558 XDG_RUNTIME_DIR XDG_SESSION_TYPE [...]