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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
|
\input texinfo @c -*-texinfo-*-
@c %**start of header
@setfilename auto-auto-complete.info
@settitle auto-auto-complete
@afourpaper
@documentencoding UTF-8
@documentlanguage en
@finalout
@c %**end of header
@dircategory Development
@direntry
* auto-auto-complete: (auto-auto-complete). Autogenerate shell auto-completion scripts
@end direntry
@copying
Copyright @copyright{} 2014 Mattias Andrée
@quotation
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with no
Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
Texts. A copy of the license is included in the section entitled
``GNU Free Documentation License''.
@end quotation
@end copying
@ifnottex
@node Top
@top auto-auto-complete -- Autogenerate shell auto-completion scripts
@insertcopying
@end ifnottex
@titlepage
@title auto-auto-complete
@subtitle Autogenerate shell auto-completion scripts
@author by Mattias Andrée (maandree)
@page
@c @center `'
@vskip 0pt plus 1filll
@insertcopying
@end titlepage
@contents
@menu
* Overview:: Brief overview of @command{auto-auto-complete}.
* Invoking:: Invocation of @command{auto-auto-complete}.
* Syntax:: The auto-auto-complete syntax.
* GNU Free Documentation License:: Copying and sharing this manual.
@end menu
@node Overview
@chapter Overview
@command{auto-auto-complete} provides a LISP-like
@footnote{A sane alternative to using XML.} declarative
language for creating auto-completion scripts for commands
in a shell-agnostic way. The current version of
@command{auto-auto-complete} can use such files to generate
auto-completion scripts for the @command{bash}, @command{zsh}
and @command{fish} shells.
@command{auto-auto-complete}'s language limited in comparsion
to for example raw auto-completion scripts for the @command{bash}
shell, however it is well enough for most projects.
@node Invoking
@chapter Invoking
@command{auto-auto-complete} recognises two options:
@table @option
@item -o
@itemx --output OUTPUT_FILE
Specifies the pathname of the generated file.
@item -s
@itemx -f
@itemx --file
@itemx --source SOURCE_FILE
Specifies the pathname of the auto-auto-complete script.
@end table
Both of these options must be used. Additionally
the shell that the generate file should be generated
for must be specified; this is done by adding name
of the shell as a stand-along argument, for example
@command{auto-auto-complete bash --output mycmd.bash --source mycmd.autocomplete}
It is also possible to define variables that can be
used the auto-auto-complete script. If you, for example,
want to give the variable @var{command} the value
@code{mycmd}, add the argument @option{command=mycmd}.
It is also possible to define arrays, for example
if you want the variable @var{srcopt} to be an array
of the for values @code{-s}, @code{-f}, @code{--source}
and @code{--file}, add the arguments @option{srcopt=-s},
@option{srcopt=-f}, @option{srcopt=--source} and
@option{srcopt=--file}. It is not possible to have
variable whose name begin with a dash (`-').
@node Syntax
@chapter Syntax
@command{auto-auto-complete} uses a LISP-like free form
syntax. Valid whitespace is normal blank space, horizontal
tab space@footnote{Also know simply as tab.},
carriage return@footnote{The first character in a new line
in for example the HTTP protocol and in Window's encoding
for new lines, it was the new line character in the classical
Mac operating systems}, line feed (new line) and form feed
(new page). Comments can be started with either a semicolon
(;) or a hash (#). Comments end at the next following
new line, which may either be a carriage return, line feed
or form feed. Comments cannot be started inside quotes.
The backslash character (\) can be used to force the
following character to be parsed verbatim, this is called
escaping. It is highly discourage to use this to escape
new lines, especially if the new line encoding used in the
document is carrige return–line feed, as that would only
escape the carrige return. There is also a set of characters
that have a special meaning when they are escaped:
@table @asis
@item a
Audible bell character.
@item b
Backspace character.
@item e
Escape character.
@item f
Form feed character.
@item n
Line feed character.
@item r
Carriage character.
@item t
Horizontal tab space character.
@item v
Vertical tab space character.
@item 0
Null character.
@end table
Quotes, either simple quotes (') or double quotes (")
can be used to parse all character verbatim except
backslash (\). A quote ends at the next quote character
that is not escaped by a backslash (\) and is identical
to the opening quote character. This is especially useful
for escaping whitespace and round brackets.
The rest of this chapter will demonstrate how to write a
script by example of @command{ponysay} (because it uses
most of the syntax).
The first thing we do is to declare which command the
script is for. We do this by creating the root brackets
and put the name of the command as the first element.
@example
(ponysay)
@end example
However, @command{ponysay} has a very similar command
called @command{ponythink}. It is sensible to let the
same script be used for auto-complete for both commands,
to do this we utilise that we can define variables
when we invoke @command{auto-auto-complete}.
@example
((value command))
@end example
Now when we compile this script we need invoke
@command{auto-auto-complete} with either
@option{command=ponysay} or @option{command=ponythink}.
If we want @command{ponysay} to be used if we
do not specify a value for @var{command} we instead
write:
@example
((value command ponysay))
@end example
Remember that we could give a variable multiple values.
This can also be done here. However in this example
we only want one value. For example, @command{((value var a b))}
would generate @command{(a b)} if @var{var} has not been set.
@command{ponysay} recognises the options @option{-h} and
@option{--help} for printing a summary of recognised options.
These options does not take any arguments and hence are specified
with @code{(unargumented)}.
@example
((value command ponysay)
(unargumented (options -h --help)
(desc 'Show summary of options'))
)
@end example
This only specifies that these option exists, if we also want
the generated scripts to suggest @option{--help} we need to
add @code{(complete --help)}.
@example
((value command ponysay)
(unargumented (options -h --help)
(complete --help)
(desc 'Show summary of options'))
)
@end example
Now that we have our first option, lets add a few others, to
keep the example short, we will skip the most of the options.
@example
((value command ponysay)
(unargumented (options -h --help)
(complete --help)
(desc 'Show summary of options'))
(unargumented (options -l --list)
(complete --list)
(desc 'List all MLP:FiM ponies'))
(unargumented (options +l ++list)
(complete ++list)
(desc 'List all non-MLP:FiM ponies'))
(unargumented (options -X --256-colours --256colours --x-colours)
(desc 'Use xterm colours'))
)
@end example
Now (especially if we had added all options) we have many
@code{(unargumented)} blocks. We can use @code{(multiple)}
so we do not have to write @code{unargumented} so many times.
@example
((value command ponysay)
(multiple unargumented
((options -h --help) (complete --help)
(desc 'Show summary of options'))
((options -l --list) (complete --list)
(desc 'List all MLP:FiM ponies'))
((options +l ++list) (complete ++list)
(desc 'List all non-MLP:FiM ponies'))
((options -X --256-colours --256colours --x-colours)
(desc 'Use xterm colours'))
)
)
@end example
To keep this example short we will truncate this to:
@example
((value command ponysay)
(multiple unargumented ...) ;We have cut out the options.
)
@end example
@command{ponysay} also have a number of options that does
take an argument. We will add a few of them.
@example
((value command ponysay)
(multiple unargumented ...) ;We have cut out the options.
(multiple argumented
((options -f --file --pony) (complete --file --pony)
(desc 'Specify the pony that should printed'))
((options -b --bubble --balloon) (complete --balloon)
(desc 'Specify message balloon style'))
((options -W --wrap) (complete --wrap)
(desc 'Specify wrapping column'))
((options +c --colour) (complete --colour)
(desc 'Specify colour of the balloon, balloon link and message'))
)
)
@end example
Just like @command{ponysay --help} prints @code{--wrap COLUMN}
to indicate that the argument for @option{--wrap} is is an
index of the column where the message printed by @command{ponysay}
is wrapped, shells could display the text @code{COLUMN} as
a placeholder for the next argument when you have typed
@option{--wrap}. To enable this in shells that support it,
we use @code{(arg)}.
@example
((value command ponysay)
(multiple unargumented ...) ;We have cut out the options.
(multiple argumented
((options -f --file --pony) (complete --file --pony) (arg PONY)
(desc 'Specify the pony that should printed'))
((options -b --bubble --balloon) (complete --balloon) (arg STYLE)
(desc 'Specify message balloon style'))
((options -W --wrap) (complete --wrap) (arg COLUMN)
(desc 'Specify wrapping column)')
((options +c --colour) (complete --colour) (arg ANSI-COLOUR)
(desc 'Specify colour of the balloon, balloon link and message'))
)
)
@end example
The next step now is to specify the type of argument the options
want. To do this we use @code{(files)}. The elements in @code{(files)}
specify what type of file the shell should suggest. Multiple
type can be used. Tehe recognsied ones are:
@table @code
@item -0
Do not suggest files, or do not suggest files of types specified
after @code{-0}.
@item -a
Suggest all files.
@item -f
Suggest regular files and pipes.
@item -r
Suggest regular files but not pipes.
@item -d
Suggest directories.
@item -l
Suggest symlinks. This is suggest by default,
but @code{-0} can be used to stop this.
@item -s
Suggest sockets.
@item -D
Suggest doors.
@end table
@example
((value command ponysay)
(multiple unargumented ...) ;We have cut out the options.
(multiple argumented
((options -f --file --pony) (complete --file --pony) (arg PONY)
(files -f)
(desc 'Specify the pony that should printed'))
((options -b --bubble --balloon) (complete --balloon) (arg STYLE)
(files -f)
(desc 'Specify message balloon style'))
((options -W --wrap) (complete --wrap) (arg COLUMN)
(files -0)
(desc Specify wrapping column))
((options +c --colour) (complete --colour) (arg ANSI-COLOUR)
(files -0)
(desc 'Specify colour of the balloon, balloon link and message'))
)
)
@end example
@code{(files)} can also be used to specify patterns (using
@code{sh}-globbing) for the filenames of the files to suggest.
For example @code{--pony} in @command{ponysay} should only,
in respect to files, suggest files that end with @code{.pony}.
@example
((value command ponysay)
(multiple unargumented ...) ;We have cut out the options.
(multiple argumented
((options -f --file --pony) (complete --file --pony) (arg PONY)
(files -f *.pony)
(desc 'Specify the pony that should printed'))
((options -b --bubble --balloon) (complete --balloon) (arg STYLE)
(files -f *.say)
(desc 'Specify message balloon style'))
((options -W --wrap) (complete --wrap) (arg COLUMN)
(files -0)
(desc Specify wrapping column))
((options +c --colour) (complete --colour) (arg ANSI-COLOUR)
(files -0)
(desc 'Specify colour of the balloon, balloon link and message'))
)
)
@end example
For @option{--balloon} files ending with @code{.say} should be
suggested if the completion is for @command{ponysay}, but for
@command{ponythink} @code{.think}-files should be suggest.
We can use @code{(case)} to select this based on the value of
the first element in the root block, which is the name of the command.
@example
((value command ponysay)
(multiple unargumented ...) ;We have cut out the options.
(multiple argumented
((options -f --file --pony) (complete --file --pony) (arg PONY)
(files -f *.pony)
(desc 'Specify the pony that should printed'))
((options -b --bubble --balloon) (complete --balloon) (arg STYLE)
(files -f (case (ponysay *.say) (ponythink *.think)))
(desc 'Specify message balloon style'))
((options -W --wrap) (complete --wrap) (arg COLUMN)
(files -0)
(desc Specify wrapping column))
((options +c --colour) (complete --colour) (arg ANSI-COLOUR)
(files -0)
(desc 'Specify colour of the balloon, balloon link and message'))
)
)
@end example
Another part of options with arguments is suggestions that are not
based on filenames.
@example
((value command ponysay)
(multiple unargumented ...) ;We have cut out the options.
(multiple argumented
((options -f --file --pony) (complete --file --pony) (arg PONY)
(suggest pony-f) (files -f *.pony)
(desc 'Specify the pony that should printed'))
((options -b --bubble --balloon) (complete --balloon) (arg STYLE)
(suggest balloon)
(files -f (case (ponysay *.say) (ponythink *.think)))
(desc 'Specify message balloon style'))
((options -W --wrap) (complete --wrap) (arg COLUMN)
(suggest wrap) (files -0)
(desc Specify wrapping column))
((options +c --colour) (complete --colour) (arg ANSI-COLOUR)
(files -0)
(desc 'Specify colour of the balloon, balloon link and message'))
)
(suggestion pony-f) ;We will fill this in later...
(suggestion balloon) ;We will fill this in later...
(suggestion wrap) ;We will fill this in later...
)
@end example
Lets cut out the options again to make this shorter.
@example
((value command ponysay)
(multiple unargumented ...) ;We have cut out the options.
(multiple argumented ...) ;We have cut out the options.
(suggestion pony-f) ;We will fill this in later...
(suggestion balloon) ;We will fill this in later...
(suggestion wrap) ;We will fill this in later...
)
@end example
Another part of ponysay is that it will take also
argument that are not associated with an option make
make a message it prints out of thiat.
@example
((value command ponysay)
(default (arg MESSAGE) (files -0) (suggest message)
(desc 'Message spoken by the pony'))
(multiple unargumented ...) ;We have cut out the options.
(multiple argumented ...) ;We have cut out the options.
(suggestion message) ;We will fill this in later...
(suggestion pony-f) ;We will fill this in later...
(suggestion balloon) ;We will fill this in later...
(suggestion wrap) ;We will fill this in later...
)
@end example
A rather unusual part of @command{ponysay} is that
it has variadic options. A variadic option is a option
that takes all following arguments, unconditionally.
For example, in @command{ponysay} you can write
@code{--ponies twilight trixie} instead of
@code{--pony twilight --pony trixie}. @code{(variadic)}
is used to declare a variadic option. @code{(bind)}
becomes interesting here; because @command{ponysay}'s
variadic options have non-variadic counterparts, it
is pleasant to reuse the non-variadic options'
configurations. @code{(bind)} will copy everything
that is missing except @code{(options)} and
@code{(complete)}. In this example we will not
use @code{(complete)} because we do not want variadic
options to be suggest but we will use @code{(desc)}
because we want to adjust the descriptions.
@example
((value command ponysay)
(default (arg MESSAGE) (files -0) (suggest message)
(desc 'Message spoken by the pony'))
(multiple unargumented ...) ;We have cut out the options.
(multiple argumented ...) ;We have cut out the options.
(variadic (options --f --files --ponies) (bind -f)
(desc 'Specify the ponies that may be printed'))
(suggestion message) ;We will fill this in later...
(suggestion pony-f) ;We will fill this in later...
(suggestion balloon) ;We will fill this in later...
(suggestion wrap) ;We will fill this in later...
)
@end example
Notice that we used @code{-f} for the element in @code{(bind)},
this is because we want @option{--f}, @option{--files} and
@code{--ponies} to have the same configurations (with exception
for the description) as the @option{-f} option.
Once again, to make the example shorter we will cut out
some parts.
@example
( ;We have cut out everything but the (suggestion):s.
(suggestion message) ;We will fill this in later...
(suggestion pony-f) ;We will fill this in later...
(suggestion balloon) ;We will fill this in later...
(suggestion wrap) ;We will fill this in later...
)
@end example
For @code{(suggestion message)} we want the word
`MESSAGE' to be suggested to let the user know
that the non-option arguments make up the message
that is printed (if used).
@example
( ;We have cut out everything but the (suggestion):s.
(suggestion message (verbatim MESSAGE))
(suggestion pony-f) ;We will fill this in later...
(suggestion balloon) ;We will fill this in later...
(suggestion wrap) ;We will fill this in later...
)
@end example
For @code{(suggestion pony-f)} we want, in addition
to the .pony-files which as already been configured,
.pony-files from @file{/usr/share/ponysay/ponies}
to be suggested without the .pony-suffix.
@example
( ;We have cut out everything but the (suggestion):s.
(suggestion message (verbatim MESSAGE))
(suggestion pony-f (ls "'/usr/share/ponysay/ponies'" .pony))
(suggestion balloon) ;We will fill this in later...
(suggestion wrap) ;We will fill this in later...
)
@end example
However, if the shell supports executing comments to
get suggetions we want to utilise this.
@example
( ;We have cut out everything but the (suggestion):s.
(suggestion message (verbatim MESSAGE))
(suggestion pony-f (exec "'/usr/bin/ponysay'" --onelist)
(noexec ls "'/usr/share/ponysay/ponies'" .pony))
(suggestion balloon) ;We will fill this in later...
(suggestion wrap) ;We will fill this in later...
)
@end example
@code{(suggestion balloon)} will work very similarly.
@example
( ;We have cut out everything but the (suggestion):s.
(suggestion message (verbatim MESSAGE))
(suggestion pony-f (exec "'/usr/bin/ponysay'" --onelist)
(noexec ls "'/usr/share/ponysay/ponies'" .pony))
(suggestion balloon (exec "'/usr/bin/ponysay'" --balloonlist)
(no-exec ls "'/usr/share/ponysay/balloons'"
(case (ponysay .say) (ponythink .think))))
(suggestion wrap) ;We will fill this in later...
)
@end example
The first thing we want to do for @option{--wrap}
is to give it some default suggestion.
@example
( ;We have cut out everything but (suggestion wrap)
(suggestion wrap (verbatim none inherit 100 60))
)
@end example
The next step is to suggest the terminal's
width minus 10 columns. In the Bash shell this
can be calculated with
@command{$(( $(stty size | cut -d ' ' -f 2) - 10 ))}.
@example
( ;We have cut out everything but (suggestion wrap)
(suggestion wrap
(verbatim none inherit 100 60)
(calc (pipe (stty size) (cut -d ' ' -f 2)) - 10)
)
)
@end example
As seen here @code{(pipe (a) (b) (c))} translates into
@code{(a | b | c)}. There are a few similar blocks that
can be used.
@table @code
@item (fullpipe (a) (b) (c))
@code{(a |& b |& c)}, or equivalently:
@code{(a 2>&1 | b 2>&1 | c)}
@item (cat (a) (b) (c))
@code{(a ; b ; c)}
@item (and (a) (b) (c))
@code{(a && b && c)}
@item (or (a) (b) (c))
@code{(a || b || c)}
@end table
@node GNU Free Documentation License
@appendix GNU Free Documentation License
@include fdl.texinfo
@bye
|