diff options
author | Mattias Andrée <maandree@operamail.com> | 2015-12-02 10:09:15 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2015-12-02 10:09:15 +0100 |
commit | 3a652d1f419bec2fe8d013b64f3bbc8e446a47b3 (patch) | |
tree | 91adeeacb695ecf9a564d7b11db695ce15a977db /doc/info/auto-auto-complete.texinfo | |
parent | improve readme (diff) | |
download | auto-auto-complete-3a652d1f419bec2fe8d013b64f3bbc8e446a47b3.tar.gz auto-auto-complete-3a652d1f419bec2fe8d013b64f3bbc8e446a47b3.tar.bz2 auto-auto-complete-3a652d1f419bec2fe8d013b64f3bbc8e446a47b3.tar.xz |
improve makefile and move info/ into doc/
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'doc/info/auto-auto-complete.texinfo')
-rw-r--r-- | doc/info/auto-auto-complete.texinfo | 651 |
1 files changed, 651 insertions, 0 deletions
diff --git a/doc/info/auto-auto-complete.texinfo b/doc/info/auto-auto-complete.texinfo new file mode 100644 index 0000000..0931933 --- /dev/null +++ b/doc/info/auto-auto-complete.texinfo @@ -0,0 +1,651 @@ +\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, 2015 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 (`-'). + +Alternatively you can run +@command{auto-auto-complete SHELL --where COMMAND} +(alternatively with @option{-w} instead of +@option{--where}). This will print the pathname +you should use for the generated file when installing +it. However the path prefix will not be included, +so if your package is installed to @file{/usr} +@footnote{The command being installed to @file{/usr/bin} +or @file{/usr/sbin}.}, you sould prepend @file{/usr} +to the output. + + + +@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 <&2 | cut -d ' ' -f 2) - 10 ))}. + +@example +( ;We have cut out everything but (suggestion wrap). + (suggestion wrap + (verbatim none inherit 100 60) + (calc (pipe (stdin-fd (stty size) (stderr)) (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 + +It was also shown that @code{(stdin-fd (a) (stderr))} translates +into @code{a <&2}. @code{(stdin)}, @code{(stdout)} and @code{(stderr)} +translates into @code{0}, @code{1} and @code{2}, respectively. +Additional @code{(stdin-fd a b)} translates into @code{a <&b}, +@code{(stdout-fd a b)} into @code{a >&b}, @code{(stderr-fd a b)} into @code{a 2>&b} +and @code{(fd-fd a b c)} into @code{a b<>&c}. +You can also redirect to files: + +@table @code +@item (stdin a b) +@code{a < b} +@item (stdout a b) +@code{a > b} +@item (stderr a b) +@code{a 2> b} +@item (fd a b c) +@code{a b> c} +@end table + + + +@node GNU Free Documentation License +@appendix GNU Free Documentation License +@include fdl.texinfo + +@bye + |