1This is zsh.info, produced by makeinfo version 4.8 from ./zsh.texi.
2
3INFO-DIR-SECTION Utilities
4START-INFO-DIR-ENTRY
5* ZSH: (zsh).                     The Z Shell Manual.
6END-INFO-DIR-ENTRY
7
8
9File: zsh.info,  Node: Completion Functions,  Next: Completion System Variables,  Prev: Bindable Commands,  Up: Completion System
10
1120.6 Utility Functions
12======================
13
14
15
16Descriptions follow for utility functions that may be useful when
17writing completion functions.  If functions are installed in
18subdirectories, most of these reside in the Base subdirectory.  Like
19the example functions for commands in the distribution, the utility
20functions generating matches all follow the convention of returning
21status zero if they generated completions and non-zero if no matching
22completions could be added.
23
24
25_absolute_command_paths
26     This function completes external commands as absolute paths (unlike
27     _command_names -e which completes their basenames).  It takes no
28     arguments.
29
30_all_labels [ -x ] [ -12VJ ] TAG NAME DESCR [ COMMAND ARG ... ]
31     This is a convenient interface to the _next_label function below,
32     implementing the loop shown in the _next_label example.  The
33     COMMAND and its arguments are called to generate the matches.  The
34     options stored in the parameter NAME will automatically be inserted
35     into the ARGs passed to the COMMAND.  Normally, they are put
36     directly after the COMMAND, but if one of the ARGs is a single
37     hyphen, they are inserted directly before that.  If the hyphen is
38     the last argument, it will be removed from the argument list
39     before the COMMAND is called.  This allows _all_labels to be used
40     in almost all cases where the matches can be generated by a single
41     call to the compadd builtin command or by a call to one of the
42     utility functions.
43
44     For example:
45
46
47          local expl
48          ...
49          if _requested foo; then
50            ...
51            _all_labels foo expl '...' compadd ... - $matches
52          fi
53
54     Will complete the strings from the matches parameter, using
55     compadd with additional options which will take precedence over
56     those generated by _all_labels.
57
58_alternative [ -O NAME ] [ -C NAME ] SPEC ...
59     This function is useful in simple cases where multiple tags are
60     available.  Essentially it implements a loop like the one
61     described for the _tags function below.
62
63     The tags to use and the action to perform if a tag is requested are
64     described using the SPECs which are of the form:
65     `TAG:DESCR:ACTION'.  The TAGs are offered using _tags and if the
66     tag is requested, the ACTION is executed with the given
67     description DESCR.  The ACTIONs are those accepted by the
68     _arguments function (described below), excluding the `->STATE' and
69     `=...' forms.
70
71     For example, the ACTION may be a simple function call:
72
73
74          _alternative \
75              'users:user:_users' \
76              'hosts:host:_hosts'
77
78     offers usernames and hostnames as possible matches, generated by
79     the _users and _hosts functions respectively.
80
81     Like _arguments, this function uses _all_labels to execute the
82     actions, which will loop over all sets of tags.  Special handling
83     is only required if there is an additional valid tag, for example
84     inside a function called from _alternative.
85
86     The option `-O NAME' is used in the same way as by the _arguments
87     function.  In other words, the elements of the NAME array will be
88     passed to compadd when executing an action.
89
90     Like _tags this function supports the -C option to give a
91     different name for the argument context field.
92
93_arguments [ -nswWCRS ] [ -A PAT ] [ -O NAME ] [ -M MATCHSPEC ]
94           [ : ] SPEC ...
95_arguments [ OPT ... ] -- [ -l ] [ -i PATS ] [ -s PAIR ]
96           [ HELPSPEC ...]
97     This function can be used to give a complete specification for
98     completion for a command whose arguments follow standard UNIX
99     option and argument conventions.
100
101     _Options Overview_
102
103     Options to _arguments itself must be in separate words, i.e. -s -w,
104     not -sw.  The options are followed by SPECs that describe options
105     and arguments of the analyzed command.  To avoid ambiguity, all
106     options to _arguments itself may be separated from the SPEC forms
107     by a single colon.
108
109     The `--' form is used to intuit SPEC forms from the help output of
110     the command being analyzed, and is described in detail below.  The
111     OPTS for the `--' form are otherwise the same options as the first
112     form.  Note that `-s' following `--' has a distinct meaning from
113     `-s' preceding `--', and both may appear.
114
115     The option switches -s, -S, -A, -w, and -W affect how _arguments
116     parses the analyzed command line's options.  These switches are
117     useful for commands with standard argument parsing.
118
119     The options of _arguments have the following meanings:
120
121
122    -n
123          With this option, _arguments sets the parameter NORMARG to
124          the position of the first normal argument in the $words array,
125          i.e. the position after the end of the options.  If that
126          argument has not been reached, NORMARG is set to -1.  The
127          caller should declare `integer NORMARG' if the -n option is
128          passed; otherwise the parameter is not used.
129
130    -s
131          Enable _option stacking_ for single-letter options, whereby
132          multiple single-letter options may be combined into a single
133          word.  For example, the two options `-x' and `-y' may be
134          combined into a single word `-xy'.  By default, every word
135          corresponds to a single option name (`-xy' is a single option
136          named `xy').
137
138          Options beginning with a single hyphen or plus sign are
139          eligible for stacking; words beginning with two hyphens are
140          not.
141
142          Note that -s after -- has a different meaning, which is
143          documented in the segment entitled `Deriving SPEC forms from
144          the help output'.
145
146    -w
147          In combination with -s, allow option stacking even if one or
148          more of the options take arguments.  For example, if -x takes
149          an argument, with no -s, `-xy' is considered as a single
150          (unhandled) option; with -s, -xy is an option with the
151          argument `y'; with both -s and -w, -xy is the option -x and
152          the option -y with arguments to -x (and to -y, if it takes
153          arguments) still to come in subsequent words.
154
155    -W
156          This option takes -w a stage further:  it is possible to
157          complete single-letter options even after an argument that
158          occurs in the same word.  However, it depends on the action
159          performed whether options will really be completed at this
160          point.  For more control, use a utility function like _guard
161          as part of the action.
162
163    -C
164          Modify the curcontext parameter for an action of the form
165          `->STATE'.  This is discussed in detail below.
166
167    -R
168          Return status 300 instead of zero when a $state is to be
169          handled, in the `->STRING' syntax.
170
171    -S
172          Do not complete options after a `--' appearing on the line,
173          and ignore the `--'.  For example, with -S, in the line
174
175
176               foobar -x -- -y
177
178          the `-x' is considered an option, the `-y' is considered an
179          argument, and the `--' is considered to be neither.
180
181    -A PAT
182          Do not complete options after the first non-option argument
183          on the line.  PAT is a pattern matching all strings which are
184          not to be taken as arguments.  For example, to make
185          _arguments stop completing options after the first normal
186          argument, but ignoring all strings starting with a hyphen
187          even if they are not described by one of the OPTSPECs, the
188          form is `-A "-*"'.
189
190    -O NAME
191          Pass the elements of the array NAME as arguments to functions
192          called to execute ACTIONs.  This is discussed in detail below.
193
194    -M MATCHSPEC
195          Use the match specification MATCHSPEC for completing option
196          names and values.  The default MATCHSPEC allows partial word
197          completion after `_' and `-', such as completing `-f-b' to
198          `-foo-bar'.  The default MATCHSPEC is:
199               r:|[_-]=* r:|=*
200
201
202     _SPECs: overview_
203
204     Each of the following forms is a SPEC describing individual sets of
205     options or arguments on the command line being analyzed.
206
207
208    N:MESSAGE:ACTION
209    N::MESSAGE:ACTION
210          This describes the N'th normal argument.  The MESSAGE will be
211          printed above the matches generated and the ACTION indicates
212          what can be completed in this position (see below).  If there
213          are two colons before the MESSAGE the argument is optional.
214          If the MESSAGE contains only white space, nothing will be
215          printed above the matches unless the action adds an
216          explanation string itself.
217
218    :MESSAGE:ACTION
219    ::MESSAGE:ACTION
220          Similar, but describes the _next_ argument, whatever number
221          that happens to be.  If all arguments are specified in this
222          form in the correct order the numbers are unnecessary.
223
224    *:MESSAGE:ACTION
225    *::MESSAGE:ACTION
226    *:::MESSAGE:ACTION
227          This describes how arguments (usually non-option arguments,
228          those not beginning with - or +) are to be completed when
229          neither of the first two forms was provided.  Any number of
230          arguments can be completed in this fashion.
231
232          With two colons before the MESSAGE, the words special array
233          and the CURRENT special parameter are modified to refer only
234          to the normal arguments when the ACTION is executed or
235          evaluated.  With three colons before the MESSAGE they are
236          modified to refer only to the normal arguments covered by
237          this description.
238
239    OPTSPEC
240    OPTSPEC:...
241          This describes an option.  The colon indicates handling for
242          one or more arguments to the option; if it is not present,
243          the option is assumed to take no arguments.
244
245          The following forms are available for the initial OPTSPEC,
246          whether or not the option has arguments.
247
248
249         *OPTSPEC
250               Here OPTSPEC is one of the remaining forms below.  This
251               indicates the following OPTSPEC may be repeated.
252               Otherwise if the corresponding option is already present
253               on the command line to the left of the cursor it will
254               not be offered again.
255
256         -OPTNAME
257         +OPTNAME
258               In the simplest form the OPTSPEC is just the option name
259               beginning with a minus or a plus sign, such as `-foo'.
260               The first argument for the option (if any) must follow
261               as a _separate_ word directly after the option.
262
263               Either of `-+OPTNAME' and `+-OPTNAME' can be used to
264               specify that -OPTNAME and +OPTNAME are both valid.
265
266               In all the remaining forms, the leading `-' may be
267               replaced by or paired with `+' in this way.
268
269         -OPTNAME-
270               The first argument of the option must come directly
271               after the option name _in the same word_.  For example,
272               `-foo-:...' specifies that the completed option and
273               argument will look like `-fooARG'.
274
275         -OPTNAME+
276               The first argument may appear immediately after OPTNAME
277               in the same word, or may appear as a separate word after
278               the option.  For example, `-foo+:...' specifies that the
279               completed option and argument will look like either
280               `-fooARG' or `-foo ARG'.
281
282         -OPTNAME=
283               The argument may appear as the next word, or in same
284               word as the option name provided that it is separated
285               from it by an equals sign, for example `-foo=ARG' or
286               `-foo ARG'.
287
288         -OPTNAME=-
289               The argument to the option must appear after an equals
290               sign in the same word, and may not be given in the next
291               argument.
292
293         OPTSPEC[EXPLANATION]
294               An explanation string may be appended to any of the
295               preceding forms of OPTSPEC by enclosing it in brackets,
296               as in `-q[query operation]'.
297
298               The verbose style is used to decide whether the
299               explanation strings are displayed with the option in a
300               completion listing.
301
302               If no bracketed explanation string is given but the
303               auto-description style is set and only one argument is
304               described for this OPTSPEC, the value of the style is
305               displayed, with any appearance of the sequence `%d' in
306               it replaced by the MESSAGE of the first OPTARG that
307               follows the OPTSPEC; see below.
308
309
310          It is possible for options with a literal `+' or `=' to
311          appear, but that character must be quoted, for example `-\+'.
312
313          Each OPTARG following an OPTSPEC must take one of the
314          following forms:
315
316
317         :MESSAGE:ACTION
318         ::MESSAGE:ACTION
319               An argument to the option; MESSAGE and ACTION are
320               treated as for ordinary arguments.  In the first form,
321               the argument is mandatory, and in the second form it is
322               optional.
323
324               This group may be repeated for options which take
325               multiple arguments.  In other words,
326               :MESSAGE1:ACTION1:MESSAGE2:ACTION2 specifies that the
327               option takes two arguments.
328
329         :*PATTERN:MESSAGE:ACTION
330         :*PATTERN::MESSAGE:ACTION
331         :*PATTERN:::MESSAGE:ACTION
332               This describes multiple arguments.  Only the last OPTARG
333               for an option taking multiple arguments may be given in
334               this form.  If the PATTERN is empty (i.e. :*:), all the
335               remaining words on the line are to be completed as
336               described by the ACTION; otherwise, all the words up to
337               and including a word matching the PATTERN are to be
338               completed using the ACTION.
339
340               Multiple colons are treated as for the `*:...' forms for
341               ordinary arguments:  when the MESSAGE is preceded by two
342               colons, the words special array and the CURRENT special
343               parameter are modified during the execution or
344               evaluation of the ACTION to refer only to the words
345               after the option.  When preceded by three colons, they
346               are modified to refer only to the words covered by this
347               description.
348
349
350
351     Any literal colon in an OPTNAME, MESSAGE, or ACTION must be
352     preceded by a backslash, `\:'.
353
354     Each of the forms above may be preceded by a list in parentheses
355     of option names and argument numbers.  If the given option is on
356     the command line, the options and arguments indicated in
357     parentheses will not be offered.  For example, `(-two -three
358     1)-one:...' completes the option `-one'; if this appears on the
359     command line, the options -two and -three and the first ordinary
360     argument will not be completed after it.  `(-foo):...' specifies
361     an ordinary argument completion; -foo will not be completed if
362     that argument is already present.
363
364     Other items may appear in the list of excluded options to indicate
365     various other items that should not be applied when the current
366     specification is matched: a single star (*) for the rest arguments
367     (i.e. a specification of the form `*:...'); a colon (:) for all
368     normal (non-option-) arguments; and a hyphen (-) for all options.
369     For example, if `(*)' appears before an option and the option
370     appears on the command line, the list of remaining arguments
371     (those shown in the above table beginning with `*:') will not be
372     completed.
373
374     To aid in reuse of specifications, it is possible to precede any
375     of the forms above with `!'; then the form will no longer be
376     completed, although if the option or argument appears on the
377     command line they will be skipped as normal.  The main use for
378     this is when the arguments are given by an array, and _arguments
379     is called repeatedly for more specific contexts: on the first call
380     `_arguments $global_options' is used, and on subsequent calls
381     `_arguments !$^global_options'.
382
383     _SPECs: actions_
384
385     In each of the forms above the ACTION determines how completions
386     should be generated.  Except for the `->STRING' form below, the
387     ACTION will be executed by calling the _all_labels function to
388     process all tag labels.  No special handling of tags is needed
389     unless a function call introduces a new one.
390
391     The functions called to execute ACTIONs will be called with the
392     elements of the array named by the `-O NAME' option as arguments.
393     This can be used, for example, to pass the same set of options for
394     the compadd builtin to all ACTIONs.
395
396     The forms for ACTION are as follows.
397
398
399     (single unquoted space)
400          This is useful where an argument is required but it is not
401          possible or desirable to generate matches for it.  The
402          MESSAGE will be displayed but no completions listed.  Note
403          that even in this case the colon at the end of the MESSAGE is
404          needed; it may only be omitted when neither a MESSAGE nor an
405          ACTION is given.
406
407    (ITEM1 ITEM2 ...)
408          One of a list of possible matches, for example:
409
410
411               :foo:(foo bar baz)
412
413    ((ITEM1\:DESC1 ...))
414          Similar to the above, but with descriptions for each possible
415          match.  Note the backslash before the colon.  For example,
416
417
418               :foo:((a\:bar b\:baz))
419
420          The matches will be listed together with their descriptions
421          if the description style is set with the values tag in the
422          context.
423
424    ->STRING
425          In this form, _arguments processes the arguments and options
426          and then returns control to the calling function with
427          parameters set to indicate the state of processing; the
428          calling function then makes its own arrangements for
429          generating completions.  For example, functions that
430          implement a state machine can use this type of action.
431
432          Where _arguments encounters ACTION in the `->STRING' format,
433          it will strip all leading and trailing whitespace from STRING
434          and set the array state to the set of all STRINGs for which an
435          action is to be performed.  The elements of the array
436          state_descr are assigned the corresponding MESSAGE field from
437          each OPTARG containing such an ACTION.
438
439          By default and in common with all other well behaved
440          completion functions, _arguments returns status zero if it
441          was able to add matches and non-zero otherwise. However, if
442          the -R option is given, _arguments will instead return a
443          status of 300 to indicate that $state is to be handled.
444
445          In addition to $state and $state_descr, _arguments also sets
446          the global parameters `context', `line' and `opt_args' as
447          described below, and does not reset any changes made to the
448          special parameters such as PREFIX and words.  This gives the
449          calling function the choice of resetting these parameters or
450          propagating changes in them.
451
452          A function calling _arguments with at least one action
453          containing a `->STRING' must therefore declare appropriate
454          local parameters:
455
456
457               local context state state_descr line
458               typeset -A opt_args
459
460          to prevent _arguments from altering the global environment.
461
462    {EVAL-STRING}
463          A string in braces is evaluated as shell code to generate
464          matches.  If the EVAL-STRING itself does not begin with an
465          opening parenthesis or brace it is split into separate words
466          before execution.
467
468    = ACTION
469          If the ACTION starts with `= ' (an equals sign followed by a
470          space), _arguments will insert the contents of the ARGUMENT
471          field of the current context as the new first element in the
472          words special array and increment the value of the CURRENT
473          special parameter.  This has the effect of inserting a dummy
474          word onto the completion command line while not changing the
475          point at which completion is taking place.
476
477          This is most useful with one of the specifiers that restrict
478          the words on the command line on which the ACTION is to
479          operate (the two- and three-colon forms above).  One
480          particular use is when an ACTION itself causes _arguments on
481          a restricted range; it is necessary to use this trick to
482          insert an appropriate command name into the range for the
483          second call to _arguments to be able to parse the line.
484
485     WORD...
486    WORD...
487          This covers all forms other than those above.  If the ACTION
488          starts with a space, the remaining list of words will be
489          invoked unchanged.
490
491          Otherwise it will be invoked with some extra strings placed
492          after the first word; these are to be passed down as options
493          to the compadd builtin.  They ensure that the state specified
494          by _arguments, in particular the descriptions of options and
495          arguments, is correctly passed to the completion command.
496          These additional arguments are taken from the array parameter
497          `expl'; this will be set up before executing the ACTION and
498          hence may be referred to inside it, typically in an expansion
499          of the form `$expl[@]' which preserves empty elements of the
500          array.
501
502
503     During the performance of the action the array `line' will be set
504     to the normal arguments from the command line, i.e. the words from
505     the command line after the command name excluding all options and
506     their arguments.  Options are stored in the associative array
507     `opt_args' with option names as keys and their arguments as the
508     values.  For options that have more than one argument these are
509     given as one string, separated by colons.  All colons and
510     backslashes in the original arguments are preceded with
511     backslashes.
512
513     The parameter `context' is set when returning to the calling
514     function to perform an action of the form `->STRING'.  It is set
515     to an array of elements corresponding to the elements of $state.
516     Each element is a suitable name for the argument field of the
517     context: either a string of the form `option-OPT-N' for the N'th
518     argument of the option -OPT, or a string of the form `argument-N'
519     for the N'th argument.  For `rest' arguments, that is those in the
520     list at the end not handled by position, N is the string `rest'.
521     For example, when completing the argument of the -o option, the
522     name is `option-o-1', while for the second normal (non-option-)
523     argument it is `argument-2'.
524
525     Furthermore, during the evaluation of the ACTION the context name
526     in the curcontext parameter is altered to append the same string
527     that is stored in the context parameter.
528
529     The option -C tells _arguments to modify the curcontext parameter
530     for an action of the form `->STATE'.  This is the standard
531     parameter used to keep track of the current context.  Here it (and
532     not the context array) should be made local to the calling
533     function to avoid passing back the modified value and should be
534     initialised to the current value at the start of the function:
535
536
537          local curcontext="$curcontext"
538
539     This is useful where it is not possible for multiple states to be
540     valid together.
541
542     _Grouping Options_
543
544     Options can be grouped to simplify exclusion lists. A group is
545     introduced with `+' followed by a name for the group in the
546     subsequent word. Whole groups can then be referenced in an
547     exclusion list or a group name can be used to disambiguate between
548     two forms of the same option. For example:
549
550
551          _arguments \
552              '(group2--x)-a' \
553            + group1 \
554              -m \
555              '(group2)-n' \
556            + group2 \
557              -x -y
558
559     If the name of a group is specified in the form `(NAME)' then only
560     one value from that group will ever be completed; more formally,
561     all specifications are mutually exclusive to all other
562     specifications in that group. This is useful for defining options
563     that are aliases for each other. For example:
564
565
566          _arguments \
567              -a -b \
568            + '(operation)' \
569              {-c,--compress}'[compress]' \
570              {-d,--decompress}'[decompress]' \
571              {-l,--list}'[list]'
572
573     If an option in a group appears on the command line, it is stored
574     in the associative array `opt_args' with 'GROUP-OPTION' as a key.
575     In the example above, a key `operation-c' is used if the option
576     `-c' is present on the command line.
577
578     _Specifying Multiple Sets of Arguments_
579
580     It is possible to specify multiple sets of options and arguments
581     with the sets separated by single hyphens. This differs from
582     groups in that sets are considered to be mutually exclusive of
583     each other.
584
585     Specifications before the first set and from any group are common
586     to all sets. For example:
587
588
589          _arguments \
590              -a \
591            - set1 \
592              -c \
593            - set2 \
594              -d \
595              ':arg:(x2 y2)'
596
597     This defines two sets.  When the command line contains the option
598     `-c', the `-d' option and the argument will not be considered
599     possible completions.  When it contains `-d' or an argument, the
600     option `-c' will not be considered.  However, after `-a' both sets
601     will still be considered valid.
602
603     As for groups, the name of a set may appear in exclusion lists,
604     either alone or preceding a normal option or argument
605     specification.
606
607     The completion code has to parse the command line separately for
608     each set. This can be slow so sets should only be used when
609     necessary.  A useful alternative is often an option specification
610     with rest-arguments (as in `-foo:*:...'); here the option -foo
611     swallows up all remaining arguments as described by the OPTARG
612     definitions.
613
614     _Deriving SPEC forms from the help output_
615
616     The option `--' allows _arguments to work out the names of long
617     options that support the `--help' option which is standard in many
618     GNU commands.  The command word is called with the argument
619     `--help' and the output examined for option names.  Clearly, it can
620     be dangerous to pass this to commands which may not support this
621     option as the behaviour of the command is unspecified.
622
623     In addition to options, `_arguments --' will try to deduce the
624     types of arguments available for options when the form `--OPT=VAL'
625     is valid.  It is also possible to provide hints by examining the
626     help text of the command and adding HELPSPEC of the form
627     `PATTERN:MESSAGE:ACTION'; note that other _arguments SPEC forms
628     are not used.  The PATTERN is matched against the help text for an
629     option, and if it matches the MESSAGE and ACTION are used as for
630     other argument specifiers.  The special case of `*:' means both
631     MESSAGE and ACTION are empty, which has the effect of causing
632     options having no description in the help output to be ordered in
633     listings ahead of options that have a description.
634
635     For example:
636
637
638          _arguments -- '*\*:toggle:(yes no)' \
639                        '*=FILE*:file:_files' \
640                        '*=DIR*:directory:_files -/' \
641                        '*=PATH*:directory:_files -/'
642
643     Here, `yes' and `no' will be completed as the argument of options
644     whose description ends in a star; file names will be completed for
645     options that contain the substring `=FILE' in the description; and
646     directories will be completed for options whose description
647     contains `=DIR' or `=PATH'.  The last three are in fact the
648     default and so need not be given explicitly, although it is
649     possible to override the use of these patterns.  A typical help
650     text which uses this feature is:
651
652
653            -C, --directory=DIR          change to directory DIR
654
655     so that the above specifications will cause directories to be
656     completed after `--directory', though not after `-C'.
657
658     Note also that _arguments tries to find out automatically if the
659     argument for an option is optional.  This can be specified
660     explicitly by doubling the colon before the MESSAGE.
661
662     If the PATTERN ends in `(-)', this will be removed from the
663     pattern and the ACTION will be used only directly after the `=',
664     not in the next word.  This is the behaviour of a normal
665     specification defined with the form `=-'.
666
667     By default, the command (with the option `-help') is run after
668     resetting all the locale categories (except for LC_CTYPE) to `C'.
669     If the localized help output is known to work, the option `-l' can
670     be specified after the `_arguments --' so that the command is run
671     in the current locale.
672
673     The `_arguments --' can be followed by the option `-i PATTERNS' to
674     give patterns for options which are not to be completed.  The
675     patterns can be given as the name of an array parameter or as a
676     literal list in parentheses.  For example,
677
678
679          _arguments -- -i \
680              "(--(en|dis)able-FEATURE*)"
681
682     will cause completion to ignore the options `--enable-FEATURE' and
683     `--disable-FEATURE' (this example is useful with GNU configure).
684
685     The `_arguments --' form can also be followed by the option `-s
686     PAIR' to describe option aliases.  The PAIR consists of a list of
687     alternating patterns and corresponding replacements, enclosed in
688     parens and quoted so that it forms a single argument word in the
689     _arguments call.
690
691     For example, some configure-script help output describes options
692     only as `--enable-foo', but the script also accepts the negated
693     form `--disable-foo'.  To allow completion of the second form:
694
695
696          _arguments -- -s "((#s)--enable- --disable-)"
697
698     _Miscellaneous notes_
699
700     Finally, note that _arguments generally expects to be the primary
701     function handling any completion for which it is used.  It may
702     have side effects which change the treatment of any matches added
703     by other functions called after it.  To combine _arguments with
704     other functions, those functions should be called either before
705     _arguments, as an ACTION within a SPEC, or in handlers for
706     `->STATE' actions.
707
708     Here is a more general example of the use of _arguments:
709
710
711          _arguments '-l+:left border:' \
712                     '-format:paper size:(letter A4)' \
713                     '*-copy:output file:_files::resolution:(300 600)' \
714                     ':postscript file:_files -g \*.\(ps\|eps\)' \
715                     '*:page number:'
716
717     This describes three options: `-l', `-format', and `-copy'.  The
718     first takes one argument described as `LEFT BORDER' for which no
719     completion will be offered because of the empty action.  Its
720     argument may come directly after the `-l' or it may be given as
721     the next word on the line.
722
723     The `-format' option takes one argument in the next word,
724     described as `PAPER SIZE' for which only the strings `letter' and
725     `A4' will be completed.
726
727     The `-copy' option may appear more than once on the command line
728     and takes two arguments.  The first is mandatory and will be
729     completed as a filename.  The second is optional (because of the
730     second colon before the description `RESOLUTION') and will be
731     completed from the strings `300' and `600'.
732
733     The last two descriptions say what should be completed as
734     arguments.  The first describes the first argument as a
735     `POSTSCRIPT FILE' and makes files ending in `ps' or `eps' be
736     completed.  The last description gives all other arguments the
737     description `PAGE NUMBERS' but does not offer completions.
738
739_cache_invalid CACHE_IDENTIFIER
740     This function returns status zero if the completions cache
741     corresponding to the given cache identifier needs rebuilding.  It
742     determines this by looking up the cache-policy style for the
743     current context.  This should provide a function name which is run
744     with the full path to the relevant cache file as the only argument.
745
746     Example:
747
748
749          _example_caching_policy () {
750              # rebuild if cache is more than a week old
751              local -a oldp
752              oldp=( "$1"(Nm+7) )
753              (( $#oldp ))
754          }
755
756_call_function RETURN NAME [ ARG ... ]
757     If a function NAME exists, it is called with the arguments ARGs.
758     The RETURN argument gives the name of a parameter in which the
759     return status from the function NAME should be stored; if RETURN
760     is empty or a single hyphen it is ignored.
761
762     The return status of _call_function itself is zero if the function
763     NAME exists and was called and non-zero otherwise.
764
765_call_program [ -l ] [ -p ] TAG STRING ...
766     This function provides a mechanism for the user to override the
767     use of an external command.  It looks up the command style with
768     the supplied TAG.  If the style is set, its value is used as the
769     command to execute.  The STRINGs from the call to _call_program,
770     or from the style if set, are concatenated with spaces between
771     them and the resulting string is evaluated.  The return status is
772     the return status of the command called.
773
774     By default, the command is run in an environment where all the
775     locale categories (except for LC_CTYPE) are reset to `C' by
776     calling the utility function _comp_locale (see below). If the
777     option `-l' is given, the command is run with the current locale.
778
779     If the option `-p' is supplied it indicates that the command
780     output is influenced by the permissions it is run with. If the
781     gain-privileges style is set to true, _call_program will make use
782     of commands such as sudo, if present on the command-line, to match
783     the permissions to whatever the final command is likely to run
784     under. When looking up the gain-privileges and command styles, the
785     command component of the zstyle context will end with a slash
786     (`/') followed by the command that would be used to gain
787     privileges.
788
789_combination [ -s PATTERN ] TAG STYLE SPEC ... FIELD OPTS ...
790     This function is used to complete combinations of values,  for
791     example pairs of hostnames and usernames.  The STYLE argument
792     gives the style which defines the pairs; it is looked up in a
793     context with the TAG specified.
794
795     The style name consists of field names separated by hyphens, for
796     example `users-hosts-ports'.  For each field for a value is
797     already known, a SPEC of the form `FIELD=PATTERN' is given.  For
798     example, if the command line so far specifies a user `pws', the
799     argument `users=pws' should appear.
800
801     The next argument with no equals sign is taken as the name of the
802     field for which completions should be generated (presumably not
803     one of the FIELDs for which the value is known).
804
805     The matches generated will be taken from the value of the style.
806     These should contain the possible values for the combinations in
807     the appropriate order (users, hosts, ports in the example above).
808     The values for the different fields are separated by colons.  This
809     can be altered with the option -s to _combination which specifies a
810     pattern.  Typically this is a character class, as for example `-s
811     "[:@]"' in the case of the users-hosts style.    Each
812     `FIELD=PATTERN' specification restricts the completions which
813     apply to elements of the style with appropriately matching fields.
814
815     If no style with the given name is defined for the given tag, or
816     if none of the strings in style's value match, but a function name
817     of the required field preceded by an underscore is defined, that
818     function will be called to generate the matches.  For example, if
819     there is no `users-hosts-ports' or no matching hostname when a
820     host is required, the function `_hosts' will automatically be
821     called.
822
823     If the same name is used for more than one field, in both the
824     `FIELD=PATTERN' and the argument that gives the name of the field
825     to be completed, the number of the field (starting with one) may
826     be given after the fieldname, separated from it by a colon.
827
828     All arguments after the required field name are passed to compadd
829     when generating matches from the style value, or to the functions
830     for the fields if they are called.
831
832_command_names [ -e | - ]
833     This function completes words that are valid at command position:
834     names of aliases, builtins, hashed commands, functions, and so on.
835     With the -e flag, only hashed commands are completed.  The - flag
836     is ignored.
837
838_comp_locale
839     This function resets all the locale categories other than LC_CTYPE
840     to `C' so that the output from external commands can be easily
841     analyzed by the completion system. LC_CTYPE retains the current
842     value (taking LC_ALL and LANG into account), ensuring that
843     non-ASCII characters in file names are still handled properly.
844
845     This function should normally be run only in a subshell, because
846     the new locale is exported to the environment. Typical usage would
847     be `$(_comp_locale; COMMAND ...)'.
848
849_completers [ -p ]
850     This function completes names of completers.
851
852
853    -p
854          Include the leading underscore (`_') in the matches.
855
856
857_describe [-12JVx] [ -oO | -t TAG ] DESCR NAME1 [ NAME2 ] [ OPT ... ]
858          [ -- NAME1 [ NAME2 ] [ OPT ... ] ... ]
859     This function associates completions with descriptions.  Multiple
860     groups separated by -- can be supplied, potentially with different
861     completion options OPTs.
862
863     The DESCR is taken as a string to display above the matches if the
864     format style for the descriptions tag is set.  This is followed by
865     one or two names of arrays followed by options to pass to compadd.
866     The array NAME1 contains the possible completions with their
867     descriptions in the form `COMPLETION:DESCRIPTION'.  Any literal
868     colons in COMPLETION must be quoted with a backslash.  If a NAME2
869     is given, it should have the same number of elements as NAME1; in
870     this case the corresponding elements are added as possible
871     completions instead of the COMPLETION strings from NAME1.  The
872     completion list will retain the descriptions from NAME1.  Finally,
873     a set of completion options can appear.
874
875     If the option `-o' appears before the first argument, the matches
876     added will be treated as names of command options (N.B. not shell
877     options), typically following a `-', `--' or `+' on the command
878     line.  In this case _describe uses the prefix-hidden,
879     prefix-needed and verbose styles to find out if the strings should
880     be added as completions and if the descriptions should be shown.
881     Without the `-o' option, only the verbose style is used to decide
882     how descriptions are shown.  If `-O' is used instead of `-o',
883     command options are completed as above but _describe will not
884     handle the prefix-needed style.
885
886     With the -t option a TAG can be specified.  The default is
887     `values' or, if the -o option is given, `options'.
888
889     The options -1, -2, -J, -V, -x are passed to _next_label.
890
891     If selected by the list-grouped style, strings with the same
892     description will appear together in the list.
893
894     _describe uses the _all_labels function to generate the matches, so
895     it does not need to appear inside a loop over tag labels.
896
897_description [ -x ] [ -12VJ ] TAG NAME DESCR [ SPEC ... ]
898     This function is not to be confused with the previous one; it is
899     used as a helper function for creating options to compadd.  It is
900     buried inside many of the higher level completion functions and so
901     often does not need to be called directly.
902
903     The styles listed below are tested in the current context using the
904     given TAG.  The resulting options for compadd are put into the
905     array named NAME (this is traditionally `expl', but this
906     convention is not enforced).  The description for the
907     corresponding set of matches is passed to the function in DESCR.
908
909     The styles tested are: format, hidden, matcher, ignore-line,
910     ignored-patterns, group-name and sort.  The format style is first
911     tested for the given TAG and then for the descriptions tag if no
912     value was found, while the remainder are only tested for the tag
913     given as the first argument.  The function also calls _setup which
914     tests some more styles.
915
916     The string returned by the format style (if any) will be modified
917     so that the sequence `%d' is replaced by the DESCR given as the
918     third argument without any leading or trailing white space.  If,
919     after removing the white space, the DESCR is the empty string, the
920     format style will not be used and the options put into the NAME
921     array will not contain an explanation string to be displayed above
922     the matches.
923
924     If _description is called with more than three arguments, the
925     additional SPECs should be of the form `CHAR:STR'.  These supply
926     escape sequence replacements for the format style: every
927     appearance of `%CHAR' will be replaced by STRING.
928
929     If the -x option is given, the description will be passed to
930     compadd using the -x option instead of the default -X.  This means
931     that the description will be displayed even if there are no
932     corresponding matches.
933
934     The options placed in the array NAME take account of the
935     group-name style, so matches are placed in a separate group where
936     necessary.  The group normally has its elements sorted (by passing
937     the option -J to compadd), but if an option starting with `-V',
938     `-J', `-1', or `-2' is passed to _description, that option will be
939     included in the array.  Hence it is possible for the completion
940     group to be unsorted by giving the option `-V', `-1V', or `-2V'.
941
942     In most cases, the function will be used like this:
943
944
945          local expl
946          _description files expl file
947          compadd "$expl[@]" - "$files[@]"
948
949     Note the use of the parameter expl, the hyphen, and the list of
950     matches.  Almost all calls to compadd within the completion system
951     use a similar format; this ensures that user-specified styles are
952     correctly passed down to the builtins which implement the
953     internals of completion.
954
955_dir_list [ -s SEP ] [ -S ]
956     Complete a list of directory names separated by colons (the same
957     format as $PATH).
958
959
960    -s SEP
961          Use SEP as separator between items.  SEP defaults to a colon
962          (`:').
963
964    -S
965          Add SEP instead of slash (`/') as an autoremoveable suffix.
966
967
968_dispatch CONTEXT STRING ...
969     This sets the current context to CONTEXT and looks for completion
970     functions to handle this context by hunting through the list of
971     command names or special contexts (as described above for compdef)
972     given as STRINGs.  The first completion function to be defined for
973     one of the contexts in the list is used to generate matches.
974     Typically, the last STRING is -default- to cause the function for
975     default completion to be used as a fallback.
976
977     The function sets the parameter $service to the STRING being
978     tried, and sets the CONTEXT/COMMAND field (the fourth) of the
979     $curcontext parameter to the CONTEXT given as the first argument.
980
981_email_addresses [ -c ] [ -n PLUGIN ]
982     Complete email addresses.  Addresses are provided by plugins.
983
984
985    -c
986          Complete bare localhost@domain.tld addresses, without a name
987          part or a comment.  Without this option, RFC822 `FIRSTNAME
988          LASTNAME <ADDRESS>' strings are completed.
989
990    -n PLUGIN
991          Complete aliases from PLUGIN.
992
993
994     The following plugins are available by default: _email-ldap (see
995     the filter style), _email-local (completes USER@HOSTNAME Unix
996     addresses), _email-mail (completes aliases from ~/.mailrc),
997     _email-mush, _email-mutt, and _email-pine.
998
999     Addresses from the _email-FOO plugin are added under the tag
1000     `email-FOO'.
1001
1002     _Writing plugins_
1003
1004     Plugins are written as separate functions with names starting with
1005     `_email-'.  They are invoked with the -c option and compadd
1006     options.  They should either do their own completion or set the
1007     $reply array to a list of `ALIAS:ADDRESS' elements and return 300.
1008     New plugins will be picked up and run automatically.
1009
1010_files
1011     The function _files is a wrapper around _path_files. It supports
1012     all of the same functionality, with some enhancements -- notably,
1013     it respects the list-dirs-first style, and it allows users to
1014     override the behaviour of the -g and -/ options with the
1015     file-patterns style. _files should therefore be preferred over
1016     _path_files in most cases.
1017
1018     This function accepts the full set of options allowed by
1019     _path_files, described below.
1020
1021_gnu_generic
1022     This function is a simple wrapper around the _arguments function
1023     described above.  It can be used to determine automatically the
1024     long options understood by commands that produce a list when
1025     passed the option `--help'.  It is intended to be used as a
1026     top-level completion function in its own right.  For example, to
1027     enable option completion for the commands foo and bar, use
1028
1029
1030          compdef _gnu_generic foo bar
1031
1032     after the call to compinit.
1033
1034     The completion system as supplied is conservative in its use of
1035     this function, since it is important to be sure the command
1036     understands the option `--help'.
1037
1038_guard [ OPTIONS ] PATTERN DESCR
1039     This function displays DESCR if PATTERN matches the string to be
1040     completed.  It is intended to be used in the ACTION for the
1041     specifications passed to _arguments and similar functions.
1042
1043     The return status is zero if the message was displayed and the
1044     word to complete is not empty, and non-zero otherwise.
1045
1046     The PATTERN may be preceded by any of the options understood by
1047     compadd that are passed down from _description, namely -M, -J, -V,
1048     -1, -2, -n, -F and -X.  All of these options will be ignored.
1049     This fits in conveniently with the argument-passing conventions of
1050     actions for _arguments.
1051
1052     As an example, consider a command taking the options -n and -none,
1053     where -n must be followed by a numeric value in the same word.  By
1054     using:
1055
1056
1057          _arguments '-n-: :_guard "[0-9]#" "numeric value"' '-none'
1058
1059     _arguments can be made to both display the message `numeric value'
1060     and complete options after `-n<TAB>'.  If the `-n' is already
1061     followed by one or more digits (the pattern passed to _guard) only
1062     the message will be displayed; if the `-n' is followed by another
1063     character, only options are completed.
1064
1065_message [ -r12 ] [ -VJ GROUP ] DESCR
1066_message -e [ TAG ] DESCR
1067     The DESCR is used in the same way as the third argument to the
1068     _description function, except that the resulting string will
1069     always be shown whether or not matches were generated.  This is
1070     useful for displaying a help message in places where no
1071     completions can be generated.
1072
1073     The format style is examined with the messages tag to find a
1074     message; the usual tag, descriptions, is used only if the style is
1075     not set with the former.
1076
1077     If the -r option is given, no style is used; the DESCR is taken
1078     literally as the string to display.  This is most useful when the
1079     DESCR comes from a pre-processed argument list which already
1080     contains an expanded description.  Note that this option does not
1081     disable the `%'-sequence parsing done by compadd.
1082
1083     The -12VJ options and the GROUP are passed to compadd and hence
1084     determine the group the message string is added to.
1085
1086     The second -e form gives a description for completions with the tag
1087     TAG to be shown even if there are no matches for that tag.  This
1088     form is called by _arguments in the event that there is no action
1089     for an option specification.  The tag can be omitted and if so the
1090     tag is taken from the parameter $curtag; this is maintained by the
1091     completion system and so is usually correct.  Note that if there
1092     are no matches at the time this function is called,
1093     compstate[insert] is cleared, so additional matches generated
1094     later are not inserted on the command line.
1095
1096_multi_parts [ -i ] SEP ARRAY
1097     The argument SEP is a separator character.  The ARRAY may be
1098     either the name of an array parameter or a literal array in the
1099     form `(foo bar)', a parenthesised list of words separated by
1100     whitespace.  The possible completions are the strings from the
1101     array.  However, each chunk delimited by SEP will be completed
1102     separately.  For example, the _tar function uses `_multi_parts /
1103     PATHARRAY' to complete partial file paths from the given array of
1104     complete file paths.
1105
1106     The -i option causes _multi_parts to insert a unique match even if
1107     that requires multiple separators to be inserted.  This is not
1108     usually the expected behaviour with filenames, but certain other
1109     types of completion, for example those with a fixed set of
1110     possibilities, may be more suited to this form.
1111
1112     Like other utility functions, this function accepts the `-V',
1113     `-J', `-1', `-2', `-n', `-f', `-X', `-M', `-P', `-S', `-r', `-R',
1114     and `-q' options and passes them to the compadd builtin.
1115
1116_next_label [ -x ] [ -12VJ ] TAG NAME DESCR [ OPTION ... ]
1117     This function is used to implement the loop over different tag
1118     labels for a particular tag as described above for the tag-order
1119     style.  On each call it checks to see if there are any more tag
1120     labels; if there is it returns status zero, otherwise non-zero.
1121     As this function requires a current tag to be set, it must always
1122     follow a call to _tags or _requested.
1123
1124     The -x12VJ options and the first three arguments are passed to the
1125     _description function.  Where appropriate the TAG will be replaced
1126     by a tag label in this call.  Any description given in the
1127     tag-order style is preferred to the DESCR passed to _next_label.
1128
1129     The OPTIONs given after the DESCR are set in the parameter given
1130     by NAME, and hence are to be passed to compadd or whatever
1131     function is called to add the matches.
1132
1133     Here is a typical use of this function for the tag foo.  The call
1134     to _requested determines if tag foo is required at all; the loop
1135     over _next_label handles any labels defined for the tag in the
1136     tag-order style.
1137
1138
1139          local expl ret=1
1140          ...
1141          if _requested foo; then
1142            ...
1143            while _next_label foo expl '...'; do
1144              compadd "$expl[@]" ... && ret=0
1145            done
1146            ...
1147          fi
1148          return ret
1149
1150_normal [ -P | -p PRECOMMAND ]
1151     This is the standard function called to handle completion outside
1152     any special -CONTEXT-.  It is called both to complete the command
1153     word and also the arguments for a command.  In the second case,
1154     _normal looks for a special completion for that command, and if
1155     there is none it uses the completion for the -default- context.
1156
1157     A second use is to reexamine the command line specified by the
1158     $words array and the $CURRENT parameter after those have been
1159     modified.  For example, the function _precommand, which completes
1160     after precommand specifiers such as nohup, removes the first word
1161     from the words array, decrements the CURRENT parameter, then calls
1162     `_normal -p $service'.  The effect is that `nohup CMD ...' is
1163     treated in the same way as `CMD ...'.
1164
1165
1166    -P
1167          Reset the list of precommands. This option should be used if
1168          completing a command line which allows internal commands
1169          (e.g. builtins and functions) regardless of prior precommands
1170          (e.g. `zsh -c').
1171
1172    -p PRECOMMAND
1173          Append PRECOMMAND to the list of precommands. This option
1174          should be used in nearly all cases in which -P is not
1175          applicable.
1176
1177
1178     If the command name matches one of the patterns given by one of the
1179     options -p or -P to compdef, the corresponding completion function
1180     is called and then the parameter _compskip is checked.  If it is
1181     set completion is terminated at that point even if no matches have
1182     been found.  This is the same effect as in the -first- context.
1183
1184_options
1185     This can be used to complete the names of shell options.  It
1186     provides a matcher specification that ignores a leading `no',
1187     ignores underscores and allows upper-case letters to match their
1188     lower-case counterparts (for example, `glob', `noglob', `NO_GLOB'
1189     are all completed).  Any arguments are propagated to the compadd
1190     builtin.
1191
1192_options_set and _options_unset
1193     These functions complete only set or unset options, with the same
1194     matching specification used in the _options function.
1195
1196     Note that you need to uncomment a few lines in the _main_complete
1197     function for these functions to work properly.  The lines in
1198     question are used to store the option settings in effect before
1199     the completion widget locally sets the options it needs.  Hence
1200     these functions are not generally used by the completion system.
1201
1202_parameters
1203     This is used to complete the names of shell parameters.
1204
1205     The option `-g PATTERN' limits the completion to parameters whose
1206     type matches the PATTERN.  The type of a parameter is that shown
1207     by `print ${(t)PARAM}', hence judicious use of `*' in PATTERN is
1208     probably necessary.
1209
1210     All other arguments are passed to the compadd builtin.
1211
1212_path_files
1213     This function is used throughout the completion system to complete
1214     filenames.  It allows completion of partial paths.  For example,
1215     the string `/u/i/s/sig' may be completed to
1216     `/usr/include/sys/signal.h'.
1217
1218     The options accepted by both _path_files and _files are:
1219
1220
1221    -f
1222          Complete all filenames.  This is the default.
1223
1224    -/
1225          Specifies that only directories should be completed.
1226
1227    -g PATTERN
1228          Specifies that only files matching the PATTERN should be
1229          completed.
1230
1231    -W PATHS
1232          Specifies path prefixes that are to be prepended to the
1233          string from the command line to generate the filenames but
1234          that should not be inserted as completions nor shown in
1235          completion listings.  Here, PATHS may be the name of an array
1236          parameter, a literal list of paths enclosed in parentheses or
1237          an absolute pathname.
1238
1239    -F IGNORED-FILES
1240          This behaves as for the corresponding option to the compadd
1241          builtin.  It gives direct control over which filenames should
1242          be ignored.  If the option is not present, the
1243          ignored-patterns style is used.
1244
1245
1246     Both _path_files and _files also accept the following options
1247     which are passed to compadd: `-J', `-V', `-1', `-2', `-n', `-X',
1248     `-M', `-P', `-S', `-q', `-r', and `-R'.
1249
1250     Finally, the _path_files function  uses the styles expand,
1251     ambiguous, special-dirs, list-suffixes and file-sort described
1252     above.
1253
1254_pick_variant [ -b BUILTIN-LABEL ] [ -c COMMAND ] [ -r NAME ]
1255              LABEL=PATTERN ... LABEL [ ARG ... ]
1256     This function is used to resolve situations where a single command
1257     name requires more than one type of handling, either because it
1258     has more than one variant or because there is a name clash between
1259     two different commands.
1260
1261     The command to run is taken from the first element of the array
1262     words unless this is overridden by the option -c.  This command is
1263     run and its output is compared with a series of patterns.
1264     Arguments to be passed to the command can be specified at the end
1265     after all the other arguments.  The patterns to try in order are
1266     given by the arguments LABEL=PATTERN; if the output of `COMMAND ARG
1267     ...' contains PATTERN, then LABEL is selected as the label for the
1268     command variant.  If none of the patterns match, the final command
1269     label is selected and status 1 is returned.
1270
1271     If the `-b BUILTIN-LABEL' is given, the command is tested to see
1272     if it is provided as a shell builtin, possibly autoloaded; if so,
1273     the label BUILTIN-LABEL is selected as the label for the variant.
1274
1275     If the `-r NAME' is given, the LABEL picked is stored in the
1276     parameter named NAME.
1277
1278     The results are also cached in the _cmd_variant associative array
1279     indexed by the name of the command run.
1280
1281_regex_arguments NAME SPEC ...
1282     This function generates a completion function NAME which matches
1283     the specifications SPECs, a set of regular expressions as
1284     described below.  After running _regex_arguments, the function
1285     NAME should be called as a normal completion function.  The
1286     pattern to be matched is given by the contents of the words array
1287     up to the current cursor position joined together with null
1288     characters; no quotation is applied.
1289
1290     The arguments are grouped as sets of alternatives separated by `|',
1291     which are tried one after the other until one matches.  Each
1292     alternative consists of a one or more specifications which are
1293     tried left to right, with each pattern matched being stripped in
1294     turn from the command line being tested, until all of the group
1295     succeeds or until one fails; in the latter case, the next
1296     alternative is tried.  This structure can be repeated to arbitrary
1297     depth by using parentheses; matching proceeds from inside to
1298     outside.
1299
1300     A special procedure is applied if no test succeeds but the
1301     remaining command line string contains no null character (implying
1302     the remaining word is the one for which completions are to be
1303     generated).  The completion target is restricted to the remaining
1304     word and any ACTIONs for the corresponding patterns are executed.
1305     In this case, nothing is stripped from the command line string.
1306     The order of evaluation of the ACTIONs can be determined by the
1307     tag-order style; the various formats supported by _alternative can
1308     be used in ACTION.  The DESCR is used for setting up the array
1309     parameter expl.
1310
1311     Specification arguments take one of following forms, in which
1312     metacharacters such as `(', `)', `#' and `|' should be quoted.
1313
1314
1315    /PATTERN/ [%LOOKAHEAD%] [-GUARD] [:TAG:DESCR:ACTION]
1316          This is a single primitive component.  The function tests
1317          whether the combined pattern `(#b)((#B)PATTERN)LOOKAHEAD*'
1318          matches the command line string.  If so, `GUARD' is evaluated
1319          and its return status is examined to determine if the test
1320          has succeeded.  The PATTERN string `[]' is guaranteed never
1321          to match.  The LOOKAHEAD is not stripped from the command
1322          line before the next pattern is examined.
1323
1324          The argument starting with : is used in the same manner as an
1325          argument to _alternative.
1326
1327          A component is used as follows: PATTERN is tested to see if
1328          the component already exists on the command line.  If it
1329          does, any following specifications are examined to find
1330          something to complete.  If a component is reached but no such
1331          pattern exists yet on the command line, the string containing
1332          the ACTION is used to generate matches to insert at that
1333          point.
1334
1335    /PATTERN/+ [%LOOKAHEAD%] [-GUARD] [:TAG:DESCR:ACTION]
1336          This is similar to `/PATTERN/ ...' but the left part of the
1337          command line string (i.e. the part already matched by
1338          previous patterns) is also considered part of the completion
1339          target.
1340
1341    /PATTERN/- [%LOOKAHEAD%] [-GUARD] [:TAG:DESCR:ACTION]
1342          This is similar to `/PATTERN/ ...' but the ACTIONs of the
1343          current and previously matched patterns are ignored even if
1344          the following `PATTERN' matches the empty string.
1345
1346    ( SPEC )
1347          Parentheses may be used to groups SPECs; note each parenthesis
1348          is a single argument to _regex_arguments.
1349
1350    SPEC #
1351          This allows any number of repetitions of SPEC.
1352
1353    SPEC SPEC
1354          The two SPECs are to be matched one after the other as
1355          described above.
1356
1357    SPEC | SPEC
1358          Either of the two SPECs can be matched.
1359
1360
1361     The function _regex_words can be used as a helper function to
1362     generate matches for a set of alternative words possibly with
1363     their own arguments as a command line argument.
1364
1365     Examples:
1366
1367
1368          _regex_arguments _tst /$'[^\0]#\0'/ \
1369              /$'[^\0]#\0'/ :'compadd aaa'
1370
1371     This generates a function _tst that completes aaa as its only
1372     argument.  The TAG and DESCRIPTION for the action have been
1373     omitted for brevity (this works but is not recommended in normal
1374     use).  The first component matches the command word, which is
1375     arbitrary; the second matches  any argument.  As the argument is
1376     also arbitrary, any following component would not depend on aaa
1377     being present.
1378
1379
1380          _regex_arguments _tst /$'[^\0]#\0'/ \
1381              /$'aaa\0'/ :'compadd aaa'
1382
1383     This is a more typical use; it is similar, but any following
1384     patterns would only match if aaa was present as the first argument.
1385
1386
1387          _regex_arguments _tst /$'[^\0]#\0'/ \( \
1388              /$'aaa\0'/ :'compadd aaa' \
1389              /$'bbb\0'/ :'compadd bbb' \) \#
1390
1391     In this example, an indefinite number of command arguments may be
1392     completed.  Odd arguments are completed as aaa and even arguments
1393     as bbb.  Completion fails unless the set of aaa and bbb arguments
1394     before the current one is matched correctly.
1395
1396
1397          _regex_arguments _tst /$'[^\0]#\0'/ \
1398              \( /$'aaa\0'/ :'compadd aaa' \| \
1399              /$'bbb\0'/ :'compadd bbb' \) \#
1400
1401     This is similar, but either aaa or bbb may be completed for any
1402     argument.  In this case _regex_words could be used to generate a
1403     suitable expression for the arguments.
1404
1405
1406
1407_regex_words TAG DESCRIPTION SPEC ...
1408     This function can be used to generate arguments for the
1409     _regex_arguments command which may be inserted at any point where
1410     a set of rules is expected.  The TAG and DESCRIPTION give a
1411     standard tag and description pertaining to the current context.
1412     Each SPEC contains two or three arguments separated by a colon:
1413     note that there is no leading colon in this case.
1414
1415     Each SPEC gives one of a set of words that may be completed at
1416     this point, together with arguments.  It is thus roughly
1417     equivalent to the _arguments function when used in normal
1418     (non-regex) completion.
1419
1420     The part of the SPEC before the first colon is the word to be
1421     completed.  This may contain a *; the entire word, before and after
1422     the * is completed, but only the text before the * is required for
1423     the context to be matched, so that further arguments may be
1424     completed after the abbreviated form.
1425
1426     The second part of SPEC is a description for the word being
1427     completed.
1428
1429     The optional third part of the SPEC describes how words following
1430     the one being completed are themselves to be completed.  It will be
1431     evaluated in order to avoid problems with quoting.  This means that
1432     typically it contains a reference to an array containing previously
1433     generated regex arguments.
1434
1435     The option -t TERM specifies a terminator for the word instead of
1436     the usual space.  This is handled as an auto-removable suffix in
1437     the manner of the option -s SEP to _values.
1438
1439     The result of the processing by _regex_words is placed in the array
1440     reply, which should be made local to the calling function.  If the
1441     set of words and arguments may be matched repeatedly, a # should
1442     be appended to the generated array at that point.
1443
1444     For example:
1445
1446
1447          local -a reply
1448          _regex_words mydb-commands 'mydb commands' \
1449            'add:add an entry to mydb:$mydb_add_cmds' \
1450            'show:show entries in mydb'
1451          _regex_arguments _mydb "$reply[@]"
1452          _mydb "$@"
1453
1454     This shows a completion function for a command mydb which takes
1455     two command arguments, add and show.  show takes no arguments,
1456     while the arguments for add have already been prepared in an array
1457     mydb_add_cmds, quite possibly by a previous call to _regex_words.
1458
1459_requested [ -x ] [ -12VJ ] TAG [ NAME DESCR [ COMMAND [ ARG ... ] ]
1460     This function is called to decide whether a tag already registered
1461     by a call to _tags (see below) has been requested by the user and
1462     hence completion should be performed for it.  It returns status
1463     zero if the tag is requested and non-zero otherwise.  The function
1464     is typically used as part of a loop over different tags as follows:
1465
1466
1467          _tags foo bar baz
1468          while _tags; do
1469            if _requested foo; then
1470              ... # perform completion for foo
1471            fi
1472            ... # test the tags bar and baz in the same way
1473            ... # exit loop if matches were generated
1474          done
1475
1476     Note that the test for whether matches were generated is not
1477     performed until the end of the _tags loop.  This is so that the
1478     user can set the tag-order style to specify a set of tags to be
1479     completed at the same time.
1480
1481     If NAME and DESCR are given, _requested calls the _description
1482     function with these arguments together with the options passed to
1483     _requested.
1484
1485     If COMMAND is given, the _all_labels function will be called
1486     immediately with the same arguments.  In simple cases this makes it
1487     possible to perform the test for the tag and the matching in one
1488     go.  For example:
1489
1490
1491          local expl ret=1
1492          _tags foo bar baz
1493          while _tags; do
1494            _requested foo expl 'description' \
1495                compadd foobar foobaz && ret=0
1496            ...
1497            (( ret )) || break
1498          done
1499
1500     If the COMMAND is not compadd, it must nevertheless be prepared to
1501     handle the same options.
1502
1503_retrieve_cache CACHE_IDENTIFIER
1504     This function retrieves completion information from the file given
1505     by CACHE_IDENTIFIER, stored in a directory specified by the
1506     cache-path style which defaults to ~/.zcompcache.  The return
1507     status is zero if retrieval was successful.  It will only attempt
1508     retrieval if the use-cache style is set, so you can call this
1509     function without worrying about whether the user wanted to use the
1510     caching layer.
1511
1512     See _store_cache below for more details.
1513
1514_sep_parts
1515     This function is passed alternating arrays and separators as
1516     arguments.  The arrays specify completions for parts of strings to
1517     be separated by the separators.  The arrays may be the names of
1518     array parameters or a quoted list of words in parentheses.  For
1519     example, with the array `hosts=(ftp news)' the call `_sep_parts
1520     '(foo bar)' @ hosts' will complete the string  `f' to `foo' and
1521     the string `b@n' to `bar@news'.
1522
1523     This function accepts the compadd options `-V', `-J', `-1', `-2',
1524     `-n', `-X', `-M', `-P', `-S', `-r', `-R', and `-q' and passes them
1525     on to the compadd builtin used to add the matches.
1526
1527_sequence [ -s SEP ] [ -n MAX ] [ -d ] FUNCTION [ - ] ...
1528     This function is a wrapper to other functions for completing items
1529     in a separated list. The same function is used to complete each
1530     item in the list. The separator is specified with the -s option.
1531     If -s is omitted it will use `,'. Duplicate values are not matched
1532     unless -d is specified. If there is a fixed or maximum number of
1533     items in the list, this can be specified with the -n option.
1534
1535     Common compadd options are passed on to the function. It is
1536     possible to use compadd directly with _sequence, though _values may
1537     be more appropriate in this situation.
1538
1539_setup TAG [ GROUP ]
1540     This function sets up the special parameters used by the
1541     completion system appropriately for the TAG given as the first
1542     argument.  It uses the styles list-colors, list-packed,
1543     list-rows-first, last-prompt, accept-exact, menu and force-list.
1544
1545     The optional GROUP supplies the name of the group in which the
1546     matches will be placed.  If it is not given, the TAG is used as
1547     the group name.
1548
1549     This function is called automatically from _description and hence
1550     is not normally called explicitly.
1551
1552_store_cache CACHE_IDENTIFIER PARAM ...
1553     This function, together with _retrieve_cache and _cache_invalid,
1554     implements a caching layer which can be used in any completion
1555     function.  Data obtained by costly operations are stored in
1556     parameters; this function then dumps the values of those
1557     parameters to a file.  The data can then be retrieved quickly from
1558     that file via _retrieve_cache, even in different instances of the
1559     shell.
1560
1561     The CACHE_IDENTIFIER specifies the file which the data should be
1562     dumped to.  The file is stored in a directory specified by the
1563     cache-path style which defaults to ~/.zcompcache.  The remaining
1564     PARAMs arguments are the parameters to dump to the file.
1565
1566     The return status is zero if storage was successful.  The function
1567     will only attempt storage if the use-cache style is set, so you can
1568     call this function without worrying about whether the user wanted
1569     to use the caching layer.
1570
1571     The completion function may avoid calling _retrieve_cache when it
1572     already has the completion data available as parameters.  However,
1573     in that case it should call _cache_invalid to check whether the
1574     data in the parameters and in the cache are still valid.
1575
1576     See the _perl_modules completion function for a simple example of
1577     the usage of the caching layer.
1578
1579_tags [ [ -C NAME ] TAG ... ]
1580     If called with arguments, these are taken to be the names of tags
1581     valid for completions in the current context.  These tags are
1582     stored internally and sorted by using the tag-order style.
1583
1584     Next, _tags is called repeatedly without arguments from the same
1585     completion function.  This successively selects the first, second,
1586     etc. set of tags requested by the user.  The return status is zero
1587     if at least one of the tags is requested and non-zero otherwise.
1588     To test if a particular tag is to be tried, the _requested
1589     function should be called (see above).
1590
1591     If `-C NAME' is given, NAME is temporarily stored in the ARGUMENT
1592     field (the fifth) of the context in the curcontext parameter
1593     during the call to _tags; the field is restored on exit.  This
1594     allows _tags to use a more specific context without having to
1595     change and reset the curcontext parameter (which has the same
1596     effect).
1597
1598_tilde_files
1599     Like _files, but resolve leading tildes according to the rules of
1600     filename expansion, so the suggested completions don't start with
1601     a `~' even if the filename on the command-line does.
1602
1603_values [ -O NAME ] [ -s SEP ] [ -S SEP ] [ -wC ] DESC SPEC ...
1604     This is used to complete arbitrary keywords (values) and their
1605     arguments, or lists of such combinations.
1606
1607     If the first argument is the option `-O NAME', it will be used in
1608     the same way as by the _arguments function.  In other words, the
1609     elements of the NAME array will be passed to compadd when
1610     executing an action.
1611
1612     If the first argument (or the first argument after `-O NAME') is
1613     `-s', the next argument is used as the character that separates
1614     multiple values.  This character is automatically added after each
1615     value in an auto-removable fashion (see below); all values
1616     completed by `_values -s' appear in the same word on the command
1617     line, unlike completion using _arguments.  If this option is not
1618     present, only a single value will be completed per word.
1619
1620     Normally, _values will only use the current word to determine
1621     which values are already present on the command line and hence are
1622     not to be completed again.  If the -w option is given, other
1623     arguments are examined as well.
1624
1625     The first non-option argument, DESC, is used as a string to print
1626     as a description before listing the values.
1627
1628     All other arguments describe the possible values and their
1629     arguments in the same format used for the description of options by
1630     the _arguments function (see above).  The only differences are that
1631     no minus or plus sign is required at the beginning, values can
1632     have only one argument, and the forms of action beginning with an
1633     equal sign are not supported.
1634
1635     The character separating a value from its argument can be set
1636     using the option -S (like -s, followed by the character to use as
1637     the separator in the next argument).  By default the equals sign
1638     will be used as the separator between values and arguments.
1639
1640     Example:
1641
1642
1643          _values -s , 'description' \
1644                  '*foo[bar]' \
1645                  '(two)*one[number]:first count:' \
1646                  'two[another number]::second count:(1 2 3)'
1647
1648     This describes three possible values: `foo', `one', and `two'.
1649     The first is described as `bar', takes no argument and may appear
1650     more than once.  The second is described as `number', may appear
1651     more than once, and takes one mandatory argument described as
1652     `first count'; no action is specified, so it will not be
1653     completed.  The `(two)' at the beginning says that if the value
1654     `one' is on the line, the value `two' will no longer be considered
1655     a possible completion.  Finally, the last value (`two') is
1656     described as `another number' and takes an optional argument
1657     described as `second count' for which the completions (to appear
1658     after an `=') are `1', `2', and `3'.  The _values function will
1659     complete lists of these values separated by commas.
1660
1661     Like _arguments, this function temporarily adds another context
1662     name component to the arguments element (the fifth) of the current
1663     context while executing the ACTION.  Here this name is just the
1664     name of the value for which the argument is completed.
1665
1666     The style verbose is used to decide if the descriptions for the
1667     values (but not those for the arguments) should be printed.
1668
1669     The associative array val_args is used to report values and their
1670     arguments; this works similarly to the opt_args associative array
1671     used by _arguments.  Hence the function calling _values should
1672     declare the local parameters state, state_descr, line, context and
1673     val_args:
1674
1675
1676          local context state state_descr line
1677          typeset -A val_args
1678
1679     when using an action of the form `->STRING'.  With this function
1680     the context parameter will be set to the name of the value whose
1681     argument is to be completed.  Note that for _values, the state and
1682     state_descr are scalars rather than arrays.  Only a single
1683     matching state is returned.
1684
1685     Note also that _values normally adds the character used as the
1686     separator between values as an auto-removable suffix (similar to a
1687     `/' after a directory).  However, this is not possible for a
1688     `->STRING' action as the matches for the argument are generated by
1689     the calling function.  To get the usual behaviour, the calling
1690     function can add the separator X as a suffix by passing the
1691     options `-qS X' either directly or indirectly to compadd.
1692
1693     The option -C is treated in the same way as it is by _arguments.
1694     In that case the parameter curcontext should be made local instead
1695     of context (as described above).
1696
1697_wanted [ -x ] [ -C NAME ]  [ -12VJ ] TAG NAME DESCR COMMAND [ ARG ...]
1698     In many contexts, completion can only generate one particular set
1699     of matches, usually corresponding to a single tag.  However, it is
1700     still necessary to decide whether the user requires matches of
1701     this type.  This function is useful in such a case.
1702
1703     The arguments to _wanted are the same as those to _requested, i.e.
1704     arguments to be passed to _description.  However, in this case the
1705     COMMAND is not optional;  all the processing of tags, including
1706     the loop over both tags and tag labels and the generation of
1707     matches, is carried out automatically by _wanted.
1708
1709     Hence to offer only one tag and immediately add the corresponding
1710     matches with the given description:
1711
1712
1713          local expl
1714          _wanted tag expl 'description' \
1715              compadd matches...
1716
1717     Note that, as for _requested, the COMMAND must be able to accept
1718     options to be passed down to compadd.
1719
1720     Like _tags this function supports the -C option to give a
1721     different name for the argument context field.  The -x option has
1722     the same meaning as for _description.
1723
1724_widgets [ -g PATTERN ]
1725     This function completes names of zle widgets (see *Note Zle
1726     Widgets::).  The PATTERN, if present, is matched against values of
1727     the $widgets special parameter, documented in *Note The
1728     zsh/zleparameter Module::.
1729
1730
1731
1732
1733File: zsh.info,  Node: Completion System Variables,  Next: Completion Directories,  Prev: Completion Functions,  Up: Completion System
1734
173520.7 Completion System Variables
1736================================
1737
1738
1739
1740There are some standard variables, initialised by the _main_complete
1741function and then used from other functions.
1742
1743The standard variables are:
1744
1745
1746_comp_caller_options
1747     The completion system uses setopt to set a number of options. This
1748     allows functions to be written without concern for compatibility
1749     with every possible combination of user options. However,
1750     sometimes completion needs to know what the user's option
1751     preferences are. These are saved in the _comp_caller_options
1752     associative array. Option names, spelled in lowercase without
1753     underscores, are mapped to one or other of the strings `on' and
1754     `off'.
1755
1756
1757
1758_comp_priv_prefix
1759     Completion functions such as _sudo can set the _comp_priv_prefix
1760     array to a command prefix that may then be used by _call_program to
1761     match the privileges when calling programs to generate matches.
1762
1763
1764Two more features are offered by the _main_complete function.  The
1765arrays compprefuncs and comppostfuncs may contain names of functions
1766that are to be called immediately before or after completion has been
1767tried.  A function will only be called once unless it explicitly
1768reinserts itself into the array.
1769
1770
1771
1772
1773File: zsh.info,  Node: Completion Directories,  Prev: Completion System Variables,  Up: Completion System
1774
177520.8 Completion Directories
1776===========================
1777
1778
1779
1780In the source distribution, the files are contained in various
1781subdirectories of the Completion directory.  They may have been
1782installed in the same structure, or into one single function directory.
1783The following is a description of the files found in the original
1784directory structure.  If you wish to alter an installed file, you will
1785need to copy it to some directory which appears earlier in your fpath
1786than the standard directory where it appears.
1787
1788
1789Base
1790     The core functions and special completion widgets automatically
1791     bound to keys.  You will certainly need most of these, though will
1792     probably not need to alter them.  Many of these are documented
1793     above.
1794
1795Zsh
1796     Functions for completing arguments of shell builtin commands and
1797     utility functions for this.  Some of these are also used by
1798     functions from the Unix directory.
1799
1800Unix
1801     Functions for completing arguments of external commands and suites
1802     of commands.  They may need modifying for your system, although in
1803     many cases some attempt is made to decide which version of a
1804     command is present.  For example, completion for the mount command
1805     tries to determine the system it is running on, while completion
1806     for many other utilities try to decide whether the GNU version of
1807     the command is in use, and hence whether the --help option is
1808     supported.
1809
1810X, AIX, BSD, ...
1811     Completion and utility function for commands available only on
1812     some systems.  These are not arranged hierarchically, so, for
1813     example, both the Linux and Debian directories, as well as the X
1814     directory, may be useful on your system.
1815
1816
1817
1818File: zsh.info,  Node: Completion Using compctl,  Next: Zsh Modules,  Prev: Completion System,  Up: Top
1819
182021 Completion Using compctl
1821***************************
1822
1823
1824
182521.1 Types of completion
1826========================
1827
1828This version of zsh has two ways of performing completion of words on
1829the command line.  New users of the shell may prefer to use the newer
1830and more powerful system based on shell functions; this is described in
1831*Note Completion System::, and the basic shell mechanisms which support
1832it are described in *Note Completion Widgets::.  This chapter describes
1833the older compctl command.
1834
183521.2 Description
1836================
1837
1838
1839
1840compctl [ -CDT ] OPTIONS [ COMMAND ... ]
1841
1842compctl [ -CDT ] OPTIONS [ -x PATTERN OPTIONS - ... -- ]
1843
1844        [ + OPTIONS [ -x ... -- ] ... [+] ] [ COMMAND ... ]
1845
1846compctl -M MATCH-SPECS ...
1847
1848compctl -L [ -CDTM ] [ COMMAND ... ]
1849
1850compctl + COMMAND ...
1851
1852
1853Control the editor's completion behavior according to the supplied set
1854of OPTIONS.  Various editing commands, notably expand-or-complete-word,
1855usually bound to tab, will attempt to complete a word typed by the
1856user, while others, notably delete-char-or-list, usually bound to ^D in
1857EMACS editing mode, list the possibilities; compctl controls what those
1858possibilities are.  They may for example be filenames (the most common
1859case, and hence the default), shell variables, or words from a
1860user-specified list.
1861
1862* Menu:
1863
1864* Command Flags::
1865* Option Flags::
1866* Alternative Completion::
1867* Extended Completion::
1868* Example::
1869
1870
1871
1872File: zsh.info,  Node: Command Flags,  Next: Option Flags,  Up: Completion Using compctl
1873
187421.3 Command Flags
1875==================
1876
1877Completion of the arguments of a command may be different for each
1878command or may use the default.  The behavior when completing the
1879command word itself may also be separately specified.  These correspond
1880to the following flags and arguments, all of which (except for -L) may
1881be combined with any combination of the OPTIONS described subsequently
1882in *Note Option Flags:::
1883
1884
1885COMMAND ...
1886     controls completion for the named commands, which must be listed
1887     last on the command line.  If completion is attempted for a
1888     command with a pathname containing slashes and no completion
1889     definition is found, the search is retried with the last pathname
1890     component. If the command starts with a =, completion is tried
1891     with the pathname of the command.
1892
1893     Any of the COMMAND strings may be patterns of the form normally
1894     used for filename generation.  These should be quoted to protect
1895     them from immediate expansion; for example the command string
1896     'foo*' arranges for completion of the words of any command
1897     beginning with foo.  When completion is attempted, all pattern
1898     completions are tried in the reverse order of their definition
1899     until one matches.  By default, completion then proceeds as
1900     normal, i.e. the shell will try to generate more matches for the
1901     specific command on the command line; this can be overridden by
1902     including -tn in the flags for the pattern completion.
1903
1904     Note that aliases are expanded before the command name is
1905     determined unless the COMPLETE_ALIASES option is set.  Commands
1906     may not be combined with the -C, -D or -T flags.
1907
1908-C
1909     controls completion when the command word itself is being
1910     completed.  If no compctl -C command has been issued,  the names
1911     of any executable command (whether in the path or specific to the
1912     shell, such as aliases or functions) are completed.
1913
1914-D
1915     controls default completion behavior for the arguments of commands
1916     not assigned any special behavior.  If no compctl -D command has
1917     been issued, filenames are completed.
1918
1919-T
1920     supplies completion flags to be used before any other processing is
1921     done, even before processing for compctls defined for specific
1922     commands.  This is especially useful when combined with extended
1923     completion (the -x flag, see *Note Extended Completion:: below).
1924     Using this flag you can define default behavior which will apply
1925     to all commands without exception, or you can alter the standard
1926     behavior for all commands.  For example, if your access to the
1927     user database is too slow and/or it contains too many users (so
1928     that completion after `~' is too slow to be usable), you can use
1929
1930
1931          compctl -T -x 's[~] C[0,[^/]#]' -k friends -S/ -tn
1932
1933     to complete the strings in the array friends after a `~'.  The
1934     C[...] argument is necessary so that this form of ~-completion is
1935     not tried after the directory name is finished.
1936
1937-L
1938     lists the existing completion behavior in a manner suitable for
1939     putting into a start-up script; the existing behavior is not
1940     changed.  Any combination of the above forms, or the -M flag
1941     (which must follow the -L flag), may be specified, otherwise all
1942     defined completions are listed.  Any other flags supplied are
1943     ignored.
1944
1945_no argument_
1946     If no argument is given, compctl lists all defined completions in
1947     an abbreviated form;  with a list of OPTIONS, all completions with
1948     those flags set (not counting extended completion) are listed.
1949
1950
1951If the + flag is alone and followed immediately by the COMMAND list,
1952the completion behavior for all the commands in the list is reset to
1953the default.  In other words, completion will subsequently use the
1954options specified by the -D flag.
1955
1956The form with -M as the first and only option defines global matching
1957specifications (see *Note Completion Matching Control::). The match
1958specifications given will be used for every completion attempt (only
1959when using compctl, not with the new completion system) and are tried
1960in the order in which they are defined until one generates at least one
1961match. E.g.:
1962
1963
1964     compctl -M '' 'm:{a-zA-Z}={A-Za-z}'
1965
1966This will first try completion without any global match specifications
1967(the empty string) and, if that generates no matches, will try case
1968insensitive completion.
1969
1970
1971
1972
1973File: zsh.info,  Node: Option Flags,  Next: Alternative Completion,  Prev: Command Flags,  Up: Completion Using compctl
1974
197521.4 Option Flags
1976=================
1977
1978
1979[ -fcFBdeaRGovNAIOPZEnbjrzu/12 ]
1980
1981[ -k ARRAY ] [ -g GLOBSTRING ] [ -s SUBSTSTRING ]
1982
1983[ -K FUNCTION ]
1984
1985[ -Q ] [ -P PREFIX ] [ -S SUFFIX ]
1986
1987[ -W FILE-PREFIX ] [ -H NUM PATTERN ]
1988
1989[ -q ] [ -X EXPLANATION ] [ -Y EXPLANATION ]
1990
1991[ -y FUNC-OR-VAR ] [ -l CMD ] [ -h CMD ] [ -U ]
1992
1993[ -t CONTINUE ] [ -J NAME ] [ -V NAME ]
1994
1995[ -M MATCH-SPEC ]
1996
1997
1998The remaining OPTIONS specify the type of command arguments to look for
1999during completion.  Any combination of these flags may be specified;
2000the result is a sorted list of all the possibilities.  The options are
2001as follows.
2002
2003* Menu:
2004
2005* Simple Flags::
2006* Flags with Arguments::
2007* Control Flags::
2008
2009
2010
2011File: zsh.info,  Node: Simple Flags,  Next: Flags with Arguments,  Up: Option Flags
2012
201321.4.1 Simple Flags
2014-------------------
2015
2016These produce completion lists made up by the shell itself:
2017
2018
2019-f
2020     Filenames and file system paths.
2021
2022-/
2023     Just file system paths.
2024
2025-c
2026     Command names, including aliases, shell functions, builtins and
2027     reserved words.
2028
2029-F
2030     Function names.
2031
2032-B
2033     Names of builtin commands.
2034
2035-m
2036     Names of external commands.
2037
2038-w
2039     Reserved words.
2040
2041-a
2042     Alias names.
2043
2044-R
2045     Names of regular (non-global) aliases.
2046
2047-G
2048     Names of global aliases.
2049
2050-d
2051     This can be combined with -F, -B, -w, -a, -R and -G to get names
2052     of disabled functions, builtins, reserved words or aliases.
2053
2054-e
2055     This option (to show enabled commands) is in effect by default, but
2056     may be combined with -d; -de in combination with -F, -B, -w, -a,
2057     -R and -G will complete names of functions, builtins, reserved
2058     words or aliases whether or not they are disabled.
2059
2060-o
2061     Names of shell options (see *Note Options::).
2062
2063-v
2064     Names of any variable defined in the shell.
2065
2066-N
2067     Names of scalar (non-array) parameters.
2068
2069-A
2070     Array names.
2071
2072-I
2073     Names of integer variables.
2074
2075-O
2076     Names of read-only variables.
2077
2078-p
2079     Names of parameters used by the shell (including special
2080     parameters).
2081
2082-Z
2083     Names of shell special parameters.
2084
2085-E
2086     Names of environment variables.
2087
2088-n
2089     Named directories.
2090
2091-b
2092     Key binding names.
2093
2094-j
2095     Job names:  the first word of the job leader's command line.  This
2096     is useful with the kill builtin.
2097
2098-r
2099     Names of running jobs.
2100
2101-z
2102     Names of suspended jobs.
2103
2104-u
2105     User names.
2106
2107
2108
2109
2110File: zsh.info,  Node: Flags with Arguments,  Next: Control Flags,  Prev: Simple Flags,  Up: Option Flags
2111
211221.4.2 Flags with Arguments
2113---------------------------
2114
2115These have user supplied arguments to determine how the list of
2116completions is to be made up:
2117
2118
2119-k ARRAY
2120     Names taken from the elements of $ARRAY (note that the `$' does
2121     not appear on the command line).  Alternatively, the argument
2122     ARRAY itself may be a set of space- or comma-separated values in
2123     parentheses, in which any delimiter may be escaped with a
2124     backslash; in this case the argument should be quoted.  For
2125     example,
2126
2127
2128          compctl -k "(cputime filesize datasize stacksize
2129          	       coredumpsize resident descriptors)" limit
2130
2131-g GLOBSTRING
2132     The GLOBSTRING is expanded using filename globbing; it should be
2133     quoted to protect it from immediate expansion. The resulting
2134     filenames are taken as the possible completions.  Use `*(/)'
2135     instead of `*/' for directories.  The fignore special parameter is
2136     not applied to the resulting files.  More than one pattern may be
2137     given separated by blanks. (Note that brace expansion is _not_
2138     part of globbing.  Use the syntax `(either|or)' to match
2139     alternatives.)
2140
2141-s SUBSTSTRING
2142     The SUBSTSTRING is split into words and these words are than
2143     expanded using all shell expansion mechanisms (see *Note
2144     Expansion::).  The resulting words are taken as possible
2145     completions.  The fignore special parameter is not applied to the
2146     resulting files.  Note that -g is faster for filenames.
2147
2148-K FUNCTION
2149     Call the given function to get the completions.  Unless the name
2150     starts with an underscore, the function is passed two arguments:
2151     the prefix and the suffix of the word on which completion is to be
2152     attempted, in other words those characters before the cursor
2153     position, and those from the cursor position onwards.  The whole
2154     command line can be accessed with the -c and -l flags of the read
2155     builtin. The function should set the variable reply to an array
2156     containing the completions (one completion per element); note that
2157     reply should not be made local to the function.  From such a
2158     function the command line can be accessed with the -c and -l flags
2159     to the read builtin.  For example,
2160
2161
2162          function whoson { reply=(`users`); }
2163          compctl -K whoson talk
2164
2165     completes only logged-on users after `talk'.  Note that `whoson'
2166     must return an array, so `reply=`users`' would be incorrect.
2167
2168-H NUM PATTERN
2169     The possible completions are taken from the last NUM history
2170     lines.  Only words matching PATTERN are taken.  If NUM is zero or
2171     negative the whole history is searched and if PATTERN is the empty
2172     string all words are taken (as with `*').  A typical use is
2173
2174
2175          compctl -D -f + -H 0 ''
2176
2177     which forces completion to look back in the history list for a
2178     word if no filename matches.
2179
2180
2181
2182
2183File: zsh.info,  Node: Control Flags,  Prev: Flags with Arguments,  Up: Option Flags
2184
218521.4.3 Control Flags
2186--------------------
2187
2188These do not directly specify types of name to be completed, but
2189manipulate the options that do:
2190
2191
2192-Q
2193     This instructs the shell not to quote any metacharacters in the
2194     possible completions.  Normally the results of a completion are
2195     inserted into the command line with any metacharacters quoted so
2196     that they are interpreted as normal characters.  This is
2197     appropriate for filenames and ordinary strings.  However, for
2198     special effects, such as inserting a backquoted expression from a
2199     completion array (-k) so that the expression will not be evaluated
2200     until the complete line is executed, this option must be used.
2201
2202-P PREFIX
2203     The PREFIX is inserted just before the completed string; any
2204     initial part already typed will be completed and the whole PREFIX
2205     ignored for completion purposes.  For example,
2206
2207
2208          compctl -j -P "%" kill
2209
2210     inserts a `%' after the kill command and then completes job names.
2211
2212-S SUFFIX
2213     When a completion is found the SUFFIX is inserted after the
2214     completed string.  In the case of menu completion the suffix is
2215     inserted immediately, but it is still possible to cycle through the
2216     list of completions by repeatedly hitting the same key.
2217
2218-W FILE-PREFIX
2219     With directory FILE-PREFIX:  for command, file, directory and
2220     globbing completion (options -c, -f, -/, -g), the file prefix is
2221     implicitly added in front of the completion.  For example,
2222
2223
2224          compctl -/ -W ~/Mail maildirs
2225
2226     completes any subdirectories to any depth beneath the directory
2227     ~/Mail, although that prefix does not appear on the command line.
2228     The FILE-PREFIX may also be of the form accepted by the -k flag,
2229     i.e. the name of an array or a literal list in parenthesis. In
2230     this case all the directories in the list will be searched for
2231     possible completions.
2232
2233-q
2234     If used with a suffix as specified by the -S option, this causes
2235     the suffix to be removed if the next character typed is a blank or
2236     does not insert anything or if the suffix consists of only one
2237     character and the next character typed is the same character; this
2238     the same rule used for the AUTO_REMOVE_SLASH option.  The option
2239     is most useful for list separators (comma, colon, etc.).
2240
2241-l CMD
2242     This option restricts the range of command line words that are
2243     considered to be arguments.  If combined with one of the extended
2244     completion patterns `p[...]', `r[...]', or `R[...]'  (see *Note
2245     Extended Completion:: below) the range is restricted to the range
2246     of arguments specified in the brackets.  Completion is then
2247     performed as if these had been given as arguments to the CMD
2248     supplied with the option. If the CMD string is empty the first
2249     word in the range is instead taken as the command name, and
2250     command name completion performed on the first word in the range.
2251     For example,
2252
2253
2254          compctl -x 'r[-exec,;]' -l '' -- find
2255
2256     completes arguments between `-exec' and the following `;' (or the
2257     end of the command line if there is no such string) as if they were
2258     a separate command line.
2259
2260-h CMD
2261     Normally zsh completes quoted strings as a whole. With this option,
2262     completion can be done separately on different parts of such
2263     strings. It works like the -l option but makes the completion code
2264     work on the parts of the current word that are separated by
2265     spaces. These parts are completed as if they were arguments to the
2266     given CMD. If CMD is the empty string, the first part is completed
2267     as a command name, as with -l.
2268
2269-U
2270     Use the whole list of possible completions, whether or not they
2271     actually match the word on the command line.  The word typed so far
2272     will be deleted.  This is most useful with a function (given by the
2273     -K option) which can examine the word components passed to it (or
2274     via the read builtin's -c and -l flags) and use its own criteria
2275     to decide what matches.  If there is no completion, the original
2276     word is retained.  Since the produced possible completions seldom
2277     have interesting common prefixes and suffixes, menu completion is
2278     started immediately if AUTO_MENU is set and this flag is used.
2279
2280-y FUNC-OR-VAR
2281     The list provided by FUNC-OR-VAR is displayed instead of the list
2282     of completions whenever a listing is required; the actual
2283     completions to be inserted are not affected.  It can be provided
2284     in two ways. Firstly, if FUNC-OR-VAR begins with a $ it defines a
2285     variable, or if it begins with a left parenthesis a literal array,
2286     which contains the list.  A variable may have been set by a call
2287     to a function using the -K option.  Otherwise it contains the name
2288     of a function which will be executed to create the list.  The
2289     function will be passed as an argument list all matching
2290     completions, including prefixes and suffixes expanded in full, and
2291     should set the array reply to the result.  In both cases, the
2292     display list will only be retrieved after a complete list of
2293     matches has been created.
2294
2295     Note that the returned list does not have to correspond, even in
2296     length, to the original set of matches, and may be passed as a
2297     scalar instead of an array.  No special formatting of characters is
2298     performed on the output in this case; in particular, newlines are
2299     printed literally and if they appear output in columns is
2300     suppressed.
2301
2302-X EXPLANATION
2303     Print EXPLANATION when trying completion on the current set of
2304     options. A `%n' in this string is replaced by the number of
2305     matches that were added for this explanation string.  The
2306     explanation only appears if completion was tried and there was no
2307     unique match, or when listing completions. Explanation strings
2308     will be listed together with the matches of the group specified
2309     together with the -X option (using the -J or -V option). If the
2310     same explanation string is given to multiple -X options, the
2311     string appears only once (for each group) and the number of
2312     matches shown for the `%n' is the total number of all matches for
2313     each of these uses. In any case, the explanation string will only
2314     be shown if there was at least one match added for the explanation
2315     string.
2316
2317     The sequences %B, %b, %S, %s, %U, and %u specify output attributes
2318     (bold, standout, and underline), %F, %f, %K, %k specify foreground
2319     and background colours, and %{...%} can be used to include literal
2320     escape sequences as in prompts.
2321
2322-Y EXPLANATION
2323     Identical to -X, except that the EXPLANATION first undergoes
2324     expansion following the usual rules for strings in double quotes.
2325     The expansion will be carried out after any functions are called
2326     for the -K or -y options, allowing them to set variables.
2327
2328-t CONTINUE
2329     The CONTINUE-string contains a character that specifies which set
2330     of completion flags should be used next.  It is useful:
2331
2332     (i) With -T, or when trying a list of pattern completions, when
2333     compctl would usually continue with ordinary processing after
2334     finding matches; this can be suppressed with `-tn'.
2335
2336     (ii) With a list of alternatives separated by +, when compctl
2337     would normally stop when one of the alternatives generates
2338     matches.  It can be forced to consider the next set of completions
2339     by adding `-t+' to the flags of the alternative before the `+'.
2340
2341     (iii) In an extended completion list (see below), when compctl
2342     would normally continue until a set of conditions succeeded, then
2343     use only the immediately following flags.  With `-t-', compctl will
2344     continue trying extended completions after the next `-'; with
2345     `-tx' it will attempt completion with the default flags, in other
2346     words those before the `-x'.
2347
2348-J NAME
2349     This gives the name of the group the matches should be placed in.
2350     Groups are listed and sorted separately; likewise, menu completion
2351     will offer the matches in the groups in the order in which the
2352     groups were defined. If no group name is explicitly given, the
2353     matches are stored in a group named default. The first time a
2354     group name is encountered, a group with that name is created.
2355     After that all matches with the same group name are stored in that
2356     group.
2357
2358     This can be useful with non-exclusive alternative completions.  For
2359     example, in
2360
2361
2362          compctl -f -J files -t+ + -v -J variables foo
2363
2364     both files and variables are possible completions, as the -t+
2365     forces both sets of alternatives before and after the + to be
2366     considered at once.  Because of the -J options, however, all files
2367     are listed before all variables.
2368
2369-V NAME
2370     Like -J, but matches within the group will not be sorted in
2371     listings nor in menu completion. These unsorted groups are in a
2372     different name space from the sorted ones, so groups defined as -J
2373     files and -V files are distinct.
2374
2375-1
2376     If given together with the -V option, makes only consecutive
2377     duplicates in the group be removed. Note that groups with and
2378     without this flag are in different name spaces.
2379
2380-2
2381     If given together with the -J or -V option, makes all duplicates
2382     be kept. Again, groups with and without this flag are in different
2383     name spaces.
2384
2385-M MATCH-SPEC
2386     This defines additional matching control specifications that
2387     should be used only when testing words for the list of flags this
2388     flag appears in. The format of the MATCH-SPEC string is described
2389     in *Note Completion Matching Control::.
2390
2391
2392
2393
2394File: zsh.info,  Node: Alternative Completion,  Next: Extended Completion,  Prev: Option Flags,  Up: Completion Using compctl
2395
239621.5 Alternative Completion
2397===========================
2398
2399
2400compctl [ -CDT ] OPTIONS + OPTIONS [ + ... ] [ + ] COMMAND ...
2401
2402
2403The form with `+' specifies alternative options. Completion is tried
2404with the options before the first `+'. If this produces no matches
2405completion is tried with the flags after the `+' and so on. If there
2406are no flags after the last `+' and a match has not been found up to
2407that point, default completion is tried.  If the list of flags contains
2408a -t with a + character, the next list of flags is used even if the
2409current list produced matches.
2410
2411
2412
2413
2414File: zsh.info,  Node: Extended Completion,  Next: Example,  Prev: Alternative Completion,  Up: Completion Using compctl
2415
2416Additional options are available that restrict completion to some part
2417of the command line; this is referred to as `extended completion'.
2418
2419
2420
242121.6 Extended Completion
2422========================
2423
2424
2425compctl [ -CDT ] OPTIONS -x PATTERN OPTIONS - ... --
2426
2427        [ COMMAND ... ]
2428
2429compctl [ -CDT ] OPTIONS [ -x PATTERN OPTIONS - ... -- ]
2430
2431        [ + OPTIONS [ -x ... -- ] ... [+] ] [ COMMAND ... ]
2432
2433
2434The form with `-x' specifies extended completion for the commands
2435given; as shown, it may be combined with alternative completion using
2436`+'.  Each PATTERN is examined in turn; when a match is found, the
2437corresponding OPTIONS, as described in *Note Option Flags:: above, are
2438used to generate possible completions.  If no PATTERN matches, the
2439OPTIONS given before the -x are used.
2440
2441Note that each pattern should be supplied as a single argument and
2442should be quoted to prevent expansion of metacharacters by the shell.
2443
2444A PATTERN is built of sub-patterns separated by commas; it matches if
2445at least one of these sub-patterns matches (they are `or'ed). These
2446sub-patterns are in turn composed of other sub-patterns separated by
2447white spaces which match if all of the sub-patterns match (they are
2448`and'ed).  An element of the sub-patterns is of the form `C[...][...]',
2449where the pairs of brackets may be repeated as often as necessary, and
2450matches if any of the sets of brackets match (an `or').  The example
2451below makes this clearer.
2452
2453The elements may be any of the following:
2454
2455
2456s[STRING]...
2457     Matches if the current word on the command line starts with one of
2458     the strings given in brackets.  The STRING is not removed and is
2459     not part of the completion.
2460
2461S[STRING]...
2462     Like s[STRING] except that the STRING is part of the completion.
2463
2464p[FROM,TO]...
2465     Matches if the number of the current word is between one of the
2466     FROM and TO pairs inclusive. The comma and TO are optional; TO
2467     defaults to the same value as FROM.  The numbers may be negative:
2468     -N refers to the N'th last word on the line.
2469
2470c[OFFSET,STRING]...
2471     Matches if the STRING matches the word offset by OFFSET from the
2472     current word position.  Usually OFFSET will be negative.
2473
2474C[OFFSET,PATTERN]...
2475     Like c but using pattern matching instead.
2476
2477w[INDEX,STRING]...
2478     Matches if the word in position INDEX is equal to the
2479     corresponding STRING.  Note that the word count is made after any
2480     alias expansion.
2481
2482W[INDEX,PATTERN]...
2483     Like w but using pattern matching instead.
2484
2485n[INDEX,STRING]...
2486     Matches if the current word contains STRING.  Anything up to and
2487     including the INDEXth occurrence of this string will not be
2488     considered part of the completion, but the rest will.  INDEX may
2489     be negative to count from the end: in most cases, INDEX will be 1
2490     or -1.  For example,
2491
2492
2493          compctl -s '`users`' -x 'n[1,@]' -k hosts -- talk
2494
2495     will usually complete usernames, but if you insert an @ after the
2496     name, names from the array HOSTS (assumed to contain hostnames,
2497     though you must make the array yourself) will be completed.  Other
2498     commands such as rcp can be handled similarly.
2499
2500N[INDEX,STRING]...
2501     Like n except that the string will be taken as a character class.
2502     Anything up to and including the INDEXth occurrence of any of the
2503     characters in STRING will not be considered part of the completion.
2504
2505m[MIN,MAX]...
2506     Matches if the total number of words lies between MIN and MAX
2507     inclusive.
2508
2509r[STR1,STR2]...
2510     Matches if the cursor is after a word with prefix STR1.  If there
2511     is also a word with prefix STR2 on the command line after the one
2512     matched by STR1 it matches only if the cursor is before this word.
2513     If the comma and STR2 are omitted, it matches if the cursor is
2514     after a word with prefix STR1.
2515
2516R[STR1,STR2]...
2517     Like r but using pattern matching instead.
2518
2519q[STR]...
2520     Matches the word currently being completed is in single quotes and
2521     the STR begins with the letter `s', or if completion is done in
2522     double quotes and STR starts with the letter `d', or if completion
2523     is done in backticks and STR starts with a `b'.
2524
2525
2526
2527
2528File: zsh.info,  Node: Example,  Prev: Extended Completion,  Up: Completion Using compctl
2529
253021.7 Example
2531============
2532
2533
2534     compctl -u -x 's[+] c[-1,-f],s[-f+]' \
2535       -g '~/Mail/*(:t)' - 's[-f],c[-1,-f]' -f -- mail
2536
2537This is to be interpreted as follows:
2538
2539If the current command is mail, then
2540
2541
2542
2543     if ((the current word begins with + and the previous word is -f)
2544     or (the current word begins with -f+)), then complete the
2545     non-directory part (the `:t' glob modifier) of files in the
2546     directory ~/Mail; else
2547
2548     if the current word begins with -f or the previous word was -f,
2549     then complete any file; else
2550
2551     complete user names.
2552
2553
2554
2555File: zsh.info,  Node: Zsh Modules,  Next: Calendar Function System,  Prev: Completion Using compctl,  Up: Top
2556
255722 Zsh Modules
2558**************
2559
2560
2561
256222.1 Description
2563================
2564
2565Some optional parts of zsh are in modules, separate from the core of
2566the shell.  Each of these modules may be linked in to the shell at
2567build time, or can be dynamically linked while the shell is running if
2568the installation supports this feature.  Modules are linked at runtime
2569with the zmodload command, see *Note Shell Builtin Commands::.
2570
2571The modules that are bundled with the zsh distribution are:
2572
2573
2574zsh/attr
2575     Builtins for manipulating extended attributes (xattr).
2576
2577zsh/cap
2578     Builtins for manipulating POSIX.1e (POSIX.6) capability
2579     (privilege) sets.
2580
2581zsh/clone
2582     A builtin that can clone a running shell onto another terminal.
2583
2584zsh/compctl
2585     The compctl builtin for controlling completion.
2586
2587zsh/complete
2588     The basic completion code.
2589
2590zsh/complist
2591     Completion listing extensions.
2592
2593zsh/computil
2594     A module with utility builtins needed for the shell function based
2595     completion system.
2596
2597zsh/curses
2598     curses windowing commands
2599
2600zsh/datetime
2601     Some date/time commands and parameters.
2602
2603zsh/db/gdbm
2604     Builtins for managing associative array parameters tied to GDBM
2605     databases.
2606
2607zsh/deltochar
2608     A ZLE function duplicating EMACS' zap-to-char.
2609
2610zsh/example
2611     An example of how to write a module.
2612
2613zsh/files
2614     Some basic file manipulation commands as builtins.
2615
2616zsh/langinfo
2617     Interface to locale information.
2618
2619zsh/mapfile
2620     Access to external files via a special associative array.
2621
2622zsh/mathfunc
2623     Standard scientific functions for use in mathematical evaluations.
2624
2625zsh/nearcolor
2626     Map colours to the nearest colour in the available palette.
2627
2628zsh/newuser
2629     Arrange for files for new users to be installed.
2630
2631zsh/parameter
2632     Access to internal hash tables via special associative arrays.
2633
2634zsh/pcre
2635     Interface to the PCRE library.
2636
2637zsh/param/private
2638     Builtins for managing private-scoped parameters in function
2639     context.
2640
2641zsh/regex
2642     Interface to the POSIX regex library.
2643
2644zsh/sched
2645     A builtin that provides a timed execution facility within the
2646     shell.
2647
2648zsh/net/socket
2649     Manipulation of Unix domain sockets
2650
2651zsh/stat
2652     A builtin command interface to the stat system call.
2653
2654zsh/system
2655     A builtin interface to various low-level system features.
2656
2657zsh/net/tcp
2658     Manipulation of TCP sockets
2659
2660zsh/termcap
2661     Interface to the termcap database.
2662
2663zsh/terminfo
2664     Interface to the terminfo database.
2665
2666zsh/zftp
2667     A builtin FTP client.
2668
2669zsh/zle
2670     The Zsh Line Editor, including the bindkey and vared builtins.
2671
2672zsh/zleparameter
2673     Access to internals of the Zsh Line Editor via parameters.
2674
2675zsh/zprof
2676     A module allowing profiling for shell functions.
2677
2678zsh/zpty
2679     A builtin for starting a command in a pseudo-terminal.
2680
2681zsh/zselect
2682     Block and return when file descriptors are ready.
2683
2684zsh/zutil
2685     Some utility builtins, e.g. the one for supporting configuration
2686     via styles.
2687
2688
2689* Menu:
2690
2691* The zsh/attr Module::
2692* The zsh/cap Module::
2693* The zsh/clone Module::
2694* The zsh/compctl Module::
2695* The zsh/complete Module::
2696* The zsh/complist Module::
2697* The zsh/computil Module::
2698* The zsh/curses Module::
2699* The zsh/datetime Module::
2700* The zsh/db/gdbm Module::
2701* The zsh/deltochar Module::
2702* The zsh/example Module::
2703* The zsh/files Module::
2704* The zsh/langinfo Module::
2705* The zsh/mapfile Module::
2706* The zsh/mathfunc Module::
2707* The zsh/nearcolor Module::
2708* The zsh/newuser Module::
2709* The zsh/parameter Module::
2710* The zsh/pcre Module::
2711* The zsh/param/private Module::
2712* The zsh/regex Module::
2713* The zsh/sched Module::
2714* The zsh/net/socket Module::
2715* The zsh/stat Module::
2716* The zsh/system Module::
2717* The zsh/net/tcp Module::
2718* The zsh/termcap Module::
2719* The zsh/terminfo Module::
2720* The zsh/zftp Module::
2721* The zsh/zle Module::
2722* The zsh/zleparameter Module::
2723* The zsh/zprof Module::
2724* The zsh/zpty Module::
2725* The zsh/zselect Module::
2726* The zsh/zutil Module::
2727
2728
2729File: zsh.info,  Node: The zsh/attr Module,  Next: The zsh/cap Module,  Up: Zsh Modules
2730
273122.2 The zsh/attr Module
2732========================
2733
2734
2735
2736   The zsh/attr module is used for manipulating extended attributes.
2737The -h option causes all commands to operate on symbolic links instead
2738of their targets.  The builtins in this module are:
2739
2740
2741zgetattr [ -h ] FILENAME ATTRIBUTE [ PARAMETER ]
2742     Get the extended attribute ATTRIBUTE from the specified FILENAME.
2743     If the optional argument PARAMETER is given, the attribute is set
2744     on that parameter instead of being printed to stdout.
2745
2746zsetattr [ -h ] FILENAME ATTRIBUTE VALUE
2747     Set the extended attribute ATTRIBUTE on the specified FILENAME to
2748     VALUE.
2749
2750zdelattr [ -h ] FILENAME ATTRIBUTE
2751     Remove the extended attribute ATTRIBUTE from the specified
2752     FILENAME.
2753
2754zlistattr [ -h ] FILENAME [ PARAMETER ]
2755     List the extended attributes currently set on the specified
2756     FILENAME. If the optional argument PARAMETER is given, the list of
2757     attributes is set on that parameter instead of being printed to
2758     stdout.
2759
2760
2761zgetattr and zlistattr allocate memory dynamically.  If the attribute
2762or list of attributes grows between the allocation and the call to get
2763them, they return 2.  On all other errors, 1 is returned.  This allows
2764the calling function to check for this case and retry.
2765
2766
2767File: zsh.info,  Node: The zsh/cap Module,  Next: The zsh/clone Module,  Prev: The zsh/attr Module,  Up: Zsh Modules
2768
276922.3 The zsh/cap Module
2770=======================
2771
2772
2773
2774   The zsh/cap module is used for manipulating POSIX.1e (POSIX.6)
2775capability sets.  If the operating system does not support this
2776interface, the builtins defined by this module will do nothing.  The
2777builtins in this module are:
2778
2779
2780cap [ CAPABILITIES ]
2781     Change the shell's process capability sets to the specified
2782     CAPABILITIES, otherwise display the shell's current capabilities.
2783
2784getcap FILENAME ...
2785     This is a built-in implementation of the POSIX standard utility.
2786     It displays the capability sets on each specified FILENAME.
2787
2788setcap CAPABILITIES FILENAME ...
2789     This is a built-in implementation of the POSIX standard utility.
2790     It sets the capability sets on each specified FILENAME to the
2791     specified CAPABILITIES.
2792
2793
2794
2795File: zsh.info,  Node: The zsh/clone Module,  Next: The zsh/compctl Module,  Prev: The zsh/cap Module,  Up: Zsh Modules
2796
279722.4 The zsh/clone Module
2798=========================
2799
2800
2801
2802   The zsh/clone module makes available one builtin command:
2803
2804
2805clone TTY
2806     Creates a forked instance of the current shell, attached to the
2807     specified TTY.  In the new shell, the PID, PPID and TTY special
2808     parameters are changed appropriately.  $! is set to zero in the new
2809     shell, and to the new shell's PID in the original shell.
2810
2811     The return status of the builtin is zero in both shells if
2812     successful, and non-zero on error.
2813
2814     The target of clone should be an unused terminal, such as an
2815     unused virtual console or a virtual terminal created by
2816
2817
2818          xterm -e sh -c 'trap : INT QUIT TSTP; tty;
2819                  while :; do sleep 100000000; done'
2820
2821     Some words of explanation are warranted about this long xterm
2822     command line: when doing clone on a pseudo-terminal, some other
2823     session ("session" meant as a unix session group, or SID) is
2824     already owning the terminal. Hence the cloned zsh cannot acquire
2825     the pseudo-terminal as a controlling tty. That means two things:
2826
2827
2828        * the job control signals will go to the sh-started-by-xterm
2829          process group (that's why we disable INT QUIT and TSTP with
2830          trap; otherwise the while loop could get suspended or killed)
2831
2832        * the cloned shell will have job control disabled, and the job
2833          control keys (control-C, control-\ and control-Z) will not
2834          work.
2835
2836     This does not apply when cloning to an _unused_ vc.
2837
2838     Cloning to a used (and unprepared) terminal will result in two
2839     processes reading simultaneously from the same terminal, with
2840     input bytes going randomly to either process.
2841
2842     clone is mostly useful as a shell built-in replacement for openvt.
2843
2844
2845
2846File: zsh.info,  Node: The zsh/compctl Module,  Next: The zsh/complete Module,  Prev: The zsh/clone Module,  Up: Zsh Modules
2847
284822.5 The zsh/compctl Module
2849===========================
2850
2851
2852
2853   The zsh/compctl module makes available two builtin commands. compctl,
2854is the old, deprecated way to control completions for ZLE.  See *Note
2855Completion Using compctl::.  The other builtin command, compcall can be
2856used in user-defined completion widgets, see *Note Completion Widgets::.
2857
2858
2859File: zsh.info,  Node: The zsh/complete Module,  Next: The zsh/complist Module,  Prev: The zsh/compctl Module,  Up: Zsh Modules
2860
286122.6 The zsh/complete Module
2862============================
2863
2864
2865
2866   The zsh/complete module makes available several builtin commands
2867which can be used in user-defined completion widgets, see *Note
2868Completion Widgets::.
2869
2870
2871File: zsh.info,  Node: The zsh/complist Module,  Next: The zsh/computil Module,  Prev: The zsh/complete Module,  Up: Zsh Modules
2872
287322.7 The zsh/complist Module
2874============================
2875
2876
2877
2878   The zsh/complist module offers three extensions to completion
2879listings: the ability to highlight matches in such a list, the ability
2880to scroll through long lists and a different style of menu completion.
2881
2882
2883
288422.7.1 Colored completion listings
2885----------------------------------
2886
2887Whenever one of the parameters ZLS_COLORS or ZLS_COLOURS is set and the
2888zsh/complist module is loaded or linked into the shell, completion
2889lists will be colored.  Note, however, that complist will not
2890automatically be loaded if it is not linked in:  on systems with
2891dynamic loading, `zmodload zsh/complist' is required.
2892
2893The parameters ZLS_COLORS and ZLS_COLOURS describe how matches are
2894highlighted.  To turn on highlighting an empty value suffices, in which
2895case all the default values given below will be used.  The format of
2896the value of these parameters is the same as used by the GNU version of
2897the ls command: a colon-separated list of specifications of the form
2898`NAME=VALUE'.  The NAME may be one of the following strings, most of
2899which specify file types for which the VALUE will be used.  The strings
2900and their default values are:
2901
2902
2903no 0
2904     for normal text (i.e. when displaying something other than a
2905     matched file)
2906
2907fi 0
2908     for regular files
2909
2910di 32
2911     for directories
2912
2913ln 36
2914     for symbolic links.  If this has the special value target,
2915     symbolic links are dereferenced and the target file used to
2916     determine the display format.
2917
2918pi 31
2919     for named pipes (FIFOs)
2920
2921so 33
2922     for sockets
2923
2924bd 44;37
2925     for block devices
2926
2927cd 44;37
2928     for character devices
2929
2930or NONE
2931     for a symlink to nonexistent file (default is the value defined
2932     for ln)
2933
2934mi NONE
2935     for a non-existent file (default is the value defined for fi);
2936     this code is currently not used
2937
2938su 37;41
2939     for files with setuid bit set
2940
2941sg 30;43
2942     for files with setgid bit set
2943
2944tw 30;42
2945     for world writable directories with sticky bit set
2946
2947ow 34;43
2948     for world writable directories without sticky bit set
2949
2950sa NONE
2951     for files with an associated suffix alias; this is only tested
2952     after specific suffixes, as described below
2953
2954st 37;44
2955     for directories with sticky bit set but not world writable
2956
2957ex 35
2958     for executable files
2959
2960lc \e[
2961     for the left code (see below)
2962
2963rc m
2964     for the right code
2965
2966tc 0
2967     for the character indicating the file type  printed after
2968     filenames if the LIST_TYPES option is set
2969
2970sp 0
2971     for the spaces printed after matches to align the next column
2972
2973ec NONE
2974     for the end code
2975
2976
2977Apart from these strings, the NAME may also be an asterisk (`*')
2978followed by any string. The VALUE given for such a string will be used
2979for all files whose name ends with the string.  The NAME may also be an
2980equals sign (`=') followed by a pattern; the EXTENDED_GLOB option will
2981be turned on for evaluation of the pattern.  The VALUE given for this
2982pattern will be used for all matches (not just filenames) whose display
2983string are matched by the pattern.  Definitions for the form with the
2984leading equal sign take precedence over the values defined for file
2985types, which in turn take precedence over the form with the leading
2986asterisk (file extensions).
2987
2988The leading-equals form also allows different parts of the displayed
2989strings to be colored differently.  For this, the pattern has to use the
2990`(#b)' globbing flag and pairs of parentheses surrounding the parts of
2991the strings that are to be colored differently.  In this case the VALUE
2992may consist of more than one color code separated by equal signs.  The
2993first code will be used for all parts for which no explicit code is
2994specified and the following codes will be used for the parts matched by
2995the sub-patterns in parentheses.  For example, the specification
2996`=(#b)(?)*(?)=0=3=7' will be used for all matches which are at least
2997two characters long and will use the code `3' for the first character,
2998`7' for the last character and `0' for the rest.
2999
3000All three forms of NAME may be preceded by a pattern in parentheses.
3001If this is given, the VALUE will be used only for matches in groups
3002whose names are matched by the pattern given in the parentheses.  For
3003example, `(g*)m*=43' highlights all matches beginning with `m' in
3004groups whose names  begin with `g' using the color code `43'.  In case
3005of the `lc', `rc', and `ec' codes, the group pattern is ignored.
3006
3007Note also that all patterns are tried in the order in which they appear
3008in the parameter value until the first one matches which is then used.
3009Patterns may be matched against completions, descriptions (possibly
3010with spaces appended for padding), or lines consisting of a completion
3011followed by a description.  For consistent coloring it may be necessary
3012to use more than one pattern or a pattern with backreferences.
3013
3014When printing a match, the code prints the value of lc, the value for
3015the file-type or the last matching specification with a `*', the value
3016of rc, the string to display for the match itself, and then the value
3017of ec if that is defined or the values of lc, no, and rc if ec is not
3018defined.
3019
3020The default values are ISO 6429 (ANSI) compliant and can be used on
3021vt100 compatible terminals such as xterms.  On monochrome terminals the
3022default values will have no visible effect.  The colors function from
3023the contribution can be used to get associative arrays containing the
3024codes for ANSI terminals (see *Note Other Functions::).  For example,
3025after loading colors, one could use `$color[red]' to get the code for
3026foreground color red and `$color[bg-green]' for the code for background
3027color green.
3028
3029If the completion system invoked by compinit is used, these parameters
3030should not be set directly because the system controls them itself.
3031Instead, the list-colors style should be used (see *Note Completion
3032System Configuration::).
3033
3034
3035
303622.7.2 Scrolling in completion listings
3037---------------------------------------
3038
3039To enable scrolling through a completion list, the LISTPROMPT parameter
3040must be set.  Its value will be used as the prompt; if it is the empty
3041string, a default prompt will be used.  The value may contain escapes
3042of the form `%x'.  It supports the escapes `%B', `%b', `%S', `%s',
3043`%U', `%u', `%F', `%f', `%K', `%k' and `%{...%}' used also in shell
3044prompts as well as three pairs of additional sequences: a `%l' or `%L'
3045is replaced by the number of the last line shown and the total number
3046of lines in the form `NUMBER/TOTAL'; a `%m' or `%M' is replaced with
3047the number of the last match shown and the total number of matches; and
3048`%p' or `%P' is replaced with `Top', `Bottom' or the position of the
3049first line shown in percent of the total number of lines, respectively.
3050In each of these cases the form with the uppercase letter will be
3051replaced with a string of fixed width, padded to the right with spaces,
3052while the lowercase form will not be padded.
3053
3054If the parameter LISTPROMPT is set, the completion code will not ask if
3055the list should be shown.  Instead it immediately starts displaying the
3056list, stopping after the first screenful, showing the prompt at the
3057bottom, waiting for a keypress after temporarily switching to the
3058listscroll keymap.  Some of the zle functions have a special meaning
3059while scrolling lists:
3060
3061
3062send-break
3063     stops listing discarding the key pressed
3064
3065accept-line, down-history, down-line-or-history
3066down-line-or-search, vi-down-line-or-history
3067     scrolls forward one line
3068
3069complete-word, menu-complete, expand-or-complete
3070expand-or-complete-prefix, menu-complete-or-expand
3071     scrolls forward one screenful
3072
3073accept-search
3074     stop listing but take no other action
3075
3076
3077Every other character stops listing and immediately processes the key
3078as usual.  Any key that is not bound in the listscroll keymap or that
3079is bound to undefined-key is looked up in the keymap currently selected.
3080
3081As for the ZLS_COLORS and ZLS_COLOURS parameters, LISTPROMPT should not
3082be set directly when using the shell function based completion system.
3083Instead, the list-prompt style should be used.
3084
3085
3086
308722.7.3 Menu selection
3088---------------------
3089
3090The zsh/complist module also offers an alternative style of selecting
3091matches from a list, called menu selection, which can be used if the
3092shell is set up to return to the last prompt after showing a completion
3093list (see the ALWAYS_LAST_PROMPT option in *Note Options::).
3094
3095Menu selection can be invoked directly by the widget menu-select
3096defined by this module.  This is a standard ZLE widget that can be
3097bound to a key in the usual way as described in *Note Zsh Line Editor::.
3098
3099Alternatively, the parameter MENUSELECT can be set to an integer, which
3100gives the minimum number of matches that must be present before menu
3101selection is automatically turned on.  This second method requires that
3102menu completion be started, either directly from a widget such as
3103menu-complete, or due to one of the options MENU_COMPLETE or AUTO_MENU
3104being set.  If MENUSELECT is set, but is 0, 1 or empty, menu selection
3105will always be started during an ambiguous menu completion.
3106
3107When using the completion system based on shell functions, the
3108MENUSELECT parameter should not be used (like the ZLS_COLORS and
3109ZLS_COLOURS parameters described above).  Instead, the menu style
3110should be used with the select=... keyword.
3111
3112After menu selection is started, the matches will be listed. If there
3113are more matches than fit on the screen, only the first screenful is
3114shown.  The matches to insert into the command line can be selected
3115from this list.  In the list one match is highlighted using the value
3116for ma from the ZLS_COLORS or ZLS_COLOURS parameter.  The default value
3117for this is `7' which forces the selected match to be highlighted using
3118standout mode on a vt100-compatible terminal.  If neither ZLS_COLORS
3119nor ZLS_COLOURS is set, the same terminal control sequence as for the
3120`%S' escape in prompts is used.
3121
3122If there are more matches than fit on the screen and the parameter
3123MENUPROMPT is set, its value will be shown below the matches.  It
3124supports the same escape sequences as LISTPROMPT, but the number of the
3125match or line shown will be that of the one where the mark is placed.
3126If its value is the empty string, a default prompt will be used.
3127
3128The MENUSCROLL parameter can be used to specify how the list is
3129scrolled.  If the parameter is unset, this is done line by line, if it
3130is set to `0' (zero), the list will scroll half the number of lines of
3131the screen.  If the value is positive, it gives the number of lines to
3132scroll and if it is negative, the list will be scrolled the number of
3133lines of the screen minus the (absolute) value.
3134
3135As for the ZLS_COLORS, ZLS_COLOURS and LISTPROMPT parameters, neither
3136MENUPROMPT nor MENUSCROLL should be set directly when using the shell
3137function based completion system.  Instead, the select-prompt and
3138select-scroll styles should be used.
3139
3140The completion code sometimes decides not to show all of the matches in
3141the list.  These hidden matches are either matches for which the
3142completion function which added them explicitly requested that they not
3143appear in the list (using the -n option of the compadd builtin command)
3144or they are matches which duplicate a string already in the list
3145(because they differ only in things like prefixes or suffixes that are
3146not displayed).  In the list used for menu selection, however, even
3147these matches are shown so that it is possible to select them.  To
3148highlight such matches the hi and du capabilities in the ZLS_COLORS and
3149ZLS_COLOURS parameters are supported for hidden matches of the first
3150and second kind, respectively.
3151
3152Selecting matches is done by moving the mark around using the zle
3153movement functions.  When not all matches can be shown on the screen at
3154the same time, the list will scroll up and down when crossing the top or
3155bottom line.  The following zle functions have special meaning during
3156menu selection.  Note that the following always perform the same task
3157within the menu selection map and cannot be replaced by user defined
3158widgets, nor can the set of functions be extended:
3159
3160
3161accept-line, accept-search
3162     accept the current match and leave menu selection (but do not
3163     cause the command line to be accepted)
3164
3165send-break
3166     leaves menu selection and restores the previous contents of the
3167     command line
3168
3169redisplay, clear-screen
3170     execute their normal function without leaving menu selection
3171
3172accept-and-hold, accept-and-menu-complete
3173     accept the currently inserted match and continue selection
3174     allowing to select the next match to insert into the line
3175
3176accept-and-infer-next-history
3177     accepts the current match and then tries completion with menu
3178     selection again;  in the case of files this allows one to select a
3179     directory and immediately attempt to complete files in it;  if
3180     there are no matches, a message is shown and one can use undo to
3181     go back to completion on the previous level, every other key
3182     leaves menu selection (including the other zle functions which are
3183     otherwise special during menu selection)
3184
3185undo
3186     removes matches inserted during the menu selection by one of the
3187     three functions before
3188
3189down-history, down-line-or-history
3190vi-down-line-or-history,  down-line-or-search
3191     moves the mark one line down
3192
3193up-history, up-line-or-history
3194vi-up-line-or-history, up-line-or-search
3195     moves the mark one line up
3196
3197forward-char, vi-forward-char
3198     moves the mark one column right
3199
3200backward-char, vi-backward-char
3201     moves the mark one column left
3202
3203forward-word, vi-forward-word
3204vi-forward-word-end, emacs-forward-word
3205     moves the mark one screenful down
3206
3207backward-word, vi-backward-word, emacs-backward-word
3208     moves the mark one screenful up
3209
3210vi-forward-blank-word, vi-forward-blank-word-end
3211     moves the mark to the first line of the next group of matches
3212
3213vi-backward-blank-word
3214     moves the mark to the last line of the previous group of matches
3215
3216beginning-of-history
3217     moves the mark to the first line
3218
3219end-of-history
3220     moves the mark to the last line
3221
3222beginning-of-buffer-or-history, beginning-of-line
3223beginning-of-line-hist, vi-beginning-of-line
3224     moves the mark to the leftmost column
3225
3226end-of-buffer-or-history, end-of-line
3227end-of-line-hist, vi-end-of-line
3228     moves the mark to the rightmost column
3229
3230complete-word, menu-complete, expand-or-complete
3231expand-or-complete-prefix, menu-expand-or-complete
3232     moves the mark to the next match
3233
3234reverse-menu-complete
3235     moves the mark to the previous match
3236
3237vi-insert
3238     this toggles between normal and interactive mode; in interactive
3239     mode the keys bound to self-insert and self-insert-unmeta insert
3240     into the command line as in normal editing mode but without leaving
3241     menu selection; after each character completion is tried again and
3242     the list changes to contain only the new matches; the completion
3243     widgets make the longest unambiguous string be inserted in the
3244     command line and undo and backward-delete-char go back to the
3245     previous set of matches
3246
3247history-incremental-search-forward
3248history-incremental-search-backward
3249     this starts incremental searches in the list of completions
3250     displayed; in this mode, accept-line only leaves incremental
3251     search, going back to the normal menu selection mode
3252
3253
3254All movement functions wrap around at the edges; any other zle function
3255not listed leaves menu selection and executes that function.  It is
3256possible to make widgets in the above list do the same by using the
3257form of the widget with a `.' in front.  For example, the widget
3258`.accept-line' has the effect of leaving menu selection and accepting
3259the entire command line.
3260
3261During this selection the widget uses the keymap menuselect.  Any key
3262that is not defined in this keymap or that is bound to undefined-key is
3263looked up in the keymap currently selected.  This is used to ensure
3264that the most important keys used during selection (namely the cursor
3265keys, return, and TAB) have sensible defaults.  However, keys in the
3266menuselect keymap can be modified directly using the bindkey builtin
3267command (see *Note The zsh/zle Module::). For example, to make the
3268return key leave menu selection without accepting the match currently
3269selected one could call
3270
3271
3272     bindkey -M menuselect '^M' send-break
3273
3274after loading the zsh/complist module.
3275
3276
3277File: zsh.info,  Node: The zsh/computil Module,  Next: The zsh/curses Module,  Prev: The zsh/complist Module,  Up: Zsh Modules
3278
327922.8 The zsh/computil Module
3280============================
3281
3282
3283
3284   The zsh/computil module adds several builtin commands that are used
3285by some of the completion functions in the completion system based on
3286shell functions (see *Note Completion System:: ).  Except for compquote
3287these builtin commands are very specialised and thus not very
3288interesting when writing your own completion functions.  In summary,
3289these builtin commands are:
3290
3291
3292comparguments
3293     This is used by the _arguments function to do the argument and
3294     command line parsing.  Like compdescribe it has an option -i to do
3295     the parsing and initialize some internal state and various options
3296     to access the state information to decide what should be completed.
3297
3298compdescribe
3299     This is used by the _describe function to build the displays for
3300     the matches and to get the strings to add as matches with their
3301     options.  On the first call one of the options -i or -I should be
3302     supplied as the first argument.  In the first case, display
3303     strings without the descriptions will be generated, in the second
3304     case, the string used to separate the matches from their
3305     descriptions must be given as the second argument and the
3306     descriptions (if any) will be shown.  All other arguments are like
3307     the definition arguments to _describe itself.
3308
3309     Once compdescribe has been called with either the -i or the -I
3310     option, it can be repeatedly called with the -g option and the
3311     names of four parameters as its arguments.  This will step through
3312     the different sets of matches and store the value of
3313     compstate[list] in the first scalar, the options for compadd in
3314     the second array, the matches in the third array, and the strings
3315     to be displayed in the completion listing in the fourth array.
3316     The arrays may then be directly given to compadd to register the
3317     matches with the completion code.
3318
3319compfiles
3320     Used by the _path_files function to optimize complex recursive
3321     filename generation (globbing).  It does three things.  With the
3322     -p and -P options it builds the glob patterns to use, including
3323     the paths already handled and trying to optimize the patterns with
3324     respect to the prefix and suffix from the line and the match
3325     specification currently used.  The -i option does the directory
3326     tests for the ignore-parents style and the -r option tests if a
3327     component for some of the matches are equal to the string on the
3328     line and removes all other matches if that is true.
3329
3330compgroups
3331     Used by the _tags function to implement the internals of the
3332     group-order style.  This only takes its arguments as names of
3333     completion groups and creates the groups for it (all six types:
3334     sorted and unsorted, both without removing duplicates, with
3335     removing all duplicates and with removing consecutive duplicates).
3336
3337compquote [ -p ] NAMES ...
3338     There may be reasons to write completion functions that have to add
3339     the matches using the -Q option to compadd and perform quoting
3340     themselves.  Instead of interpreting the first character of the
3341     all_quotes key of the compstate special association and using the
3342     q flag for parameter expansions, one can use this builtin command.
3343     The arguments are the names of scalar or array parameters and the
3344     values of these parameters are quoted as needed for the innermost
3345     quoting level.  If the -p option is given, quoting is done as if
3346     there is some prefix before the values of the parameters, so that
3347     a leading equal sign will not be quoted.
3348
3349     The return status is non-zero in case of an error and zero
3350     otherwise.
3351
3352comptags
3353comptry
3354     These implement the internals of the tags mechanism.
3355
3356compvalues
3357     Like comparguments, but for the _values function.
3358
3359
3360
3361File: zsh.info,  Node: The zsh/curses Module,  Next: The zsh/datetime Module,  Prev: The zsh/computil Module,  Up: Zsh Modules
3362
336322.9 The zsh/curses Module
3364==========================
3365
3366
3367
3368   The zsh/curses module makes available one builtin command and
3369various parameters.
3370
3371
3372
337322.9.1 Builtin
3374--------------
3375
3376
3377zcurses init
3378zcurses end
3379zcurses addwin TARGETWIN NLINES NCOLS BEGIN_Y BEGIN_X [ PARENTWIN ]
3380zcurses delwin TARGETWIN
3381zcurses refresh [ TARGETWIN ... ]
3382zcurses touch TARGETWIN ...
3383zcurses move TARGETWIN NEW_Y NEW_X
3384zcurses clear TARGETWIN [ redraw | eol | bot ]
3385zcurses position TARGETWIN ARRAY
3386zcurses char TARGETWIN CHARACTER
3387zcurses string TARGETWIN STRING
3388zcurses border TARGETWIN BORDER
3389zcurses attr TARGETWIN [ [+|-]ATTRIBUTE | FG_COL/BG_COL ] [...]
3390zcurses bg TARGETWIN [ [+|-]ATTRIBUTE | FG_COL/BG_COL | @CHAR ] [...]
3391zcurses scroll TARGETWIN [ on | off | [+|-]LINES ]
3392zcurses input TARGETWIN [ PARAM [ KPARAM [ MPARAM ] ] ]
3393zcurses mouse [ delay NUM | [+|-]motion ]
3394zcurses timeout TARGETWIN INTVAL
3395zcurses querychar TARGETWIN [ PARAM ]
3396zcurses resize HEIGHT WIDTH [ endwin | nosave | endwin_nosave ]
3397     Manipulate curses windows.  All uses of this command should be
3398     bracketed by `zcurses init' to initialise use of curses, and
3399     `zcurses end' to end it; omitting `zcurses end' can cause the
3400     terminal to be in an unwanted state.
3401
3402     The subcommand addwin creates a window with NLINES lines and NCOLS
3403     columns.  Its upper left corner will be placed at row BEGIN_Y and
3404     column BEGIN_X of the screen.  TARGETWIN is a string and refers to
3405     the name of a window that is not currently assigned.  Note in
3406     particular the curses convention that vertical values appear
3407     before horizontal values.
3408
3409     If addwin is given an existing window as the final argument, the
3410     new window is created as a subwindow of PARENTWIN.  This differs
3411     from an ordinary new window in that the memory of the window
3412     contents is shared with the parent's memory.  Subwindows must be
3413     deleted before their parent.  Note that the coordinates of
3414     subwindows are relative to the screen, not the parent, as with
3415     other windows.
3416
3417     Use the subcommand delwin to delete a window created with addwin.
3418     Note that end does _not_ implicitly delete windows, and that
3419     delwin does not erase the screen image of the window.
3420
3421     The window corresponding to the full visible screen is called
3422     stdscr; it always exists after `zcurses init' and cannot be delete
3423     with delwin.
3424
3425     The subcommand refresh will refresh window TARGETWIN; this is
3426     necessary to make any pending changes (such as characters you have
3427     prepared for output with char) visible on the screen.  refresh
3428     without an argument causes the screen to be cleared and redrawn.
3429     If multiple windows are given, the screen is updated once at the
3430     end.
3431
3432     The subcommand touch marks the TARGETWINs listed as changed.  This
3433     is necessary before refreshing windows if a window that was in
3434     front of another window (which may be stdscr) is deleted.
3435
3436     The subcommand move moves the cursor position in TARGETWIN to new
3437     coordinates NEW_Y and NEW_X.  Note that the subcommand string (but
3438     not the subcommand char) advances the cursor position over the
3439     characters added.
3440
3441     The subcommand clear erases the contents of TARGETWIN.  One (and
3442     no more than one) of three options may be specified.  With the
3443     option redraw, in addition the next refresh of TARGETWIN will
3444     cause the screen to be cleared and repainted.  With the option
3445     eol, TARGETWIN is only cleared to the end of the current cursor
3446     line.  With the option bot, TARGETWIN is cleared to the end of the
3447     window, i.e everything to the right and below the cursor is
3448     cleared.
3449
3450     The subcommand position writes various positions associated with
3451     TARGETWIN into the array named ARRAY.  These are, in order:
3452    -
3453          The y and x coordinates of the cursor relative to the top left
3454          of TARGETWIN
3455
3456    -
3457          The y and x coordinates of the top left of TARGETWIN on the
3458          screen
3459
3460    -
3461          The size of TARGETWIN in y and x dimensions.
3462
3463     Outputting characters and strings are achieved by char and string
3464     respectively.
3465
3466     To draw a border around window TARGETWIN, use border.  Note that
3467     the border is not subsequently handled specially:  in other words,
3468     the border is simply a set of characters output at the edge of the
3469     window.  Hence it can be overwritten, can scroll off the window,
3470     etc.
3471
3472     The subcommand attr will set TARGETWIN's attributes or
3473     foreground/background color pair for any successive character
3474     output.  Each ATTRIBUTE given on the line may be prepended by a +
3475     to set or a - to unset that attribute; + is assumed if absent.  The
3476     attributes supported are blink, bold, dim, reverse, standout, and
3477     underline.
3478
3479     Each FG_COL/BG_COL attribute (to be read as `FG_COL on BG_COL')
3480     sets the foreground and background color for character output.
3481     The color default is sometimes available (in particular if the
3482     library is ncurses), specifying the foreground or background color
3483     with which the terminal started.  The color pair default/default
3484     is always available. To use more than the 8 named colors (red,
3485     green, etc.) construct the FG_COL/BG_COL pairs where FG_COL and
3486     BG_COL are decimal integers, e.g 128/200.  The maximum color value
3487     is 254 if the terminal supports 256 colors.
3488
3489     bg overrides the color and other attributes of all characters in
3490     the window.  Its usual use is to set the background initially, but
3491     it will overwrite the attributes of any characters at the time
3492     when it is called.  In addition to the arguments allowed with
3493     attr, an argument @CHAR specifies a character to be shown in
3494     otherwise blank areas of the window.  Owing to limitations of
3495     curses this cannot be a multibyte character (use of ASCII
3496     characters only is recommended).  As the specified set of
3497     attributes override the existing background, turning attributes
3498     off in the arguments is not useful, though this does not cause an
3499     error.
3500
3501     The subcommand scroll can be used with on or off to enabled or
3502     disable scrolling of a window when the cursor would otherwise move
3503     below the window due to typing or output.  It can also be used
3504     with a positive or negative integer to scroll the window up or
3505     down the given number of lines without changing the current cursor
3506     position (which therefore appears to move in the opposite
3507     direction relative to the window).  In the second case, if
3508     scrolling is off it is temporarily turned on to allow the window
3509     to be scrolled.
3510
3511     The subcommand input reads a single character from the window
3512     without echoing it back.  If PARAM is supplied the character is
3513     assigned to the parameter PARAM, else it is assigned to the
3514     parameter REPLY.
3515
3516     If both PARAM and KPARAM are supplied, the key is read in `keypad'
3517     mode.  In this mode special keys such as function keys and arrow
3518     keys return the name of the key in the parameter KPARAM.  The key
3519     names are the macros defined in the curses.h or ncurses.h with the
3520     prefix `KEY_' removed; see also the description of the parameter
3521     zcurses_keycodes below.  Other keys cause a value to be set in
3522     PARAM as before.  On a successful return only one of PARAM or
3523     KPARAM contains a non-empty string; the other is set to an empty
3524     string.
3525
3526     If MPARAM is also supplied, input attempts to handle mouse input.
3527     This is only available with the ncurses library; mouse handling
3528     can be detected by checking for the exit status of `zcurses mouse'
3529     with no arguments.  If a mouse button is clicked (or double- or
3530     triple-clicked, or pressed or released with a configurable delay
3531     from being clicked) then kparam is set to the string MOUSE, and
3532     MPARAM is set to an array consisting of the following elements:
3533    -
3534          An identifier to discriminate different input devices; this
3535          is only rarely useful.
3536
3537    -
3538          The x, y and z coordinates of the mouse click relative to the
3539          full screen, as three elements in that order (i.e. the y
3540          coordinate is, unusually, after the x coordinate).  The z
3541          coordinate is only available for a few unusual input devices
3542          and is otherwise set to zero.
3543
3544    -
3545          Any events that occurred as separate items; usually there
3546          will be just one.  An event consists of PRESSED, RELEASED,
3547          CLICKED, DOUBLE_CLICKED or TRIPLE_CLICKED followed
3548          immediately (in the same element) by the number of the button.
3549
3550    -
3551          If the shift key was pressed, the string SHIFT.
3552
3553    -
3554          If the control key was pressed, the string CTRL.
3555
3556    -
3557          If the alt key was pressed, the string ALT.
3558
3559     Not all mouse events may be passed through to the terminal window;
3560     most terminal emulators handle some mouse events themselves.  Note
3561     that the ncurses manual implies that using input both with and
3562     without mouse handling may cause the mouse cursor to appear and
3563     disappear.
3564
3565     The subcommand mouse can be used to configure the use of the mouse.
3566     There is no window argument; mouse options are global.  `zcurses
3567     mouse' with no arguments returns status 0 if mouse handling is
3568     possible, else status 1.  Otherwise, the possible arguments (which
3569     may be combined on the same command line) are as follows.  delay
3570     NUM sets the maximum delay in milliseconds between press and
3571     release events to be considered as a click; the value 0 disables
3572     click resolution, and the default is one sixth of a second.
3573     motion proceeded by an optional `+' (the default) or - turns on or
3574     off reporting of mouse motion in addition to clicks, presses and
3575     releases, which are always reported.  However, it appears reports
3576     for mouse motion are not currently implemented.
3577
3578     The subcommand timeout specifies a timeout value for input from
3579     TARGETWIN.  If INTVAL is negative, `zcurses input' waits
3580     indefinitely for a character to be typed; this is the default.  If
3581     INTVAL is zero, `zcurses input' returns immediately; if there is
3582     typeahead it is returned, else no input is done and status 1 is
3583     returned.  If INTVAL is positive, `zcurses input' waits INTVAL
3584     milliseconds for input and if there is none at the end of that
3585     period returns status 1.
3586
3587     The subcommand querychar queries the character at the current
3588     cursor position.  The return values are stored in the array named
3589     PARAM if supplied, else in the array reply.  The first value is
3590     the character (which may be a multibyte character if the system
3591     supports them); the second is the color pair in the usual
3592     FG_COL/BG_COL notation, or 0 if color is not supported.  Any
3593     attributes other than color that apply to the character, as set
3594     with the subcommand attr, appear as additional elements.
3595
3596     The subcommand resize resizes stdscr and all windows to given
3597     dimensions (windows that stick out from the new dimensions are
3598     resized down). The underlying curses extension (resize_term call)
3599     can be unavailable. To verify, zeroes can be used for HEIGHT and
3600     WIDTH. If the result of the subcommand is 0, resize_term is
3601     available (2 otherwise). Tests show that resizing can be normally
3602     accomplished by calling zcurses end and zcurses refresh. The
3603     resize subcommand is provided for versatility. Multiple system
3604     configurations have been checked and zcurses end and zcurses
3605     refresh are still needed for correct terminal state after resize.
3606     To invoke them with resize, use ENDWIN argument.  Using NOSAVE
3607     argument will cause new terminal state to not be saved internally
3608     by zcurses. This is also provided for versatility and should
3609     normally be not needed.
3610
3611
3612
361322.9.2 Parameters
3614-----------------
3615
3616
3617ZCURSES_COLORS
3618     Readonly integer.  The maximum number of colors the terminal
3619     supports.  This value is initialised by the curses library and is
3620     not available until the first time zcurses init is run.
3621
3622ZCURSES_COLOR_PAIRS
3623     Readonly integer.  The maximum number of color pairs FG_COL/BG_COL
3624     that may be defined in `zcurses attr' commands; note this limit
3625     applies to all color pairs that have been used whether or not they
3626     are currently active.  This value is initialised by the curses
3627     library and is not available until the first time zcurses init is
3628     run.
3629
3630zcurses_attrs
3631     Readonly array.  The attributes supported by zsh/curses; available
3632     as soon as the module is loaded.
3633
3634zcurses_colors
3635     Readonly array.  The colors supported by zsh/curses; available as
3636     soon as the module is loaded.
3637
3638zcurses_keycodes
3639     Readonly array.  The values that may be returned in the second
3640     parameter supplied to `zcurses input' in the order in which they
3641     are defined internally by curses.  Not all function keys are
3642     listed, only F0; curses reserves space for F0 up to F63.
3643
3644zcurses_windows
3645     Readonly array.  The current list of windows, i.e. all windows that
3646     have been created with `zcurses addwin' and not removed with
3647     `zcurses delwin'.
3648
3649
3650
3651File: zsh.info,  Node: The zsh/datetime Module,  Next: The zsh/db/gdbm Module,  Prev: The zsh/curses Module,  Up: Zsh Modules
3652
365322.10 The zsh/datetime Module
3654=============================
3655
3656
3657
3658   The zsh/datetime module makes available one builtin command:
3659
3660
3661strftime [ -s SCALAR ] FORMAT [ EPOCHTIME [ NANOSECONDS ] ]
3662strftime -r [ -q ] [ -s SCALAR ] FORMAT TIMESTRING
3663     Output the date in the FORMAT specified.  With no EPOCHTIME, the
3664     current system date/time is used; optionally, EPOCHTIME may be
3665     used to specify the number of seconds since the epoch, and
3666     NANOSECONDS may additionally be used to specify the number of
3667     nanoseconds past the second (otherwise that number is assumed to
3668     be 0).  See man page strftime(3) for details.  The zsh extensions
3669     described in *Note Prompt Expansion:: are also available.
3670
3671
3672    -q
3673          Run quietly; suppress printing of all error messages
3674          described below.  Errors for invalid EPOCHTIME values are
3675          always printed.
3676
3677    -r
3678          With the option -r (reverse), use FORMAT to parse the input
3679          string TIMESTRING and output the number of seconds since the
3680          epoch at which the time occurred.  The parsing is implemented
3681          by the system function strptime; see man page strptime(3).
3682          This means that zsh format extensions are not available, but
3683          for reverse lookup they are not required.
3684
3685          In most implementations of strftime any timezone in the
3686          TIMESTRING is ignored and the local timezone declared by the
3687          TZ environment variable is used; other parameters are set to
3688          zero if not present.
3689
3690          If TIMESTRING does not match FORMAT the command returns
3691          status 1 and prints an error message.  If TIMESTRING matches
3692          FORMAT but not all characters in TIMESTRING were used, the
3693          conversion succeeds but also prints an error message.
3694
3695          If either of the system functions strptime or mktime is not
3696          available, status 2 is returned and an error message is
3697          printed.
3698
3699    -s SCALAR
3700          Assign the date string (or epoch time in seconds if -r is
3701          given) to SCALAR instead of printing it.
3702
3703
3704     Note that depending on the system's declared integral time type,
3705     strftime may produce incorrect results for epoch times greater than
3706     2147483647 which corresponds to 2038-01-19 03:14:07 +0000.
3707
3708
3709The zsh/datetime module makes available several parameters; all are
3710readonly:
3711
3712
3713EPOCHREALTIME
3714     A floating point value representing the number of seconds since
3715     the epoch.  The notional accuracy is to nanoseconds if the
3716     clock_gettime call is available and to microseconds otherwise, but
3717     in practice the range of double precision floating point and shell
3718     scheduling latencies may be significant effects.
3719
3720EPOCHSECONDS
3721     An integer value representing the number of seconds since the
3722     epoch.
3723
3724epochtime
3725     An array value containing the number of seconds since the epoch in
3726     the first element and the remainder of the time since the epoch in
3727     nanoseconds in the second element.  To ensure the two elements are
3728     consistent the array should be copied or otherwise referenced as a
3729     single substitution before the values are used.  The following
3730     idiom may be used:
3731
3732
3733          for secs nsecs in $epochtime; do
3734            ...
3735          done
3736
3737
3738
3739
3740File: zsh.info,  Node: The zsh/db/gdbm Module,  Next: The zsh/deltochar Module,  Prev: The zsh/datetime Module,  Up: Zsh Modules
3741
374222.11 The zsh/db/gdbm Module
3743============================
3744
3745
3746
3747   The zsh/db/gdbm module is used to create "tied" associative arrays
3748that interface to database files.  If the GDBM interface is not
3749available, the builtins defined by this module will report an error.
3750This module is also intended as a prototype for creating additional
3751database interfaces, so the ztie builtin may move to a more generic
3752module in the future.
3753
3754The builtins in this module are:
3755
3756
3757ztie -d db/gdbm -f FILENAME [ -r ] ARRAYNAME
3758     Open the GDBM database identified by FILENAME and, if successful,
3759     create the associative array ARRAYNAME linked to the file.  To
3760     create a local tied array, the parameter must first be declared,
3761     so commands similar to the following would be executed inside a
3762     function scope:
3763
3764
3765          local -A sampledb
3766          ztie -d db/gdbm -f sample.gdbm sampledb
3767
3768     The -r option opens the database file for reading only, creating a
3769     parameter with the readonly attribute.  Without this option, using
3770     `ztie' on a file for which the user does not have write permission
3771     is an error.  If writable, the database is opened synchronously so
3772     fields changed in ARRAYNAME are immediately written to FILENAME.
3773
3774     Changes to the file modes FILENAME after it has been opened do not
3775     alter the state of ARRAYNAME, but `typeset -r ARRAYNAME' works as
3776     expected.
3777
3778zuntie [ -u ] ARRAYNAME ...
3779     Close the GDBM database associated with each ARRAYNAME and then
3780     unset the parameter.  The -u option forces an unset of parameters
3781     made readonly with `ztie -r'.
3782
3783     This happens automatically if the parameter is explicitly unset or
3784     its local scope (function) ends.  Note that a readonly parameter
3785     may not be explicitly unset, so the only way to unset a global
3786     parameter created with `ztie -r' is to use `zuntie -u'.
3787
3788zgdbmpath PARAMETERNAME
3789     Put path to database file assigned to PARAMETERNAME into REPLY
3790     scalar.
3791
3792zgdbm_tied
3793     Array holding names of all tied parameters.
3794
3795
3796The fields of an associative array tied to GDBM are neither cached nor
3797otherwise stored in memory, they are read from or written to the
3798database on each reference.  Thus, for example, the values in a
3799readonly array may be changed by a second writer of the same database
3800file.
3801
3802
3803File: zsh.info,  Node: The zsh/deltochar Module,  Next: The zsh/example Module,  Prev: The zsh/db/gdbm Module,  Up: Zsh Modules
3804
380522.12 The zsh/deltochar Module
3806==============================
3807
3808
3809
3810   The zsh/deltochar module makes available two ZLE functions:
3811
3812
3813delete-to-char
3814     Read a character from the keyboard, and delete from the cursor
3815     position up to and including the next (or, with repeat count N,
3816     the Nth) instance of that character.  Negative repeat counts mean
3817     delete backwards.
3818
3819zap-to-char
3820     This behaves like delete-to-char, except that the final occurrence
3821     of the character itself is not deleted.
3822
3823
3824
3825File: zsh.info,  Node: The zsh/example Module,  Next: The zsh/files Module,  Prev: The zsh/deltochar Module,  Up: Zsh Modules
3826
382722.13 The zsh/example Module
3828============================
3829
3830
3831
3832   The zsh/example module makes available one builtin command:
3833
3834
3835example [ -flags ] [ ARGS ... ]
3836     Displays the flags and arguments it is invoked with.
3837
3838
3839The purpose of the module is to serve as an example of how to write a
3840module.
3841
3842
3843File: zsh.info,  Node: The zsh/files Module,  Next: The zsh/langinfo Module,  Prev: The zsh/example Module,  Up: Zsh Modules
3844
384522.14 The zsh/files Module
3846==========================
3847
3848
3849
3850   The zsh/files module makes available some common commands for file
3851manipulation as builtins; these commands are probably not needed for
3852many normal situations but can be useful in emergency recovery
3853situations with constrained resources.  The commands do not implement
3854all features now required by relevant standards committees.
3855
3856For all commands, a variant beginning zf_ is also available and loaded
3857automatically.  Using the features capability of zmodload will let you
3858load only those names you want.  Note that it's possible to load only
3859the builtins with zsh-specific names using the following command:
3860
3861
3862     zmodload -m -F zsh/files b:zf_\*
3863
3864The commands loaded by default are:
3865
3866
3867chgrp [ -hRs ] GROUP FILENAME ...
3868     Changes group of files specified.  This is equivalent to chown with
3869     a USER-SPEC argument of `:GROUP'.
3870
3871chmod [ -Rs ] MODE FILENAME ...
3872     Changes mode of files specified.
3873
3874     The specified MODE must be in octal.
3875
3876     The -R option causes chmod to recursively descend into directories,
3877     changing the mode of all files in the directory after changing the
3878     mode of the directory itself.
3879
3880     The -s option is a zsh extension to chmod functionality.  It
3881     enables paranoid behaviour, intended to avoid security problems
3882     involving a chmod being tricked into affecting files other than
3883     the ones intended.  It will refuse to follow symbolic links, so
3884     that (for example) ``chmod 600 /tmp/foo/passwd'' can't
3885     accidentally chmod /etc/passwd if /tmp/foo happens to be a link to
3886     /etc.  It will also check where it is after leaving directories,
3887     so that a recursive chmod of a deep directory tree can't end up
3888     recursively chmoding /usr as a result of directories being moved
3889     up the tree.
3890
3891chown [ -hRs ] USER-SPEC FILENAME ...
3892     Changes ownership and group of files specified.
3893
3894     The USER-SPEC can be in four forms:
3895
3896
3897    USER
3898          change owner to USER; do not change group
3899
3900    USER::
3901          change owner to USER; do not change group
3902
3903    USER:
3904          change owner to USER; change group to USER's primary group
3905
3906    USER:GROUP
3907          change owner to USER; change group to GROUP
3908
3909    :GROUP
3910          do not change owner; change group to GROUP
3911
3912     In each case, the `:' may instead be a `.'.  The rule is that if
3913     there is a `:' then the separator is `:', otherwise if there is a
3914     `.' then the separator is `.', otherwise there is no separator.
3915
3916     Each of USER and GROUP may be either a username (or group name, as
3917     appropriate) or a decimal user ID (group ID).  Interpretation as a
3918     name takes precedence, if there is an all-numeric username (or
3919     group name).
3920
3921     If the target is a symbolic link, the -h option causes chown to set
3922     the ownership of the link instead of its target.
3923
3924     The -R option causes chown to recursively descend into directories,
3925     changing the ownership of all files in the directory after
3926     changing the ownership of the directory itself.
3927
3928     The -s option is a zsh extension to chown functionality.  It
3929     enables paranoid behaviour, intended to avoid security problems
3930     involving a chown being tricked into affecting files other than
3931     the ones intended.  It will refuse to follow symbolic links, so
3932     that (for example) ``chown luser /tmp/foo/passwd'' can't
3933     accidentally chown /etc/passwd if /tmp/foo happens to be a link to
3934     /etc.  It will also check where it is after leaving directories,
3935     so that a recursive chown of a deep directory tree can't end up
3936     recursively chowning /usr as a result of directories being moved
3937     up the tree.
3938
3939ln [ -dfhins ] FILENAME DEST
3940ln [ -dfhins ] FILENAME ... DIR
3941     Creates hard (or, with -s, symbolic) links.  In the first form, the
3942     specified DESTination is created, as a link to the specified
3943     FILENAME.  In the second form, each of the FILENAMEs is taken in
3944     turn, and linked to a pathname in the specified DIRectory that has
3945     the same last pathname component.
3946
3947     Normally, ln will not attempt to create hard links to directories.
3948     This check can be overridden using the -d option.  Typically only
3949     the super-user can actually succeed in creating hard links to
3950     directories.  This does not apply to symbolic links in any case.
3951
3952     By default, existing files cannot be replaced by links.  The -i
3953     option causes the user to be queried about replacing existing
3954     files.  The -f option causes existing files to be silently
3955     deleted, without querying.  -f takes precedence.
3956
3957     The -h and -n options are identical and both exist for
3958     compatibility; either one indicates that if the target is a symlink
3959     then it should not be dereferenced.  Typically this is used in
3960     combination with -sf so that if an existing link points to a
3961     directory then it will be removed, instead of followed.  If this
3962     option is used with multiple filenames and the target is a
3963     symbolic link pointing to a directory then the result is an error.
3964
3965mkdir [ -p ] [ -m MODE ] DIR ...
3966     Creates directories.  With the -p option, non-existing parent
3967     directories are first created if necessary, and there will be no
3968     complaint if the directory already exists.  The -m option can be
3969     used to specify (in octal) a set of file permissions for the
3970     created directories, otherwise mode 777 modified by the current
3971     umask (see man page umask(2)) is used.
3972
3973mv [ -fi ] FILENAME DEST
3974mv [ -fi ] FILENAME ... DIR
3975     Moves files.  In the first form, the specified FILENAME is moved
3976     to the specified DESTination.  In the second form, each of the
3977     FILENAMEs is taken in turn, and moved to a pathname in the
3978     specified DIRectory that has the same last pathname component.
3979
3980     By default, the user will be queried before replacing any file
3981     that the user cannot write to, but writable files will be silently
3982     removed.  The -i option causes the user to be queried about
3983     replacing any existing files.  The -f option causes any existing
3984     files to be silently deleted, without querying.  -f takes
3985     precedence.
3986
3987     Note that this mv will not move files across devices.  Historical
3988     versions of mv, when actual renaming is impossible, fall back on
3989     copying and removing files; if this behaviour is desired, use cp
3990     and rm manually.  This may change in a future version.
3991
3992rm [ -dfiRrs ] FILENAME ...
3993     Removes files and directories specified.
3994
3995     Normally, rm will not remove directories (except with the -R or -r
3996     options).  The -d option causes rm to try removing directories
3997     with unlink (see man page unlink(2)), the same method used for
3998     files.  Typically only the super-user can actually succeed in
3999     unlinking directories in this way.  -d takes precedence over -R
4000     and -r.
4001
4002     By default, the user will be queried before removing any file that
4003     the user cannot write to, but writable files will be silently
4004     removed.  The -i option causes the user to be queried about
4005     removing any files.  The -f option causes files to be silently
4006     deleted, without querying, and suppresses all error indications.
4007     -f takes precedence.
4008
4009     The -R and -r options cause rm to recursively descend into
4010     directories, deleting all files in the directory before removing
4011     the directory with the rmdir system call (see man page rmdir(2)).
4012
4013     The -s option is a zsh extension to rm functionality.  It enables
4014     paranoid behaviour, intended to avoid common security problems
4015     involving a root-run rm being tricked into removing files other
4016     than the ones intended.  It will refuse to follow symbolic links,
4017     so that (for example) ``rm /tmp/foo/passwd'' can't accidentally
4018     remove /etc/passwd if /tmp/foo happens to be a link to /etc.  It
4019     will also check where it is after leaving directories, so that a
4020     recursive removal of a deep directory tree can't end up
4021     recursively removing /usr as a result of directories being moved
4022     up the tree.
4023
4024rmdir DIR ...
4025     Removes empty directories specified.
4026
4027sync
4028     Calls the system call of the same name (see man page sync(2)),
4029     which flushes dirty buffers to disk.  It might return before the
4030     I/O has actually been completed.
4031
4032
4033
4034File: zsh.info,  Node: The zsh/langinfo Module,  Next: The zsh/mapfile Module,  Prev: The zsh/files Module,  Up: Zsh Modules
4035
403622.15 The zsh/langinfo Module
4037=============================
4038
4039
4040
4041   The zsh/langinfo module makes available one parameter:
4042
4043
4044langinfo
4045     An associative array that maps langinfo elements to their values.
4046
4047     Your implementation may support a number of the following keys:
4048
4049     CODESET, D_T_FMT, D_FMT, T_FMT, RADIXCHAR, THOUSEP, YESEXPR,
4050     NOEXPR, CRNCYSTR, ABDAY_{1..7}, DAY_{1..7}, ABMON_{1..12},
4051     MON_{1..12}, T_FMT_AMPM, AM_STR, PM_STR, ERA, ERA_D_FMT,
4052     ERA_D_T_FMT, ERA_T_FMT, ALT_DIGITS
4053
4054
4055
4056
4057File: zsh.info,  Node: The zsh/mapfile Module,  Next: The zsh/mathfunc Module,  Prev: The zsh/langinfo Module,  Up: Zsh Modules
4058
405922.16 The zsh/mapfile Module
4060============================
4061
4062
4063
4064   The zsh/mapfile module provides one special associative array
4065parameter of the same name.
4066
4067
4068mapfile
4069     This associative array takes as keys the names of files; the
4070     resulting value is the content of the file.  The value is treated
4071     identically to any other text coming from a parameter.  The value
4072     may also be assigned to, in which case the file in question is
4073     written (whether or not it originally existed); or an element may
4074     be unset, which will delete the file in question.  For example,
4075     `vared mapfile[myfile]' works as expected, editing the file
4076     `myfile'.
4077
4078     When the array is accessed as a whole, the keys are the names of
4079     files in the current directory, and the values are empty (to save
4080     a huge overhead in memory).  Thus ${(k)mapfile} has the same
4081     effect as the glob operator *(D), since files beginning with a dot
4082     are not special.  Care must be taken with expressions such as rm
4083     ${(k)mapfile}, which will delete every file in the current
4084     directory without the usual `rm *' test.
4085
4086     The parameter mapfile may be made read-only; in that case, files
4087     referenced may not be written or deleted.
4088
4089     A file may conveniently be read into an array as one line per
4090     element with the form `ARRAY=("${(f@)mapfile[FILENAME]}")'.  The
4091     double quotes and the `@' are necessary to prevent empty lines
4092     from being removed.  Note that if the file ends with a newline,
4093     the shell will split on the final newline, generating an additional
4094     empty field; this can be suppressed by using
4095     `ARRAY=("${(f@)${mapfile[FILENAME]%$'\n'}}")'.
4096
4097
4098
409922.16.1 Limitations
4100-------------------
4101
4102Although reading and writing of the file in question is efficiently
4103handled, zsh's internal memory management may be arbitrarily baroque;
4104however, mapfile is usually very much more efficient than anything
4105involving a loop.  Note in particular that the whole contents of the
4106file will always reside physically in memory when accessed (possibly
4107multiple times, due to standard parameter substitution operations).  In
4108particular, this means handling of sufficiently long files (greater
4109than the machine's swap space, or than the range of the pointer type)
4110will be incorrect.
4111
4112No errors are printed or flagged for non-existent, unreadable, or
4113unwritable files, as the parameter mechanism is too low in the shell
4114execution hierarchy to make this convenient.
4115
4116It is unfortunate that the mechanism for loading modules does not yet
4117allow the user to specify the name of the shell parameter to be given
4118the special behaviour.
4119
4120
4121File: zsh.info,  Node: The zsh/mathfunc Module,  Next: The zsh/nearcolor Module,  Prev: The zsh/mapfile Module,  Up: Zsh Modules
4122
412322.17 The zsh/mathfunc Module
4124=============================
4125
4126
4127
4128   The zsh/mathfunc module provides standard mathematical functions for
4129use when evaluating mathematical formulae.  The syntax agrees with
4130normal C and FORTRAN conventions, for example,
4131
4132
4133     (( f = sin(0.3) ))
4134
4135assigns the sine of 0.3 to the parameter f.
4136
4137Most functions take floating point arguments and return a floating point
4138value.  However, any necessary conversions from or to integer type will
4139be performed automatically by the shell.  Apart from atan with a second
4140argument and the abs, int and float functions, all functions behave as
4141noted in the manual page for the corresponding C function, except that
4142any arguments out of range for the function in question will be
4143detected by the shell and an error reported.
4144
4145The following functions take a single floating point argument: acos,
4146acosh, asin, asinh, atan, atanh, cbrt, ceil, cos, cosh, erf, erfc, exp,
4147expm1, fabs, floor, gamma, j0, j1, lgamma, log, log10, log1p, log2,
4148logb, sin, sinh, sqrt, tan, tanh, y0, y1.  The atan function can
4149optionally take a second argument, in which case it behaves like the C
4150function atan2.  The ilogb function takes a single floating point
4151argument, but returns an integer.
4152
4153The function signgam takes no arguments, and returns an integer, which
4154is the C variable of the same name, as described in man page gamma(3).
4155Note that it is therefore only useful immediately after a call to gamma
4156or lgamma.  Note also that `signgam()' and `signgam' are distinct
4157expressions.
4158
4159The functions min, max, and sum are defined not in this module but in
4160the zmathfunc autoloadable function, described in *Note Mathematical
4161Functions::.
4162
4163The following functions take two floating point arguments: copysign,
4164fmod, hypot, nextafter.
4165
4166The following take an integer first argument and a floating point second
4167argument: jn, yn.
4168
4169The following take a floating point first argument and an integer second
4170argument: ldexp, scalb.
4171
4172The function abs does not convert the type of its single argument; it
4173returns the absolute value of either a floating point number or an
4174integer.  The functions float and int convert their arguments into a
4175floating point or integer value (by truncation) respectively.
4176
4177Note that the C pow function is available in ordinary math evaluation
4178as the `**' operator and is not provided here.
4179
4180The function rand48 is available if your system's mathematical library
4181has the function erand48(3).  It returns a pseudo-random floating point
4182number between 0 and 1.  It takes a single string optional argument.
4183
4184If the argument is not present, the random number seed is initialised by
4185three calls to the rand(3) function -- this produces the same random
4186numbers as the next three values of $RANDOM.
4187
4188If the argument is present, it gives the name of a scalar parameter
4189where the current random number seed will be stored.  On the first
4190call, the value must contain at least twelve hexadecimal digits (the
4191remainder of the string is ignored), or the seed will be initialised in
4192the same manner as for a call to rand48 with no argument.  Subsequent
4193calls to rand48(PARAM) will then maintain the seed in the parameter
4194PARAM as a string of twelve hexadecimal digits, with no base signifier.
4195The random number sequences for different parameters are completely
4196independent, and are also independent from that used by calls to rand48
4197with no argument.
4198
4199For example, consider
4200
4201
4202     print $(( rand48(seed) ))
4203     print $(( rand48() ))
4204     print $(( rand48(seed) ))
4205
4206Assuming $seed does not exist, it will be initialised by the first
4207call.  In the second call, the default seed is initialised; note,
4208however, that because of the properties of rand() there is a
4209correlation between the seeds used for the two initialisations, so for
4210more secure uses, you should generate your own 12-byte seed.  The third
4211call returns to the same sequence of random numbers used in the first
4212call, unaffected by the intervening rand48().
4213
4214
4215File: zsh.info,  Node: The zsh/nearcolor Module,  Next: The zsh/newuser Module,  Prev: The zsh/mathfunc Module,  Up: Zsh Modules
4216
421722.18 The zsh/nearcolor Module
4218==============================
4219
4220
4221
4222   The zsh/nearcolor module replaces colours specified as hex triplets
4223with the nearest colour in the 88 or 256 colour palettes that are widely
4224used by terminal emulators.  By default, 24-bit true colour escape codes
4225are generated when colours are specified using hex triplets.  These are
4226not supported by all terminals.  The purpose of this module is to make
4227it easier to define colour preferences in a form that can work across a
4228range of terminal emulators.
4229
4230Aside from the default colour, the ANSI standard for terminal escape
4231codes provides for eight colours. The bright attribute brings this to
4232sixteen. These basic colours are commonly used in terminal applications
4233due to being widely supported. Expanded 88 and 256 colour palettes are
4234also common and, while the first sixteen colours vary somewhat between
4235terminals and configurations, these add a generally consistent and
4236predictable set of colours.
4237
4238In order to use the zsh/nearcolor module, it only needs to be loaded.
4239Thereafter, whenever a colour is specified using a hex triplet, it will
4240be compared against each of the available colours and the closest will
4241be selected. The first sixteen colours are never matched in this
4242process due to being unpredictable.
4243
4244It isn't possible to reliably detect support for true colour in the
4245terminal emulator. It is therefore recommended to be selective in
4246loading the zsh/nearcolor module. For example, the following checks the
4247COLORTERM environment variable:
4248
4249
4250     [[ $COLORTERM = *(24bit|truecolor)* ]] || zmodload zsh/nearcolor
4251
4252Note that some terminals accept the true color escape codes but map
4253them internally to a more limited palette in a similar manner to the
4254zsh/nearcolor module.
4255
4256
4257File: zsh.info,  Node: The zsh/newuser Module,  Next: The zsh/parameter Module,  Prev: The zsh/nearcolor Module,  Up: Zsh Modules
4258
425922.19 The zsh/newuser Module
4260============================
4261
4262
4263
4264   The zsh/newuser module is loaded at boot if it is available, the RCS
4265option is set, and the PRIVILEGED option is not set (all three are true
4266by default).  This takes place immediately after commands in the global
4267zshenv file (typically /etc/zshenv), if any, have been executed.  If
4268the module is not available it is silently ignored by the shell; the
4269module may safely be removed from $MODULE_PATH by the administrator if
4270it is not required.
4271
4272On loading, the module tests if any of the start-up files .zshenv,
4273.zprofile, .zshrc or .zlogin exist in the directory given by the
4274environment variable ZDOTDIR, or the user's home directory if that is
4275not set.  The test is not performed and the module halts processing if
4276the shell was in an emulation mode (i.e. had been invoked as some other
4277shell than zsh).
4278
4279If none of the start-up files were found, the module then looks for the
4280file newuser first in a sitewide directory, usually the parent
4281directory of the site-functions directory, and if that is not found the
4282module searches in a version-specific directory, usually the parent of
4283the functions directory containing version-specific functions.  (These
4284directories can be configured when zsh is built using the
4285-enable-site-scriptdir=DIR and -enable-scriptdir=DIR flags to
4286configure, respectively; the defaults are PREFIX/share/zsh and
4287PREFIX/share/zsh/$ZSH_VERSION where the default PREFIX is /usr/local.)
4288
4289If the file newuser is found, it is then sourced in the same manner as
4290a start-up file.  The file is expected to contain code to install
4291start-up files for the user, however any valid shell code will be
4292executed.
4293
4294The zsh/newuser module is then unconditionally unloaded.
4295
4296Note that it is possible to achieve exactly the same effect as the
4297zsh/newuser module by adding code to /etc/zshenv.  The module exists
4298simply to allow the shell to make arrangements for new users without
4299the need for intervention by package maintainers and system
4300administrators.
4301
4302The script supplied with the module invokes the shell function
4303zsh-newuser-install.  This may be invoked directly by the user even if
4304the zsh/newuser module is disabled.  Note, however, that if the module
4305is not installed the function will not be installed either.  The
4306function is documented in *Note User Configuration Functions::.
4307
4308
4309File: zsh.info,  Node: The zsh/parameter Module,  Next: The zsh/pcre Module,  Prev: The zsh/newuser Module,  Up: Zsh Modules
4310
431122.20 The zsh/parameter Module
4312==============================
4313
4314
4315
4316   The zsh/parameter module gives access to some of the internal hash
4317tables used by the shell by defining some special parameters.
4318
4319
4320options
4321     The keys for this associative array are the names of the options
4322     that can be set and unset using the setopt and unsetopt builtins.
4323     The value of each key is either the string on if the option is
4324     currently set, or the string off if the option is unset.  Setting
4325     a key to one of these strings is like setting or unsetting the
4326     option, respectively. Unsetting a key in this array is like
4327     setting it to the value off.
4328
4329commands
4330     This array gives access to the command hash table. The keys are the
4331     names of external commands, the values are the pathnames of the
4332     files that would be executed when the command would be invoked.
4333     Setting a key in this array defines a new entry in this table in
4334     the same way as with the hash builtin. Unsetting a key as in `unset
4335     "commands[foo]"' removes the entry for the given key from the
4336     command hash table.
4337
4338functions
4339     This associative array maps names of enabled functions to their
4340     definitions. Setting a key in it is like defining a function with
4341     the name given by the key and the body given by the value.
4342     Unsetting a key removes the definition for the function named by
4343     the key.
4344
4345dis_functions
4346     Like functions but for disabled functions.
4347
4348functions_source
4349     This readonly associative array maps names of enabled functions to
4350     the name of the file containing the source of the function.
4351
4352     For an autoloaded function that has already been loaded, or marked
4353     for autoload with an absolute path, or that has had its path
4354     resolved with `functions -r', this is the file found for
4355     autoloading, resolved to an absolute path.
4356
4357     For a function defined within the body of a script or sourced file,
4358     this is the name of that file.  In this case, this is the exact
4359     path originally used to that file, which may be a relative path.
4360
4361     For any other function, including any defined at an interactive
4362     prompt or an autoload function whose path has not yet been
4363     resolved, this is the empty string.  However, the hash element is
4364     reported as defined just so long as the function is present:  the
4365     keys to this hash are the same as those to $functions.
4366
4367dis_functions_source
4368     Like functions_source but for disabled functions.
4369
4370builtins
4371     This associative array gives information about the builtin commands
4372     currently enabled. The keys are the names of the builtin commands
4373     and the values are either `undefined' for builtin commands that
4374     will automatically be loaded from a module if invoked or `defined'
4375     for builtin commands that are already loaded.
4376
4377dis_builtins
4378     Like builtins but for disabled builtin commands.
4379
4380reswords
4381     This array contains the enabled reserved words.
4382
4383dis_reswords
4384     Like reswords but for disabled reserved words.
4385
4386patchars
4387     This array contains the enabled pattern characters.
4388
4389dis_patchars
4390     Like patchars but for disabled pattern characters.
4391
4392aliases
4393     This maps the names of the regular aliases currently enabled to
4394     their expansions.
4395
4396dis_aliases
4397     Like aliases but for disabled regular aliases.
4398
4399galiases
4400     Like aliases, but for global aliases.
4401
4402dis_galiases
4403     Like galiases but for disabled global aliases.
4404
4405saliases
4406     Like raliases, but for suffix aliases.
4407
4408dis_saliases
4409     Like saliases but for disabled suffix aliases.
4410
4411parameters
4412     The keys in this associative array are the names of the parameters
4413     currently defined. The values are strings describing the type of
4414     the parameter, in the same format used by the t parameter flag, see
4415     *Note Parameter Expansion:: .  Setting or unsetting keys in this
4416     array is not possible.
4417
4418modules
4419     An associative array giving information about modules. The keys
4420     are the names of the modules loaded, registered to be autoloaded,
4421     or aliased. The value says which state the named module is in and
4422     is one of the strings `loaded', `autoloaded', or `alias:NAME',
4423     where NAME is the name the module is aliased to.
4424
4425     Setting or unsetting keys in this array is not possible.
4426
4427dirstack
4428     A normal array holding the elements of the directory stack. Note
4429     that the output of the dirs builtin command includes one more
4430     directory, the current working directory.
4431
4432history
4433     This associative array maps history event numbers to the full
4434     history lines.  Although it is presented as an associative array,
4435     the array of all values (${history[@]}) is guaranteed to be
4436     returned in order from most recent to oldest history event, that
4437     is, by decreasing history event number.
4438
4439historywords
4440     A special array containing the words stored in the history.  These
4441     also appear in most to least recent order.
4442
4443jobdirs
4444     This associative array maps job numbers to the directories from
4445     which the job was started (which may not be the current directory
4446     of the job).
4447
4448     The keys of the associative arrays are usually valid job numbers,
4449     and these are the values output with, for example, ${(k)jobdirs}.
4450     Non-numeric job references may be used when looking up a value;
4451     for example, ${jobdirs[%+]} refers to the current job.
4452
4453jobtexts
4454     This associative array maps job numbers to the texts of the
4455     command lines that were used to start the jobs.
4456
4457     Handling of the keys of the associative array is as described for
4458     jobdirs above.
4459
4460jobstates
4461     This associative array gives information about the states of the
4462     jobs currently known. The keys are the job numbers and the values
4463     are strings of the form `JOB-STATE:MARK:PID=STATE...'. The
4464     JOB-STATE gives the state the whole job is currently in, one of
4465     `running', `suspended', or `done'. The MARK is `+' for the current
4466     job, `-' for the previous job and empty otherwise. This is
4467     followed by one `:PID=STATE' for every process in the job. The
4468     PIDs are, of course, the process IDs and the STATE describes the
4469     state of that process.
4470
4471     Handling of the keys of the associative array is as described for
4472     jobdirs above.
4473
4474nameddirs
4475     This associative array maps the names of named directories to the
4476     pathnames they stand for.
4477
4478userdirs
4479     This associative array maps user names to the pathnames of their
4480     home directories.
4481
4482usergroups
4483     This associative array maps names of system groups of which the
4484     current user is a member to the corresponding group identifiers.
4485     The contents are the same as the groups output by the id command.
4486
4487funcfiletrace
4488     This array contains the absolute line numbers and corresponding
4489     file names for the point where the current function, sourced file,
4490     or (if EVAL_LINENO is set) eval command was called.  The array is
4491     of the same length as funcsourcetrace and functrace, but differs
4492     from funcsourcetrace in that the line and file are the point of
4493     call, not the point of definition, and differs from functrace in
4494     that all values are absolute line numbers in files, rather than
4495     relative to the start of a function, if any.
4496
4497funcsourcetrace
4498     This array contains the file names and line numbers of the points
4499     where the functions, sourced files, and (if EVAL_LINENO is set)
4500     eval commands currently being executed were defined.  The line
4501     number is the line where the `function NAME' or `NAME ()' started.
4502     In the case of an autoloaded function  the line number is
4503     reported as zero.  The format of each element is FILENAME:LINENO.
4504
4505     For functions autoloaded from a file in native zsh format, where
4506     only the body of the function occurs in the file, or for files
4507     that have been executed by the source or `.' builtins, the trace
4508     information is shown as FILENAME:0, since the entire file is the
4509     definition.  The source file name is resolved to an absolute path
4510     when the function is loaded or the path to it otherwise resolved.
4511
4512     Most users will be interested in the information in the
4513     funcfiletrace array instead.
4514
4515funcstack
4516     This array contains the names of the functions, sourced files, and
4517     (if EVAL_LINENO is set) eval commands. currently being executed.
4518     The first element is the name of the function using the parameter.
4519
4520     The standard shell array zsh_eval_context can be used to determine
4521     the type of shell construct being executed at each depth: note,
4522     however, that is in the opposite order, with the most recent item
4523     last, and it is more detailed, for example including an entry for
4524     toplevel, the main shell code being executed either interactively
4525     or from a script, which is not present in $funcstack.
4526
4527functrace
4528     This array contains the names and line numbers of the callers
4529     corresponding to the functions currently being executed.  The
4530     format of each element is NAME:LINENO.  Callers are also shown for
4531     sourced files; the caller is the point where the source or `.'
4532     command was executed.
4533
4534
4535
4536File: zsh.info,  Node: The zsh/pcre Module,  Next: The zsh/param/private Module,  Prev: The zsh/parameter Module,  Up: Zsh Modules
4537
453822.21 The zsh/pcre Module
4539=========================
4540
4541
4542
4543   The zsh/pcre module makes some commands available as builtins:
4544
4545
4546pcre_compile [ -aimxs ] PCRE
4547     Compiles a perl-compatible regular expression.
4548
4549     Option -a will force the pattern to be anchored.  Option -i will
4550     compile a case-insensitive pattern.  Option -m will compile a
4551     multi-line pattern; that is, ^ and $ will match newlines within
4552     the pattern.  Option -x will compile an extended pattern, wherein
4553     whitespace and # comments are ignored.  Option -s makes the dot
4554     metacharacter match all characters, including those that indicate
4555     newline.
4556
4557pcre_study
4558     Studies the previously-compiled PCRE which may result in faster
4559     matching.
4560
4561pcre_match [ -v VAR ] [ -a ARR ] [ -n OFFSET ] [ -b ] STRING
4562     Returns successfully if string matches the previously-compiled
4563     PCRE.
4564
4565     Upon successful match, if the expression captures substrings
4566     within parentheses, pcre_match will set the array match to those
4567     substrings, unless the -a option is given, in which case it will
4568     set the array ARR.  Similarly, the variable MATCH will be set to
4569     the entire matched portion of the string, unless the -v option is
4570     given, in which case the variable VAR will be set.  No variables
4571     are altered if there is no successful match.  A -n option starts
4572     searching for a match from the byte OFFSET position in STRING.  If
4573     the -b option is given, the variable ZPCRE_OP will be set to an
4574     offset pair string, representing the byte offset positions of the
4575     entire matched portion within the STRING.  For example, a ZPCRE_OP
4576     set to "32 45" indicates that the matched portion began on byte
4577     offset 32 and ended on byte offset 44.  Here, byte offset position
4578     45 is the position directly after the matched portion.  Keep in
4579     mind that the byte position isn't necessarily the same as the
4580     character position when UTF-8 characters are involved.
4581     Consequently, the byte offset positions are only to be relied on
4582     in the context of using them for subsequent searches on STRING,
4583     using an offset position as an argument to the -n option.  This is
4584     mostly used to implement the "find all non-overlapping matches"
4585     functionality.
4586
4587     A simple example of "find all non-overlapping matches":
4588
4589
4590          string="The following zip codes: 78884 90210 99513"
4591          pcre_compile -m "\d{5}"
4592          accum=()
4593          pcre_match -b -- $string
4594          while [[ $? -eq 0 ]] do
4595              b=($=ZPCRE_OP)
4596              accum+=$MATCH
4597              pcre_match -b -n $b[2] -- $string
4598          done
4599          print -l $accum
4600
4601
4602The zsh/pcre module makes available the following test condition:
4603
4604
4605EXPR -pcre-match PCRE
4606     Matches a string against a perl-compatible regular expression.
4607
4608     For example,
4609
4610
4611          [[ "$text" -pcre-match ^d+$ ]] &&
4612          print text variable contains only "d's".
4613
4614     If the REMATCH_PCRE option is set, the =~ operator is equivalent to
4615     -pcre-match, and the NO_CASE_MATCH option may be used.  Note that
4616     NO_CASE_MATCH never applies to the pcre_match builtin, instead use
4617     the -i switch of pcre_compile.
4618
4619
4620
4621File: zsh.info,  Node: The zsh/param/private Module,  Next: The zsh/regex Module,  Prev: The zsh/pcre Module,  Up: Zsh Modules
4622
462322.22 The zsh/param/private Module
4624==================================
4625
4626
4627
4628   The zsh/param/private module is used to create parameters whose scope
4629is limited to the current function body, and _not_ to other functions
4630called by the current function.
4631
4632This module provides a single autoloaded builtin:
4633
4634private [ {+|-}AHUahlprtux ] [ {+|-}EFLRZi [ N ] ] [ NAME[=VALUE] ... ]
4635     The private builtin accepts all the same options and arguments as
4636     local (*Note Shell Builtin Commands::) except for the `-T' option.
4637     Tied parameters may not be made private.
4638
4639     If used at the top level (outside a function scope), private
4640     creates a normal parameter in the same manner as declare or
4641     typeset.  A warning about this is printed if WARN_CREATE_GLOBAL is
4642     set (*Note Options::).  Used inside a function scope, private
4643     creates a local parameter similar to one declared with local,
4644     except having special properties noted below.
4645
4646     Special parameters which expose or manipulate internal shell
4647     state, such as ARGC, argv, COLUMNS, LINES, UID, EUID, IFS, PROMPT,
4648     RANDOM, SECONDS, etc., cannot be made private unless the `-h'
4649     option is used to hide the special meaning of the parameter.  This
4650     may change in the future.
4651
4652
4653As with other typeset equivalents, private is both a builtin and a
4654reserved word, so arrays may be assigned with parenthesized word list
4655NAME=(VALUE...) syntax.  However, the reserved word `private' is not
4656available until zsh/param/private is loaded, so care must be taken with
4657order of execution and parsing for function definitions which use
4658private.  To compensate for this, the module also adds the option `-P'
4659to the `local' builtin to declare private parameters.
4660
4661For example, this construction fails if zsh/param/private has not yet
4662been loaded when `bad_declaration' is defined:
4663     bad_declaration() {
4664       zmodload zsh/param/private
4665       private array=( one two three )
4666     }
4667
4668This construction works because local is already a keyword, and the
4669module is loaded before the statement is executed:
4670     good_declaration() {
4671       zmodload zsh/param/private
4672       local -P array=( one two three )
4673     }
4674
4675The following is usable in scripts but may have trouble with autoload:
4676     zmodload zsh/param/private
4677     iffy_declaration() {
4678       private array=( one two three )
4679     }
4680
4681The private builtin may always be used with scalar assignments and for
4682declarations without assignments.
4683
4684Parameters declared with private have the following properties:
4685
4686   * Within the function body where it is declared, the parameter
4687     behaves as a local, except as noted above for tied or special
4688     parameters.
4689
4690   * The type of a parameter declared private cannot be changed in the
4691     scope where it was declared, even if the parameter is unset.  Thus
4692     an array cannot be assigned to a private scalar, etc.
4693
4694   * Within any other function called by the declaring function, the
4695     private parameter does _NOT_ hide other parameters of the same
4696     name, so for example a global parameter of the same name is
4697     visible and may be assigned or unset.  This includes calls to
4698     anonymous functions, although that may also change in the future.
4699
4700   * An exported private remains in the environment of inner scopes but
4701     appears unset for the current shell in those scopes.  Generally,
4702     exporting private parameters should be avoided.
4703
4704Note that this differs from the static scope defined by compiled
4705languages derived from C, in that the a new call to the same function
4706creates a new scope, i.e., the parameter is still associated with the
4707call stack rather than with the function definition.  It differs from
4708ksh `typeset -S' because the syntax used to define the function has no
4709bearing on whether the parameter scope is respected.
4710
4711
4712File: zsh.info,  Node: The zsh/regex Module,  Next: The zsh/sched Module,  Prev: The zsh/param/private Module,  Up: Zsh Modules
4713
471422.23 The zsh/regex Module
4715==========================
4716
4717
4718
4719   The zsh/regex module makes available the following test condition:
4720
4721
4722EXPR -regex-match REGEX
4723     Matches a string against a POSIX extended regular expression.  On
4724     successful match, matched portion of the string will normally be
4725     placed in the MATCH variable.  If there are any capturing
4726     parentheses within the regex, then the match array variable will
4727     contain those.  If the match is not successful, then the variables
4728     will not be altered.
4729
4730     For example,
4731
4732
4733          [[ alphabetical -regex-match ^a([^a]+)a([^a]+)a ]] &&
4734          print -l $MATCH X $match
4735
4736     If the option REMATCH_PCRE is not set, then the =~ operator will
4737     automatically load this module as needed and will invoke the
4738     -regex-match operator.
4739
4740     If BASH_REMATCH is set, then the array BASH_REMATCH will be set
4741     instead of MATCH and match.
4742
4743
4744
4745File: zsh.info,  Node: The zsh/sched Module,  Next: The zsh/net/socket Module,  Prev: The zsh/regex Module,  Up: Zsh Modules
4746
474722.24 The zsh/sched Module
4748==========================
4749
4750
4751
4752   The zsh/sched module makes available one builtin command and one
4753parameter.
4754
4755
4756sched [-o] [+]HH:MM[:SS] COMMAND ...
4757sched [-o] [+]SECONDS COMMAND ...
4758sched [ -ITEM ]
4759     Make an entry in the scheduled list of commands to execute.  The
4760     time may be specified in either absolute or relative time, and
4761     either as hours, minutes and (optionally) seconds separated by a
4762     colon, or seconds alone.  An absolute number of seconds indicates
4763     the time since the epoch (1970/01/01 00:00); this is useful in
4764     combination with the features in the zsh/datetime module, see
4765     *Note The zsh/datetime Module::.
4766
4767     With no arguments, prints the list of scheduled commands.  If the
4768     scheduled command has the -o flag set, this is shown at the start
4769     of the command.
4770
4771     With the argument `-ITEM', removes the given item from the list.
4772     The numbering of the list is continuous and entries are in time
4773     order, so the numbering can change when entries are added or
4774     deleted.
4775
4776     Commands are executed either immediately before a prompt, or while
4777     the shell's line editor is waiting for input.  In the latter case
4778     it is useful to be able to produce output that does not interfere
4779     with the line being edited.  Providing the option -o causes the
4780     shell to clear the command line before the event and redraw it
4781     afterwards.  This should be used with any scheduled event that
4782     produces visible output to the terminal; it is not needed, for
4783     example, with output that updates a terminal emulator's title bar.
4784
4785     To effect changes to the editor buffer when an event executes, use
4786     the `zle' command with no arguments to test whether the editor is
4787     active, and if it is, then use `zle WIDGET' to access the editor
4788     via the named WIDGET.
4789
4790     The sched builtin is not made available by default when the shell
4791     starts in a mode emulating another shell.  It can be made available
4792     with the command `zmodload -F zsh/sched b:sched'.
4793
4794
4795
4796zsh_scheduled_events
4797     A readonly array corresponding to the events scheduled by the
4798     sched builtin.  The indices of the array correspond to the numbers
4799     shown when sched is run with no arguments (provided that the
4800     KSH_ARRAYS option is not set).  The value of the array consists of
4801     the scheduled time in seconds since the epoch (see *Note The
4802     zsh/datetime Module:: for facilities for using this number),
4803     followed by a colon, followed by any options (which may be empty
4804     but will be preceded by a `-' otherwise), followed by a colon,
4805     followed by the command to be executed.
4806
4807     The sched builtin should be used for manipulating the events.  Note
4808     that this will have an immediate effect on the contents of the
4809     array, so that indices may become invalid.
4810
4811
4812
4813File: zsh.info,  Node: The zsh/net/socket Module,  Next: The zsh/stat Module,  Prev: The zsh/sched Module,  Up: Zsh Modules
4814
481522.25 The zsh/net/socket Module
4816===============================
4817
4818
4819
4820   The zsh/net/socket module makes available one builtin command:
4821
4822
4823zsocket [ -altv ] [ -d FD ] [ ARGS ]
4824     zsocket is implemented as a builtin to allow full use of shell
4825     command line editing, file I/O, and job control mechanisms.
4826
4827
4828
482922.25.1 Outbound Connections
4830----------------------------
4831
4832
4833
4834
4835zsocket [ -v ] [ -d FD ] FILENAME
4836     Open a new Unix domain connection to FILENAME.  The shell
4837     parameter REPLY will be set to the file descriptor associated with
4838     that connection.  Currently, only stream connections are supported.
4839
4840     If -d is specified, its argument will be taken as the target file
4841     descriptor for the connection.
4842
4843     In order to elicit more verbose output, use -v.
4844
4845     File descriptors can be closed with normal shell syntax when no
4846     longer needed, for example:
4847
4848
4849          exec {REPLY}>&-
4850
4851
4852
485322.25.2 Inbound Connections
4854---------------------------
4855
4856
4857
4858
4859zsocket -l [ -v ] [ -d FD ] FILENAME
4860     zsocket -l will open a socket listening on FILENAME.  The shell
4861     parameter REPLY will be set to the file descriptor associated with
4862     that listener.  The file descriptor remains open in subshells and
4863     forked external executables.
4864
4865     If -d is specified, its argument will be taken as the target file
4866     descriptor for the connection.
4867
4868     In order to elicit more verbose output, use -v.
4869
4870zsocket -a [ -tv ] [ -d TARGETFD ] LISTENFD
4871     zsocket -a will accept an incoming connection to the socket
4872     associated with LISTENFD.  The shell parameter REPLY will be set
4873     to the file descriptor associated with the inbound connection.
4874     The file descriptor remains open in subshells and forked external
4875     executables.
4876
4877     If -d is specified, its argument will be taken as the target file
4878     descriptor for the connection.
4879
4880     If -t is specified, zsocket will return if no incoming connection
4881     is pending.  Otherwise it will wait for one.
4882
4883     In order to elicit more verbose output, use -v.
4884
4885
4886
4887File: zsh.info,  Node: The zsh/stat Module,  Next: The zsh/system Module,  Prev: The zsh/net/socket Module,  Up: Zsh Modules
4888
488922.26 The zsh/stat Module
4890=========================
4891
4892
4893
4894   The zsh/stat module makes available one builtin command under two
4895possible names:
4896
4897
4898zstat [ -gnNolLtTrs ] [ -f FD ] [ -H HASH ] [ -A ARRAY ] [ -F FMT ]
4899      [ +ELEMENT ] [ FILE ... ]
4900stat ...
4901     The command acts as a front end to the stat system call (see man
4902     page stat(2)).  The same command is provided with two names; as
4903     the name stat is often used by an external command it is
4904     recommended that only the zstat form of the command is used.  This
4905     can be arranged by loading the module with the command `zmodload
4906     -F zsh/stat b:zstat'.
4907
4908     If the stat call fails, the appropriate system error message
4909     printed and status 1 is returned.  The fields of struct stat give
4910     information about the files provided as arguments to the command.
4911     In addition to those available from the stat call, an extra
4912     element `link' is provided.  These elements are:
4913
4914
4915    device
4916          The number of the device on which the file resides.
4917
4918    inode
4919          The unique number of the file on this device (`_inode_'
4920          number).
4921
4922    mode
4923          The mode of the file; that is, the file's type and access
4924          permissions.  With the -s option, this will be returned as a
4925          string corresponding to the first column in the display of
4926          the ls -l command.
4927
4928    nlink
4929          The number of hard links to the file.
4930
4931    uid
4932          The user ID of the owner of the file.  With the -s option,
4933          this is displayed as a user name.
4934
4935    gid
4936          The group ID of the file.  With the -s option, this is
4937          displayed as a group name.
4938
4939    rdev
4940          The raw device number.  This is only useful for special
4941          devices.
4942
4943    size
4944          The size of the file in bytes.
4945
4946    atime
4947    mtime
4948    ctime
4949          The last access, modification and inode change times of the
4950          file, respectively, as the number of seconds since midnight
4951          GMT on 1st January, 1970.  With the -s option, these are
4952          printed as strings for the local time zone; the format can be
4953          altered with the -F option, and with the -g option the times
4954          are in GMT.
4955
4956    blksize
4957          The number of bytes in one allocation block on the device on
4958          which the file resides.
4959
4960    block
4961          The number of disk blocks used by the file.
4962
4963    link
4964          If the file is a link and the -L option is in effect, this
4965          contains the name of the file linked to, otherwise it is
4966          empty.  Note that if this element is selected (``zstat
4967          +link'') then the -L option is automatically used.
4968
4969
4970     A particular element may be selected by including its name
4971     preceded by a `+' in the option list; only one element is allowed.
4972     The element may be shortened to any unique set of leading
4973     characters.  Otherwise, all elements will be shown for all files.
4974
4975     Options:
4976
4977
4978    -A ARRAY
4979          Instead of displaying the results on standard output, assign
4980          them to an ARRAY, one struct stat element per array element
4981          for each file in order.  In this case neither the name of the
4982          element nor the name of the files appears in ARRAY unless the
4983          -t or -n options were given, respectively.  If -t is given,
4984          the element name appears as a prefix to the appropriate array
4985          element; if -n is given, the file name appears as a separate
4986          array element preceding all the others.  Other formatting
4987          options are respected.
4988
4989    -H HASH
4990          Similar to -A, but instead assign the values to HASH.  The
4991          keys are the elements listed above.  If the -n option is
4992          provided then the name of the file is included in the hash
4993          with key name.
4994
4995    -f FD
4996          Use the file on file descriptor FD instead of named files; no
4997          list of file names is allowed in this case.
4998
4999    -F FMT
5000          Supplies a strftime (see man page strftime(3)) string for the
5001          formatting of the time elements.  The format string supports
5002          all of the zsh extensions described in *Note Prompt
5003          Expansion::.  The -s option is implied.
5004
5005    -g
5006          Show the time elements in the GMT time zone.  The -s option
5007          is implied.
5008
5009    -l
5010          List the names of the type elements (to standard output or an
5011          array as appropriate) and return immediately; arguments, and
5012          options other than -A, are ignored.
5013
5014    -L
5015          Perform an lstat (see man page lstat(2)) rather than a stat
5016          system call.  In this case, if the file is a link, information
5017          about the link itself rather than the target file is returned.
5018          This option is required to make the link element useful.
5019          It's important to note that this is the exact opposite from
5020          man page ls(1), etc.
5021
5022    -n
5023          Always show the names of files.  Usually these are only shown
5024          when output is to standard output and there is more than one
5025          file in the list.
5026
5027    -N
5028          Never show the names of files.
5029
5030    -o
5031          If a raw file mode is printed, show it in octal, which is
5032          more useful for human consumption than the default of
5033          decimal.  A leading zero will be printed in this case.  Note
5034          that this does not affect whether a raw or formatted file
5035          mode is shown, which is controlled by the -r and -s options,
5036          nor whether a mode is shown at all.
5037
5038    -r
5039          Print raw data (the default format) alongside string data
5040          (the -s format); the string data appears in parentheses after
5041          the raw data.
5042
5043    -s
5044          Print mode, uid, gid and the three time elements as strings
5045          instead of numbers.  In each case the format is like that of
5046          ls -l.
5047
5048    -t
5049          Always show the type names for the elements of struct stat.
5050          Usually these are only shown when output is to standard
5051          output and no individual element has been selected.
5052
5053    -T
5054          Never show the type names of the struct stat elements.
5055
5056
5057
5058
5059File: zsh.info,  Node: The zsh/system Module,  Next: The zsh/net/tcp Module,  Prev: The zsh/stat Module,  Up: Zsh Modules
5060
506122.27 The zsh/system Module
5062===========================
5063
5064
5065
5066   The zsh/system module makes available various builtin commands and
5067parameters.
5068
5069
5070
507122.27.1 Builtins
5072----------------
5073
5074
5075syserror [ -e ERRVAR ] [ -p PREFIX ] [ ERRNO | ERRNAME ]
5076     This command prints out the error message associated with ERRNO, a
5077     system error number, followed by a newline to standard error.
5078
5079     Instead of the error number, a name ERRNAME, for example ENOENT,
5080     may be used.  The set of names is the same as the contents of the
5081     array errnos, see below.
5082
5083     If the string PREFIX is given, it is printed in front of the error
5084     message, with no intervening space.
5085
5086     If ERRVAR is supplied, the entire message, without a newline, is
5087     assigned to the parameter names ERRVAR and nothing is output.
5088
5089     A return status of 0 indicates the message was successfully printed
5090     (although it may not be useful if the error number was out of the
5091     system's range), a return status of 1 indicates an error in the
5092     parameters, and a return status of 2 indicates the error name was
5093     not recognised (no message is printed for this).
5094
5095sysopen [ -arw ] [ -m PERMISSIONS ] [ -o OPTIONS ]
5096        -u FD FILE
5097     This command opens a file. The -r, -w and -a flags indicate
5098     whether the file should be opened for reading, writing and
5099     appending, respectively. The -m option allows the initial
5100     permissions to use when creating a file to be specified in octal
5101     form.  The file descriptor is specified with -u. Either an
5102     explicit file descriptor in the range 0 to 9 can be specified or a
5103     variable name can be given to which the file descriptor number
5104     will be assigned.
5105
5106     The -o option allows various system specific options to be
5107     specified as a comma-separated list. The following is a list of
5108     possible options. Note that, depending on the system, some may not
5109     be available.
5110    cloexec
5111          mark file to be closed when other programs are executed (else
5112          the file descriptor remains open in subshells and forked
5113          external executables)
5114
5115    create
5116    creat
5117          create file if it does not exist
5118
5119    excl
5120          create file, error if it already exists
5121
5122    noatime
5123          suppress updating of the file atime
5124
5125    nofollow
5126          fail if FILE is a symbolic link
5127
5128    sync
5129          request that writes wait until data has been physically
5130          written
5131
5132    truncate
5133    trunc
5134          truncate file to size 0
5135
5136
5137     To close the file, use one of the following:
5138
5139
5140          exec {FD}<&-
5141          exec {FD}>&-
5142
5143sysread [ -c COUNTVAR ] [ -i INFD ] [ -o OUTFD ]
5144        [ -s BUFSIZE ] [ -t TIMEOUT ] [ PARAM ]
5145     Perform a single system read from file descriptor INFD, or zero if
5146     that is not given.  The result of the read is stored in PARAM or
5147     REPLY if that is not given.  If COUNTVAR is given, the number of
5148     bytes read is assigned to the parameter named by COUNTVAR.
5149
5150     The maximum number of bytes read is BUFSIZE or 8192 if that is not
5151     given, however the command returns as soon as any number of bytes
5152     was successfully read.
5153
5154     If TIMEOUT is given, it specifies a timeout in seconds, which may
5155     be zero to poll the file descriptor.  This is handled by the poll
5156     system call if available, otherwise the select system call if
5157     available.
5158
5159     If OUTFD is given, an attempt is made to write all the bytes just
5160     read to the file descriptor OUTFD.  If this fails, because of a
5161     system error other than EINTR or because of an internal zsh error
5162     during an interrupt, the bytes read but not written are stored in
5163     the parameter named by PARAM if supplied (no default is used in
5164     this case), and the number of bytes read but not written is stored
5165     in the parameter named by COUNTVAR if that is supplied.  If it was
5166     successful, COUNTVAR contains the full number of bytes transferred,
5167     as usual, and PARAM is not set.
5168
5169     The error EINTR (interrupted system call) is handled internally so
5170     that shell interrupts are transparent to the caller.  Any other
5171     error causes a return.
5172
5173     The possible return statuses are
5174    0
5175          At least one byte of data was successfully read and, if
5176          appropriate, written.
5177
5178    1
5179          There was an error in the parameters to the command.  This is
5180          the only error for which a message is printed to standard
5181          error.
5182
5183    2
5184          There was an error on the read, or on polling the input file
5185          descriptor for a timeout.  The parameter ERRNO gives the
5186          error.
5187
5188    3
5189          Data were successfully read, but there was an error writing
5190          them to OUTFD.  The parameter ERRNO gives the error.
5191
5192    4
5193          The attempt to read timed out.  Note this does not set ERRNO
5194          as this is not a system error.
5195
5196    5
5197          No system error occurred, but zero bytes were read.  This
5198          usually indicates end of file.  The parameters are set
5199          according to the usual rules; no write to OUTFD is attempted.
5200
5201
5202sysseek [ -u FD ] [ -w start|end|current ] OFFSET
5203     The current file position at which future reads and writes will
5204     take place is adjusted to the specified byte offset. The OFFSET is
5205     evaluated as a math expression. The -u option allows the file
5206     descriptor to be specified. By default the offset is specified
5207     relative to the start or the file but, with the -w option, it is
5208     possible to specify that the offset should be relative to the
5209     current position or the end of the file.
5210
5211syswrite [ -c COUNTVAR ] [ -o OUTFD ] DATA
5212     The data (a single string of bytes) are written to the file
5213     descriptor OUTFD, or 1 if that is not given, using the write
5214     system call.  Multiple write operations may be used if the first
5215     does not write all the data.
5216
5217     If COUNTVAR is given, the number of byte written is stored in the
5218     parameter named by COUNTVAR; this may not be the full length of
5219     DATA if an error occurred.
5220
5221     The error EINTR (interrupted system call) is handled internally by
5222     retrying; otherwise an error causes the command to return.  For
5223     example, if the file descriptor is set to non-blocking output, an
5224     error EAGAIN (on some systems, EWOULDBLOCK) may result in the
5225     command returning early.
5226
5227     The return status may be 0 for success, 1 for an error in the
5228     parameters to the command, or 2 for an error on the write; no
5229     error message is printed in the last case, but the parameter ERRNO
5230     will reflect the error that occurred.
5231
5232zsystem flock [ -t TIMEOUT ] [ -f VAR ] [-er] FILE
5233zsystem flock -u FD_EXPR
5234     The builtin zsystem's subcommand flock performs advisory file
5235     locking (via the man page fcntl(2) system call) over the entire
5236     contents of the given file.  This form of locking requires the
5237     processes accessing the file to cooperate; its most obvious use is
5238     between two instances of the shell itself.
5239
5240     In the first form the named FILE, which must already exist, is
5241     locked by opening a file descriptor to the file and applying a
5242     lock to the file descriptor.  The lock terminates when the shell
5243     process that created the lock exits; it is therefore often
5244     convenient to create file locks within subshells, since the lock
5245     is automatically released when the subshell exits.  Note that use
5246     of the print builtin with the -u option will, as a side effect,
5247     release the lock, as will redirection to the file in the shell
5248     holding the lock.  To work around this use a subshell, e.g.
5249     `(print message) >> FILE'.  Status 0 is returned if the lock
5250     succeeds, else status 1.
5251
5252     In the second form the file descriptor given by the arithmetic
5253     expression FD_EXPR is closed, releasing a lock.  The file
5254     descriptor can be queried by using the `-f VAR' form during the
5255     lock; on a successful lock, the shell variable VAR is set to the
5256     file descriptor used for locking.  The lock will be released if the
5257     file descriptor is closed by any other means, for example using
5258     `exec {VAR}>&-'; however, the form described here performs a
5259     safety check that the file descriptor is in use for file locking.
5260
5261     By default the shell waits indefinitely for the lock to succeed.
5262     The option -t TIMEOUT specifies a timeout for the lock in seconds;
5263     currently this must be an integer.  The shell will attempt to lock
5264     the file once a second during this period.  If the attempt times
5265     out, status 2 is returned.
5266
5267     If the option -e is given, the file descriptor for the lock is
5268     preserved when the shell uses exec to start a new process;
5269     otherwise it is closed at that point and the lock released.
5270
5271     If the option -r is given, the lock is only for reading, otherwise
5272     it is for reading and writing.  The file descriptor is opened
5273     accordingly.
5274
5275zsystem supports SUBCOMMAND
5276     The builtin zsystem's subcommand supports tests whether a given
5277     subcommand is supported.  It returns status 0 if so, else status
5278     1.  It operates silently unless there was a syntax error (i.e. the
5279     wrong number of arguments), in which case status 255 is returned.
5280     Status 1 can indicate one of two things:  SUBCOMMAND is known but
5281     not supported by the current operating system, or SUBCOMMAND is
5282     not known (possibly because this is an older version of the shell
5283     before it was implemented).
5284
5285
5286
528722.27.2 Math Functions
5288----------------------
5289
5290
5291systell(FD)
5292     The systell math function returns the current file position for
5293     the file descriptor passed as an argument.
5294
5295
5296
529722.27.3 Parameters
5298------------------
5299
5300
5301errnos
5302     A readonly array of the names of errors defined on the system.
5303     These are typically macros defined in C by including the system
5304     header file errno.h.  The index of each name (assuming the option
5305     KSH_ARRAYS is unset) corresponds to the error number.  Error
5306     numbers NUM before the last known error which have no name are
5307     given the name ENUM in the array.
5308
5309     Note that aliases for errors are not handled; only the canonical
5310     name is used.
5311
5312sysparams
5313     A readonly associative array.  The keys are:
5314
5315
5316    pid
5317          Returns the process ID of the current process, even in
5318          subshells.  Compare $$, which returns the process ID of the
5319          main shell process.
5320
5321    ppid
5322          Returns the process ID of the parent of the current process,
5323          even in subshells.  Compare $PPID, which returns the process
5324          ID of the parent of the main shell process.
5325
5326    procsubstpid
5327          Returns the process ID of the last process started for process
5328          substitution, i.e. the <(...) and >(...) expansions.
5329
5330
5331
5332
5333File: zsh.info,  Node: The zsh/net/tcp Module,  Next: The zsh/termcap Module,  Prev: The zsh/system Module,  Up: Zsh Modules
5334
533522.28 The zsh/net/tcp Module
5336============================
5337
5338
5339
5340   The zsh/net/tcp module makes available one builtin command:
5341
5342
5343ztcp [ -acflLtv ] [ -d FD ] [ ARGS ]
5344     ztcp is implemented as a builtin to allow full use of shell
5345     command line editing, file I/O, and job control mechanisms.
5346
5347     If ztcp is run with no options, it will output the contents of its
5348     session table.
5349
5350     If it is run with only the option -L, it will output the contents
5351     of the session table in a format suitable for automatic parsing.
5352     The option is ignored if given with a command to open or close a
5353     session.  The output consists of a set of lines, one per session,
5354     each containing the following elements separated by spaces:
5355
5356
5357    File descriptor
5358          The file descriptor in use for the connection.  For normal
5359          inbound (I) and outbound (O) connections this may be read and
5360          written by the usual shell mechanisms.  However, it should
5361          only be close with `ztcp -c'.
5362
5363    Connection type
5364          A letter indicating how the session was created:
5365
5366
5367         Z
5368               A session created with the zftp command.
5369
5370         L
5371               A connection opened for listening with `ztcp -l'.
5372
5373         I
5374               An inbound connection accepted with `ztcp -a'.
5375
5376         O
5377               An outbound connection created with `ztcp HOST ...'.
5378
5379
5380
5381    The local host
5382          This is usually set to an all-zero IP address as the address
5383          of the localhost is irrelevant.
5384
5385    The local port
5386          This is likely to be zero unless the connection is for
5387          listening.
5388
5389    The remote host
5390          This is the fully qualified domain name of the peer, if
5391          available, else an IP address.  It is an all-zero IP address
5392          for a session opened for listening.
5393
5394    The remote port
5395          This is zero for a connection opened for listening.
5396
5397
5398
5399
540022.28.1 Outbound Connections
5401----------------------------
5402
5403
5404
5405
5406ztcp [ -v ] [ -d FD ] HOST [ PORT ]
5407     Open a new TCP connection to HOST.  If the PORT is omitted, it
5408     will default to port 23.  The connection will be added to the
5409     session table and the shell parameter REPLY will be set to the
5410     file descriptor associated with that connection.
5411
5412     If -d is specified, its argument will be taken as the target file
5413     descriptor for the connection.
5414
5415     In order to elicit more verbose output, use -v.
5416
5417
5418
541922.28.2 Inbound Connections
5420---------------------------
5421
5422
5423
5424
5425ztcp -l [ -v ] [ -d FD ] PORT
5426     ztcp -l will open a socket listening on TCP PORT.  The socket will
5427     be added to the session table and the shell parameter REPLY will
5428     be set to the file descriptor associated with that listener.
5429
5430     If -d is specified, its argument will be taken as the target file
5431     descriptor for the connection.
5432
5433     In order to elicit more verbose output, use -v.
5434
5435ztcp -a [ -tv ] [ -d TARGETFD ] LISTENFD
5436     ztcp -a will accept an incoming connection to the port associated
5437     with LISTENFD.  The connection will be added to the session table
5438     and the shell parameter REPLY will be set to the file descriptor
5439     associated with the inbound connection.
5440
5441     If -d is specified, its argument will be taken as the target file
5442     descriptor for the connection.
5443
5444     If -t is specified, ztcp will return if no incoming connection is
5445     pending.  Otherwise it will wait for one.
5446
5447     In order to elicit more verbose output, use -v.
5448
5449
5450
545122.28.3 Closing Connections
5452---------------------------
5453
5454
5455
5456
5457ztcp -cf [ -v ] [ FD ]
5458ztcp -c [ -v ] [ FD ]
5459     ztcp -c will close the socket associated with FD.  The socket will
5460     be removed from the session table.  If FD is not specified, ztcp
5461     will close everything in the session table.
5462
5463     Normally, sockets registered by zftp (see *Note The zsh/zftp
5464     Module:: ) cannot be closed this way.  In order to force such a
5465     socket closed, use -f.
5466
5467     In order to elicit more verbose output, use -v.
5468
5469
5470
547122.28.4 Example
5472---------------
5473
5474Here is how to create a TCP connection between two instances of zsh.  We
5475need to pick an unassigned port; here we use the randomly chosen 5123.
5476
5477On host1,
5478     zmodload zsh/net/tcp
5479     ztcp -l 5123
5480     listenfd=$REPLY
5481     ztcp -a $listenfd
5482     fd=$REPLY
5483   The second from last command blocks until there is an incoming
5484connection.
5485
5486Now create a connection from host2 (which may, of course, be the same
5487machine):
5488     zmodload zsh/net/tcp
5489     ztcp host1 5123
5490     fd=$REPLY
5491
5492Now on each host, $fd contains a file descriptor for talking to the
5493other.  For example, on host1:
5494     print This is a message >&$fd
5495   and on host2:
5496     read -r line <&$fd; print -r - $line
5497   prints `This is a message'.
5498
5499To tidy up, on host1:
5500     ztcp -c $listenfd
5501     ztcp -c $fd
5502   and on host2
5503     ztcp -c $fd
5504
5505
5506File: zsh.info,  Node: The zsh/termcap Module,  Next: The zsh/terminfo Module,  Prev: The zsh/net/tcp Module,  Up: Zsh Modules
5507
550822.29 The zsh/termcap Module
5509============================
5510
5511
5512
5513   The zsh/termcap module makes available one builtin command:
5514
5515
5516echotc CAP [ ARG ... ]
5517     Output the termcap value corresponding to the capability CAP, with
5518     optional arguments.
5519
5520
5521The zsh/termcap module makes available one parameter:
5522
5523
5524termcap
5525     An associative array that maps termcap capability codes to their
5526     values.
5527
5528
5529
5530File: zsh.info,  Node: The zsh/terminfo Module,  Next: The zsh/zftp Module,  Prev: The zsh/termcap Module,  Up: Zsh Modules
5531
553222.30 The zsh/terminfo Module
5533=============================
5534
5535
5536
5537   The zsh/terminfo module makes available one builtin command:
5538
5539
5540echoti CAP [ ARG ]
5541     Output the terminfo value corresponding to the capability CAP,
5542     instantiated with ARG if applicable.
5543
5544
5545The zsh/terminfo module makes available one parameter:
5546
5547
5548terminfo
5549     An associative array that maps terminfo capability names to their
5550     values.
5551
5552
5553
5554File: zsh.info,  Node: The zsh/zftp Module,  Next: The zsh/zle Module,  Prev: The zsh/terminfo Module,  Up: Zsh Modules
5555
555622.31 The zsh/zftp Module
5557=========================
5558
5559
5560
5561   The zsh/zftp module makes available one builtin command:
5562
5563
5564zftp SUBCOMMAND [ ARGS ]
5565     The zsh/zftp module is a client for FTP (file transfer protocol).
5566     It is implemented as a builtin to allow full use of shell command
5567     line editing, file I/O, and job control mechanisms.  Often, users
5568     will access it via shell functions providing a more powerful
5569     interface; a set is provided with the zsh distribution and is
5570     described in *Note Zftp Function System::.  However, the zftp
5571     command is entirely usable in its own right.
5572
5573     All commands consist of the command name zftp followed by the name
5574     of a subcommand.  These are listed below.  The return status of
5575     each subcommand is supposed to reflect the success or failure of
5576     the remote operation.  See a description of the variable
5577     ZFTP_VERBOSE for more information on how responses from the server
5578     may be printed.
5579
5580
5581
558222.31.1 Subcommands
5583-------------------
5584
5585
5586
5587
5588open HOST[:PORT] [ USER [ PASSWORD [ ACCOUNT ] ] ]
5589     Open a new FTP session to HOST, which may be the name of a TCP/IP
5590     connected host or an IP number in the standard dot notation.  If
5591     the argument is in the form HOST:PORT, open a connection to TCP
5592     port PORT instead of the standard FTP port 21.  This may be the
5593     name of a TCP service or a number:  see the description of
5594     ZFTP_PORT below for more information.
5595
5596     If IPv6 addresses in colon format are used, the HOST should be
5597     surrounded by quoted square brackets to distinguish it from the
5598     PORT, for example '[fe80::203:baff:fe02:8b56]'.  For consistency
5599     this is allowed with all forms of HOST.
5600
5601     Remaining arguments are passed to the login subcommand.  Note that
5602     if no arguments beyond HOST are supplied, open will _not_
5603     automatically call login.  If no arguments at all are supplied,
5604     open will use the parameters set by the params subcommand.
5605
5606     After a successful open, the shell variables ZFTP_HOST, ZFTP_PORT,
5607     ZFTP_IP and ZFTP_SYSTEM are available; see `Variables' below.
5608
5609login [ NAME [ PASSWORD [ ACCOUNT ] ] ]
5610user [ NAME [ PASSWORD [ ACCOUNT ] ] ]
5611     Login the user NAME with parameters PASSWORD and ACCOUNT.  Any of
5612     the parameters can be omitted, and will be read from standard
5613     input if needed (NAME is always needed).  If standard input is a
5614     terminal, a prompt for each one will be printed on standard error
5615     and PASSWORD will not be echoed.  If any of the parameters are not
5616     used, a warning message is printed.
5617
5618     After a successful login, the shell variables ZFTP_USER,
5619     ZFTP_ACCOUNT and ZFTP_PWD are available; see `Variables' below.
5620
5621     This command may be re-issued when a user is already logged in, and
5622     the server will first be reinitialized for a new user.
5623
5624params [ HOST [ USER [ PASSWORD [ ACCOUNT ] ] ] ]
5625params -
5626     Store the given parameters for a later open command with no
5627     arguments.  Only those given on the command line will be
5628     remembered.  If no arguments are given, the parameters currently
5629     set are printed, although the password will appear as a line of
5630     stars; the return status is one if no parameters were set, zero
5631     otherwise.
5632
5633     Any of the parameters may be specified as a `?', which may need to
5634     be quoted to protect it from shell expansion.  In this case, the
5635     appropriate parameter will be read from stdin as with the login
5636     subcommand, including special handling of PASSWORD.  If the `?' is
5637     followed by a string, that is used as the prompt for reading the
5638     parameter instead of the default message (any necessary
5639     punctuation and whitespace should be included at the end of the
5640     prompt).  The first letter of the parameter (only) may be quoted
5641     with a `\'; hence an argument "\\$word" guarantees that the string
5642     from the shell parameter $word will be treated literally, whether
5643     or not it begins with a `?'.
5644
5645     If instead a single `-' is given, the existing parameters, if any,
5646     are deleted.  In that case, calling open with no arguments will
5647     cause an error.
5648
5649     The list of parameters is not deleted after a close, however it
5650     will be deleted if the zsh/zftp module is unloaded.
5651
5652     For example,
5653
5654
5655          zftp params ftp.elsewhere.xx juser '?Password for juser: '
5656
5657     will store the host ftp.elsewhere.xx and the user juser and then
5658     prompt the user for the corresponding password with the given
5659     prompt.
5660
5661test
5662     Test the connection; if the server has reported that it has closed
5663     the connection (maybe due to a timeout), return status 2; if no
5664     connection was open anyway, return status 1; else return status 0.
5665     The test subcommand is silent, apart from messages printed by the
5666     $ZFTP_VERBOSE mechanism, or error messages if the connection
5667     closes.  There is no network overhead for this test.
5668
5669     The test is only supported on systems with either the select(2) or
5670     poll(2) system calls; otherwise the message `not supported on this
5671     system' is printed instead.
5672
5673     The test subcommand will automatically be called at the start of
5674     any other subcommand for the current session when a connection is
5675     open.
5676
5677cd DIRECTORY
5678     Change the remote directory to DIRECTORY.  Also alters the shell
5679     variable ZFTP_PWD.
5680
5681cdup
5682     Change the remote directory to the one higher in the directory
5683     tree.  Note that cd .. will also work correctly on non-UNIX
5684     systems.
5685
5686dir [ ARG ... ]
5687     Give a (verbose) listing of the remote directory.  The ARGs are
5688     passed directly to the server. The command's behaviour is
5689     implementation dependent, but a UNIX server will typically
5690     interpret ARGs as arguments to the ls command and with no
5691     arguments return the result of `ls -l'. The directory is listed to
5692     standard output.
5693
5694ls [ ARG ... ]
5695     Give a (short) listing of the remote directory.  With no ARG,
5696     produces a raw list of the files in the directory, one per line.
5697     Otherwise, up to vagaries of the server implementation, behaves
5698     similar to dir.
5699
5700type [ TYPE ]
5701     Change the type for the transfer to TYPE, or print the current type
5702     if TYPE is absent.  The allowed values are `A' (ASCII), `I'
5703     (Image, i.e. binary), or `B' (a synonym for `I').
5704
5705     The FTP default for a transfer is ASCII.  However, if zftp finds
5706     that the remote host is a UNIX machine with 8-bit byes, it will
5707     automatically switch to using binary for file transfers upon open.
5708     This can subsequently be overridden.
5709
5710     The transfer type is only passed to the remote host when a data
5711     connection is established; this command involves no network
5712     overhead.
5713
5714ascii
5715     The same as type A.
5716
5717binary
5718     The same as type I.
5719
5720mode [ S | B ]
5721     Set the mode type to stream (S) or block (B).  Stream mode is the
5722     default; block mode is not widely supported.
5723
5724remote FILE ...
5725local [ FILE ... ]
5726     Print the size and last modification time of the remote or local
5727     files.  If there is more than one item on the list, the name of the
5728     file is printed first.  The first number is the file size, the
5729     second is the last modification time of the file in the format
5730     CCYYMMDDhhmmSS consisting of year, month, date, hour, minutes and
5731     seconds in GMT.  Note that this format, including the length, is
5732     guaranteed, so that time strings can be directly compared via the
5733     [[ builtin's < and > operators, even if they are too long to be
5734     represented as integers.
5735
5736     Not all servers support the commands for retrieving this
5737     information.  In that case, the remote command will print nothing
5738     and return status 2, compared with status 1 for a file not found.
5739
5740     The local command (but not remote) may be used with no arguments,
5741     in which case the information comes from examining file descriptor
5742     zero.  This is the same file as seen by a put command with no
5743     further redirection.
5744
5745get FILE ...
5746     Retrieve all FILEs from the server, concatenating them and sending
5747     them to standard output.
5748
5749put FILE ...
5750     For each FILE, read a file from standard input and send that to
5751     the remote host with the given name.
5752
5753append FILE ...
5754     As put, but if the remote FILE already exists, data is appended to
5755     it instead of overwriting it.
5756
5757getat FILE POINT
5758putat FILE POINT
5759appendat FILE POINT
5760     Versions of get, put and append which will start the transfer at
5761     the given POINT in the remote FILE.  This is useful for appending
5762     to an incomplete local file.  However, note that this ability is
5763     not universally supported by servers (and is not quite the
5764     behaviour specified by the standard).
5765
5766delete FILE ...
5767     Delete the list of files on the server.
5768
5769mkdir DIRECTORY
5770     Create a new directory DIRECTORY on the server.
5771
5772rmdir DIRECTORY
5773     Delete the directory DIRECTORY  on the server.
5774
5775rename OLD-NAME NEW-NAME
5776     Rename file OLD-NAME to NEW-NAME on the server.
5777
5778site ARG ...
5779     Send a host-specific command to the server.  You will probably
5780     only need this if instructed by the server to use it.
5781
5782quote ARG ...
5783     Send the raw FTP command sequence to the server.  You should be
5784     familiar with the FTP command set as defined in RFC959 before doing
5785     this.  Useful commands may include STAT and HELP.  Note also the
5786     mechanism for returning messages as described for the variable
5787     ZFTP_VERBOSE below, in particular that all messages from the
5788     control connection are sent to standard error.
5789
5790close
5791quit
5792     Close the current data connection.  This unsets the shell
5793     parameters ZFTP_HOST, ZFTP_PORT, ZFTP_IP, ZFTP_SYSTEM, ZFTP_USER,
5794     ZFTP_ACCOUNT, ZFTP_PWD, ZFTP_TYPE and ZFTP_MODE.
5795
5796session [ SESSNAME ]
5797     Allows multiple FTP sessions to be used at once.  The name of the
5798     session is an arbitrary string of characters; the default session
5799     is called `default'.  If this command is called without an
5800     argument, it will list all the current sessions; with an argument,
5801     it will either switch to the existing session called SESSNAME, or
5802     create a new session of that name.
5803
5804     Each session remembers the status of the connection, the set of
5805     connection-specific shell parameters (the same set as are unset
5806     when a connection closes, as given in the description of close),
5807     and any user parameters specified with the params subcommand.
5808     Changing to a previous session restores those values; changing to
5809     a new session initialises them in the same way as if zftp had just
5810     been loaded.  The name of the current session is given by the
5811     parameter ZFTP_SESSION.
5812
5813rmsession [ SESSNAME ]
5814     Delete a session; if a name is not given, the current session is
5815     deleted.  If the current session is deleted, the earliest existing
5816     session becomes the new current session, otherwise the current
5817     session is not changed.  If the session being deleted is the only
5818     one, a new session called `default' is created and becomes the
5819     current session; note that this is a new session even if the
5820     session being deleted is also called `default'. It is recommended
5821     that sessions not be deleted while background commands which use
5822     zftp are still active.
5823
5824
5825
582622.31.2 Parameters
5827------------------
5828
5829The following shell parameters are used by zftp.  Currently none of
5830them are special.
5831
5832
5833ZFTP_TMOUT
5834     Integer.  The time in seconds to wait for a network operation to
5835     complete before returning an error.  If this is not set when the
5836     module is loaded, it will be given the default value 60.  A value
5837     of zero turns off timeouts.  If a timeout occurs on the control
5838     connection it will be closed.  Use a larger value if this occurs
5839     too frequently.
5840
5841ZFTP_IP
5842     Readonly.  The IP address of the current connection in dot
5843     notation.
5844
5845ZFTP_HOST
5846     Readonly.  The hostname of the current remote server.  If the host
5847     was opened as an IP number, ZFTP_HOST contains that instead; this
5848     saves the overhead for a name lookup, as IP numbers are most
5849     commonly used when a nameserver is unavailable.
5850
5851ZFTP_PORT
5852     Readonly.  The number of the remote TCP port to which the
5853     connection is open (even if the port was originally specified as a
5854     named service).  Usually this is the standard FTP port, 21.
5855
5856     In the unlikely event that your system does not have the
5857     appropriate conversion functions, this appears in network byte
5858     order.  If your system is little-endian, the port then consists of
5859     two swapped bytes and the standard port will be reported as 5376.
5860     In that case, numeric ports passed to zftp open will also need to
5861     be in this format.
5862
5863ZFTP_SYSTEM
5864     Readonly.  The system type string returned by the server in
5865     response to an FTP SYST request.  The most interesting case is a
5866     string beginning "UNIX Type: L8", which ensures maximum
5867     compatibility with a local UNIX host.
5868
5869ZFTP_TYPE
5870     Readonly.  The type to be used for data transfers , either `A' or
5871     `I'.   Use the type subcommand to change this.
5872
5873ZFTP_USER
5874     Readonly.  The username currently logged in, if any.
5875
5876ZFTP_ACCOUNT
5877     Readonly.  The account name of the current user, if any.  Most
5878     servers do not require an account name.
5879
5880ZFTP_PWD
5881     Readonly.  The current directory on the server.
5882
5883ZFTP_CODE
5884     Readonly.  The three digit code of the last FTP reply from the
5885     server as a string.  This can still be read after the connection
5886     is closed, and is not changed when the current session changes.
5887
5888ZFTP_REPLY
5889     Readonly.  The last line of the last reply sent by the server.
5890     This can still be read after the connection is closed, and is not
5891     changed when the current session changes.
5892
5893ZFTP_SESSION
5894     Readonly.  The name of the current FTP session; see the
5895     description of the session subcommand.
5896
5897ZFTP_PREFS
5898     A string of preferences for altering aspects of zftp's behaviour.
5899     Each preference is a single character.  The following are defined:
5900
5901
5902    P
5903          Passive:  attempt to make the remote server initiate data
5904          transfers.  This is slightly more efficient than sendport
5905          mode.  If the letter S occurs later in the string, zftp will
5906          use sendport mode if passive mode is not available.
5907
5908    S
5909          Sendport:  initiate transfers by the FTP PORT command.  If
5910          this occurs before any P in the string, passive mode will
5911          never be attempted.
5912
5913    D
5914          Dumb:  use only the bare minimum of FTP commands.  This
5915          prevents the variables ZFTP_SYSTEM and ZFTP_PWD from being
5916          set, and will mean all connections default to ASCII type.  It
5917          may prevent ZFTP_SIZE from being set during a transfer if the
5918          server does not send it anyway (many servers do).
5919
5920
5921     If ZFTP_PREFS is not set when zftp is loaded, it will be set to a
5922     default of `PS', i.e. use passive mode if available, otherwise
5923     fall back to sendport mode.
5924
5925ZFTP_VERBOSE
5926     A string of digits between 0 and 5 inclusive, specifying which
5927     responses from the server should be printed.  All responses go to
5928     standard error.  If any of the numbers 1 to 5 appear in the string,
5929     raw responses from the server with reply codes beginning with that
5930     digit will be printed to standard error.  The first digit of the
5931     three digit reply code is defined by RFC959 to correspond to:
5932
5933
5934    1.
5935          A positive preliminary reply.
5936
5937    2.
5938          A positive completion reply.
5939
5940    3.
5941          A positive intermediate reply.
5942
5943    4.
5944          A transient negative completion reply.
5945
5946    5.
5947          A permanent negative completion reply.
5948
5949
5950     It should be noted that, for unknown reasons, the reply `Service
5951     not available', which forces termination of a connection, is
5952     classified as 421, i.e. `transient negative', an interesting
5953     interpretation of the word `transient'.
5954
5955     The code 0 is special:  it indicates that all but the last line of
5956     multiline replies read from the server will be printed to standard
5957     error in a processed format.  By convention, servers use this
5958     mechanism for sending information for the user to read.  The
5959     appropriate reply code, if it matches the same response, takes
5960     priority.
5961
5962     If ZFTP_VERBOSE is not set when zftp is loaded, it will be set to
5963     the default value 450, i.e., messages destined for the user and
5964     all errors will be printed.  A null string is valid and specifies
5965     that no messages should be printed.
5966
5967
5968
596922.31.3 Functions
5970-----------------
5971
5972
5973
5974
5975zftp_chpwd
5976     If this function is set by the user, it is called every time the
5977     directory changes on the server, including when a user is logged
5978     in, or when a connection is closed.  In the last case, $ZFTP_PWD
5979     will be unset; otherwise it will reflect the new directory.
5980
5981zftp_progress
5982     If this function is set by the user, it will be called during a
5983     get, put or append operation each time sufficient data has been
5984     received from the host.  During a get, the data is sent to
5985     standard output, so it is vital that this function should write to
5986     standard error or directly to the terminal, _not_ to standard
5987     output.
5988
5989     When it is called with a transfer in progress, the following
5990     additional shell parameters are set:
5991
5992
5993    ZFTP_FILE
5994          The name of the remote file being transferred from or to.
5995
5996    ZFTP_TRANSFER
5997          A G for a get operation and a P for a put operation.
5998
5999    ZFTP_SIZE
6000          The total size of the complete file being transferred: the
6001          same as the first value provided by the remote and local
6002          subcommands for a particular file.  If the server cannot
6003          supply this value for a remote file being retrieved, it will
6004          not be set.  If input is from a pipe the value may be
6005          incorrect and correspond simply to a full pipe buffer.
6006
6007    ZFTP_COUNT
6008          The amount of data so far transferred; a number between zero
6009          and $ZFTP_SIZE, if that is set.  This number is always
6010          available.
6011
6012
6013     The function is initially called with ZFTP_TRANSFER set
6014     appropriately and ZFTP_COUNT set to zero.  After the transfer is
6015     finished, the function will be called one more time with
6016     ZFTP_TRANSFER set to GF or PF, in case it wishes to tidy up.  It
6017     is otherwise never called twice with the same value of ZFTP_COUNT.
6018
6019     Sometimes the progress meter may cause disruption.  It is up to the
6020     user to decide whether the function should be defined and to use
6021     unfunction when necessary.
6022
6023
6024
602522.31.4 Problems
6026----------------
6027
6028
6029
6030A connection may not be opened in the left hand side of a pipe as this
6031occurs in a subshell and the file information is not updated in the main
6032shell.  In the case of type or mode changes or closing the connection
6033in a subshell, the information is returned but variables are not
6034updated until the next call to zftp.  Other status changes in subshells
6035will not be reflected by changes to the variables (but should be
6036otherwise harmless).
6037
6038Deleting sessions while a zftp command is active in the background can
6039have unexpected effects, even if it does not use the session being
6040deleted.  This is because all shell subprocesses share information on
6041the state of all connections, and deleting a session changes the
6042ordering of that information.
6043
6044On some operating systems, the control connection is not valid after a
6045fork(), so that operations in subshells, on the left hand side of a
6046pipeline, or in the background are not possible, as they should be.
6047This is presumably a bug in the operating system.
6048
6049
6050File: zsh.info,  Node: The zsh/zle Module,  Next: The zsh/zleparameter Module,  Prev: The zsh/zftp Module,  Up: Zsh Modules
6051
605222.32 The zsh/zle Module
6053========================
6054
6055
6056
6057   The zsh/zle module contains the Zsh Line Editor.  See *Note Zsh Line
6058Editor::.
6059
6060
6061File: zsh.info,  Node: The zsh/zleparameter Module,  Next: The zsh/zprof Module,  Prev: The zsh/zle Module,  Up: Zsh Modules
6062
606322.33 The zsh/zleparameter Module
6064=================================
6065
6066
6067
6068   The zsh/zleparameter module defines two special parameters that can
6069be used to access internal information of the Zsh Line Editor (see
6070*Note Zsh Line Editor::).
6071
6072
6073keymaps
6074     This array contains the names of the keymaps currently defined.
6075
6076widgets
6077     This associative array contains one entry per widget. The name of
6078     the widget is the key and the value gives information about the
6079     widget. It is either   the string `builtin' for builtin widgets,
6080     a string of the form `user:NAME' for user-defined widgets,
6081     where NAME is the name of the shell function implementing the
6082     widget,   a string of the form `completion:TYPE:NAME'     for
6083     completion widgets,   or a null value if the widget is not yet
6084     fully defined.  In the penultimate case, TYPE is the name of the
6085     builtin widget the completion widget imitates in its behavior and
6086     NAME is the name of the shell function implementing the completion
6087     widget.
6088
6089
6090
6091File: zsh.info,  Node: The zsh/zprof Module,  Next: The zsh/zpty Module,  Prev: The zsh/zleparameter Module,  Up: Zsh Modules
6092
609322.34 The zsh/zprof Module
6094==========================
6095
6096
6097
6098   When loaded, the zsh/zprof causes shell functions to be profiled.
6099The profiling results can be obtained with the zprof builtin command
6100made available by this module.  There is no way to turn profiling off
6101other than unloading the module.
6102
6103
6104zprof [ -c ]
6105     Without the -c option, zprof lists profiling results to standard
6106     output.  The format is comparable to that of commands like gprof.
6107
6108     At the top there is a summary listing all functions that were
6109     called at least once.  This summary is sorted in decreasing order
6110     of the amount of time spent in each.  The lines contain the number
6111     of the function in order, which is used in other parts of the list
6112     in suffixes of the form `[NUM]', then the number of calls made to
6113     the function.  The next three columns list the time in
6114     milliseconds spent in the function and its descendants, the average
6115     time in milliseconds spent in the function and its descendants per
6116     call and the percentage of time spent in all shell functions used
6117     in this function and its descendants.  The following three columns
6118     give the same information, but counting only the time spent in the
6119     function itself.  The final column shows the name of the function.
6120
6121     After the summary, detailed information about every function that
6122     was invoked is listed, sorted in decreasing order of the amount of
6123     time spent in each function and its descendants.  Each of these
6124     entries consists of descriptions for the functions that called the
6125     function described, the function itself, and the functions that
6126     were called from it.  The description for the function itself has
6127     the same format as in the summary (and shows the same
6128     information).  The other lines don't show the number of the
6129     function at the beginning and have their function named indented to
6130     make it easier to distinguish the line showing the function
6131     described in the section from the surrounding lines.
6132
6133     The information shown in this case is almost the same as in the
6134     summary, but only refers to the call hierarchy being displayed.
6135     For example, for a calling function the column showing the total
6136     running time lists the time spent in the described function and
6137     its descendants only for the times when it was called from that
6138     particular calling function.  Likewise, for a called function,
6139     this columns lists the total time spent in the called function and
6140     its descendants only for the times when it was called from the
6141     function described.
6142
6143     Also in this case, the column showing the number of calls to a
6144     function also shows a slash and then the total number of
6145     invocations made to the called function.
6146
6147     As long as the zsh/zprof module is loaded, profiling will be done
6148     and multiple invocations of the zprof builtin command will show the
6149     times and numbers of calls since the module was loaded.  With the
6150     -c option, the zprof builtin command will reset its internal
6151     counters and will not show the listing.
6152
6153
6154
6155File: zsh.info,  Node: The zsh/zpty Module,  Next: The zsh/zselect Module,  Prev: The zsh/zprof Module,  Up: Zsh Modules
6156
615722.35 The zsh/zpty Module
6158=========================
6159
6160
6161
6162   The zsh/zpty module offers one builtin:
6163
6164
6165zpty [ -e ] [ -b ] NAME [ ARG ... ]
6166     The arguments following NAME are concatenated with spaces between,
6167     then executed as a command, as if passed to the eval builtin.  The
6168     command runs under a newly assigned pseudo-terminal; this is
6169     useful for running commands non-interactively which expect an
6170     interactive environment.  The NAME is not part of the command, but
6171     is used to refer to this command in later calls to zpty.
6172
6173     With the -e option, the pseudo-terminal is set up so that input
6174     characters are echoed.
6175
6176     With the -b option, input to and output from the pseudo-terminal
6177     are made non-blocking.
6178
6179     The shell parameter REPLY is set to the file descriptor assigned to
6180     the master side of the pseudo-terminal.  This allows the terminal
6181     to be monitored with ZLE descriptor handlers (see *Note Zle
6182     Builtins::) or manipulated with sysread and syswrite (see *Note
6183     The zsh/system Module::).  _Warning_: Use of sysread and syswrite
6184     is _not_ recommended; use zpty -r and zpty -w unless you know
6185     exactly what you are doing.
6186
6187zpty -d [ NAME ... ]
6188     The second form, with the -d option, is used to delete commands
6189     previously started, by supplying a list of their NAMEs.  If no
6190     NAME is given, all commands are deleted.  Deleting a command causes
6191     the HUP signal to be sent to the corresponding process.
6192
6193zpty -w [ -n ] NAME [ STRING ... ]
6194     The -w option can be used to send the to command NAME the given
6195     STRINGs as input (separated by spaces).  If the -n option is _not_
6196     given, a newline is added at the end.
6197
6198     If no STRING is provided, the standard input is copied to the
6199     pseudo-terminal; this may stop before copying the full input if the
6200     pseudo-terminal is non-blocking.  The exact input is always copied:
6201     the -n option is not applied.
6202
6203     Note that the command under the pseudo-terminal sees this input as
6204     if it were typed, so beware when sending special tty driver
6205     characters such as word-erase, line-kill, and end-of-file.
6206
6207zpty -r [ -mt ] NAME [ PARAM [ PATTERN ] ]
6208     The -r option can be used to read the output of the command NAME.
6209     With only a NAME argument, the output read is copied to the
6210     standard output.  Unless the pseudo-terminal is non-blocking,
6211     copying continues until the command under the pseudo-terminal
6212     exits; when non-blocking, only as much output as is immediately
6213     available is copied.  The return status is zero if any output is
6214     copied.
6215
6216     When also given a PARAM argument, at most one line is read and
6217     stored in the parameter named PARAM.  Less than a full line may be
6218     read if the pseudo-terminal is non-blocking.  The return status is
6219     zero if at least one character is stored in PARAM.
6220
6221     If a PATTERN is given as well, output is read until the whole
6222     string read matches the PATTERN, even in the non-blocking case.
6223     The return status is zero if the string read matches the pattern,
6224     or if the command has exited but at least one character could
6225     still be read.  If the option -m is present, the return status is
6226     zero only if the pattern matches.  As of this writing, a maximum
6227     of one megabyte of output can be consumed this way; if a full
6228     megabyte is read without matching the pattern, the return status
6229     is non-zero.
6230
6231     In all cases, the return status is non-zero if nothing could be
6232     read, and is 2 if this is because the command has finished.
6233
6234     If the -r option is combined with the -t option, zpty tests
6235     whether output is available before trying to read.  If no output is
6236     available, zpty immediately returns the status 1.  When used with
6237     a PATTERN, the behaviour on a failed poll is similar to when the
6238     command has exited:  the return value is zero if at least one
6239     character could still be read even if the pattern failed to match.
6240
6241zpty -t NAME
6242     The -t option without the -r option can be used to test whether
6243     the command NAME is still running.  It returns a zero status if
6244     the command is running and a non-zero value otherwise.
6245
6246zpty [ -L ]
6247     The last form, without any arguments, is used to list the commands
6248     currently defined.  If the -L option is given, this is done in the
6249     form of calls to the zpty builtin.
6250
6251
6252
6253File: zsh.info,  Node: The zsh/zselect Module,  Next: The zsh/zutil Module,  Prev: The zsh/zpty Module,  Up: Zsh Modules
6254
625522.36 The zsh/zselect Module
6256============================
6257
6258
6259
6260   The zsh/zselect module makes available one builtin command:
6261
6262
6263zselect [ -rwe ] [ -t TIMEOUT ] [ -a ARRAY ] [ -A ASSOC ] [ FD ... ]
6264     The zselect builtin is a front-end to the `select' system call,
6265     which blocks until a file descriptor is ready for reading or
6266     writing, or has an error condition, with an optional timeout.  If
6267     this is not available on your system, the command prints an error
6268     message and returns status 2 (normal errors return status 1).  For
6269     more information, see your systems documentation for man page
6270     select(3).  Note there is no connection with the shell builtin of
6271     the same name.
6272
6273     Arguments and options may be intermingled in any order.  Non-option
6274     arguments are file descriptors, which must be decimal integers.  By
6275     default, file descriptors are to be tested for reading, i.e.
6276     zselect will return when data is available to be read from the
6277     file descriptor, or more precisely, when a read operation from the
6278     file descriptor will not block.  After a -r, -w and -e, the given
6279     file descriptors are to be tested for reading, writing, or error
6280     conditions.  These options and an arbitrary list of file
6281     descriptors may be given in any order.
6282
6283     (The presence of an `error condition' is not well defined in the
6284     documentation for many implementations of the select system call.
6285     According to recent versions of the POSIX specification, it is
6286     really an _exception_ condition, of which the only standard
6287     example is out-of-band data received on a socket.  So zsh users
6288     are unlikely to find the -e option useful.)
6289
6290     The option `-t TIMEOUT' specifies a timeout in hundredths of a
6291     second.  This may be zero, in which case the file descriptors will
6292     simply be polled and zselect will return immediately.  It is
6293     possible to call zselect with no file descriptors and a non-zero
6294     timeout for use as a finer-grained replacement for `sleep'; note,
6295     however, the return status is always 1 for a timeout.
6296
6297     The option `-a ARRAY' indicates that ARRAY should be set to
6298     indicate the file descriptor(s) which are ready.  If the option is
6299     not given, the array reply will be used for this purpose.  The
6300     array will contain a string similar to the arguments for zselect.
6301     For example,
6302
6303
6304          zselect -t 0 -r 0 -w 1
6305
6306     might return immediately with status 0 and $reply containing `-r 0
6307     -w 1' to show that both file descriptors are ready for the
6308     requested operations.
6309
6310     The option `-A ASSOC' indicates that the associative array ASSOC
6311     should be set to indicate the file descriptor(s) which are ready.
6312     This option overrides the option -a, nor will reply be modified.
6313     The keys of assoc are the file descriptors, and the corresponding
6314     values are any of the characters `rwe' to indicate the condition.
6315
6316     The command returns status 0 if some file descriptors are ready for
6317     reading.  If the operation timed out, or a timeout of 0 was given
6318     and no file descriptors were ready, or there was an error, it
6319     returns status 1 and the array will not be set (nor modified in
6320     any way).  If there was an error in the select operation the
6321     appropriate error message is printed.
6322
6323
6324
6325File: zsh.info,  Node: The zsh/zutil Module,  Prev: The zsh/zselect Module,  Up: Zsh Modules
6326
632722.37 The zsh/zutil Module
6328==========================
6329
6330
6331
6332   The zsh/zutil module only adds some builtins:
6333
6334
6335zstyle [ -L [ METAPATTERN [ STYLE ] ] ]
6336zstyle [ -e | - | -- ] PATTERN STYLE STRING ...
6337zstyle -d [ PATTERN [ STYLE ... ] ]
6338zstyle -g NAME [ PATTERN [ STYLE ] ]
6339zstyle -{a|b|s} CONTEXT STYLE NAME [ SEP ]
6340zstyle -{T|t} CONTEXT STYLE [ STRING ... ]
6341zstyle -m CONTEXT STYLE PATTERN
6342     This builtin command is used to define and lookup styles.  Styles
6343     are pairs of names and values, where the values consist of any
6344     number of strings.  They are stored together with patterns and
6345     lookup is done by giving a string, called the `_context_', which
6346     is matched against the patterns.  The definition stored for the
6347     most specific pattern that matches will be returned.
6348
6349     A pattern is considered to be more specific than another if it
6350     contains more components (substrings separated by colons) or if
6351     the patterns for the components are more specific, where simple
6352     strings are considered to be more specific than patterns and
6353     complex patterns are considered to be more specific than the
6354     pattern `*'.  A `*' in the pattern will match zero or more
6355     characters in the context; colons are not treated specially in
6356     this regard.  If two patterns are equally specific, the tie is
6357     broken in favour of the pattern that was defined first.
6358
6359     _Example_
6360
6361     For example, to define your preferred form of precipitation
6362     depending on which city you're in, you might set the following in
6363     your zshrc:
6364
6365
6366          zstyle ':weather:europe:*' preferred-precipitation rain
6367          zstyle ':weather:europe:germany:* preferred-precipitation none
6368          zstyle ':weather:europe:germany:*:munich' preferred-precipitation snow
6369
6370     Then, the fictional `weather' plugin might run under the hood a
6371     command such as
6372
6373
6374          zstyle -s ":weather:${continent}:${country}:${county}:${city}" preferred-precipitation REPLY
6375
6376     in order to retrieve your preference into the scalar variable
6377     $REPLY.
6378
6379     _Usage_
6380
6381     The forms that operate on patterns are the following.
6382
6383
6384    zstyle [ -L [ METAPATTERN [ STYLE ] ] ]
6385          Without arguments, lists style definitions.  Styles are shown
6386          in alphabetic order and patterns are shown in the order
6387          zstyle will test them.
6388
6389          If the -L option is given, listing is done in the form of
6390          calls to zstyle.  The optional first argument, METAPATTERN,
6391          is a pattern which will be matched against the string
6392          supplied as PATTERN when the style was defined.  Note: this
6393          means, for example, `zstyle -L ":completion:*"' will match
6394          any supplied pattern beginning `:completion:', not just
6395          ":completion:*":  use ':completion:\*' to match that.  The
6396          optional second argument limits the output to a specific
6397          STYLE (not a pattern).  -L is not compatible with any other
6398          options.
6399
6400    zstyle [ - | -- | -e ] PATTERN STYLE STRING ...
6401          Defines the given STYLE for the PATTERN with the STRINGs as
6402          the value.  If the -e option is given, the STRINGs will be
6403          concatenated (separated by spaces) and the resulting string
6404          will be evaluated (in the same way as it is done by the eval
6405          builtin command) when the style is looked up.  In this case
6406          the parameter `reply' must be assigned to set the strings
6407          returned after the evaluation.  Before evaluating the value,
6408          reply is unset, and if it is still unset after the
6409          evaluation, the style is treated as if it were not set.
6410
6411    zstyle -d [ PATTERN [ STYLE ... ] ]
6412          Delete style definitions. Without arguments all definitions
6413          are deleted, with a PATTERN all definitions for that pattern
6414          are deleted and if any STYLEs are given, then only those
6415          styles are deleted for the PATTERN.
6416
6417    zstyle -g NAME [ PATTERN [ STYLE ] ]
6418          Retrieve a style definition. The NAME is used as the name of
6419          an array in which the results are stored. Without any further
6420          arguments, all patterns defined are returned. With a PATTERN
6421          the styles defined for that pattern are returned and with
6422          both a PATTERN and a STYLE, the value strings of that
6423          combination is returned.
6424
6425
6426     The other forms can be used to look up or test styles for a given
6427     context.
6428
6429
6430    zstyle -s CONTEXT STYLE NAME [ SEP ]
6431          The parameter NAME is set to the value of the style
6432          interpreted as a string.  If the value contains several
6433          strings they are concatenated with spaces (or with the SEP
6434          string if that is given) between them.
6435
6436          Return 0 if the style is set, 1 otherwise.
6437
6438    zstyle -b CONTEXT STYLE NAME
6439          The value is stored in NAME as a boolean, i.e. as the string
6440          `yes' if the value has only one string and that string is
6441          equal to one of `yes', `true', `on', or `1'. If the value is
6442          any other string or has more than one string, the parameter
6443          is set to `no'.
6444
6445          Return 0 if NAME is set to `yes', 1 otherwise.
6446
6447    zstyle -a CONTEXT STYLE NAME
6448          The value is stored in NAME as an array. If NAME is declared
6449          as an associative array,  the first, third, etc. strings are
6450          used as the keys and the other strings are used as the values.
6451
6452          Return 0 if the style is set, 1 otherwise.
6453
6454    zstyle -t CONTEXT STYLE [ STRING ... ]
6455    zstyle -T CONTEXT STYLE [ STRING ... ]
6456          Test the value of a style, i.e. the -t option only returns a
6457          status (sets $?).  Without any STRING the return status is
6458          zero if the style is defined for at least one matching
6459          pattern, has only one string in its value, and that is equal
6460          to one of `true', `yes', `on' or `1'. If any STRINGs are
6461          given the status is zero if and only if at least one of the
6462          STRINGs is equal to at least one of the strings in the value.
6463          If the style is defined but doesn't match, the return status
6464          is 1. If the style is not defined, the status is 2.
6465
6466          The -T option tests the values of the style like -t, but it
6467          returns status zero (rather than 2) if the style is not
6468          defined for any matching pattern.
6469
6470    zstyle -m CONTEXT STYLE PATTERN
6471          Match a value. Returns status zero if the PATTERN matches at
6472          least one of the strings in the value.
6473
6474
6475zformat -f PARAM FORMAT SPEC ...
6476zformat -a ARRAY SEP SPEC ...
6477     This builtin provides two different forms of formatting. The first
6478     form is selected with the -f option. In this case the FORMAT
6479     string will be modified by replacing sequences starting with a
6480     percent sign in it with strings from the SPECs.  Each SPEC should
6481     be of the form `CHAR:STRING' which will cause every appearance of
6482     the sequence `%CHAR' in FORMAT to be replaced by the STRING.  The
6483     `%' sequence may also contain optional minimum and maximum field
6484     width specifications between the `%' and the `CHAR' in the form
6485     `%MIN.MAXc', i.e. the minimum field width is given first and if
6486     the maximum field width is used, it has to be preceded by a dot.
6487     Specifying a minimum field width makes the result be padded with
6488     spaces to the right if the STRING is shorter than the requested
6489     width.  Padding to the left can be achieved by giving a negative
6490     minimum field width.  If a maximum field width is specified, the
6491     STRING will be truncated after that many characters.  After all
6492     `%' sequences for the given SPECs have been processed, the
6493     resulting string is stored in the parameter PARAM.
6494
6495     The %-escapes also understand ternary expressions in the form used
6496     by prompts.  The % is followed by a `(' and then an ordinary
6497     format specifier character as described above.  There may be a set
6498     of digits either before or after the `('; these specify a test
6499     number, which defaults to zero.  Negative numbers are also
6500     allowed.  An arbitrary delimiter character follows the format
6501     specifier, which is followed by a piece of `true' text, the
6502     delimiter character again, a piece of `false' text, and a closing
6503     parenthesis.  The complete expression (without the digits) thus
6504     looks like `%(X.TEXT1.TEXT2)', except that the `.' character is
6505     arbitrary.  The value given for the format specifier in the
6506     CHAR:STRING expressions is evaluated as a mathematical expression,
6507     and compared with the test number.  If they are the same, TEXT1 is
6508     output, else TEXT2 is output.  A parenthesis may be escaped in
6509     TEXT2 as %).  Either of TEXT1 or TEXT2 may contain nested
6510     %-escapes.
6511
6512     For example:
6513
6514
6515          zformat -f REPLY "The answer is '%3(c.yes.no)'." c:3
6516
6517     outputs "The answer is 'yes'." to REPLY since the value for the
6518     format specifier c is 3, agreeing with the digit argument to the
6519     ternary expression.
6520
6521     The second form, using the -a option, can be used for aligning
6522     strings.  Here, the SPECs are of the form `LEFT:RIGHT' where
6523     `LEFT' and `RIGHT' are arbitrary strings.  These strings are
6524     modified by replacing the colons by the SEP string and padding the
6525     LEFT strings with spaces to the right so that the SEP strings in
6526     the result (and hence the RIGHT strings after them) are all
6527     aligned if the strings are printed below each other.  All strings
6528     without a colon are left unchanged and all strings with an empty
6529     RIGHT string have the trailing colon removed.  In both cases the
6530     lengths of the strings are not used to determine how the other
6531     strings are to be aligned.  A colon in the LEFT string can be
6532     escaped with a backslash.  The resulting strings are stored in the
6533     ARRAY.
6534
6535zregexparse
6536     This implements some internals of the _regex_arguments function.
6537
6538zparseopts [ -D -E -F -K -M ] [ -a ARRAY ] [ -A ASSOC ] [ - ] SPEC ...
6539     This builtin simplifies the parsing of options in positional
6540     parameters, i.e. the set of arguments given by $*.  Each SPEC
6541     describes one option and must be of the form `OPT[=ARRAY]'.  If an
6542     option described by OPT is found in the positional parameters it
6543     is copied into the ARRAY specified with the -a option; if the
6544     optional `=ARRAY' is given, it is instead copied into that array,
6545     which should be declared as a normal array and never as an
6546     associative array.
6547
6548     Note that it is an error to give any SPEC without an `=ARRAY'
6549     unless one of the -a or -A options is used.
6550
6551     Unless the -E option is given, parsing stops at the first string
6552     that isn't described by one of the SPECs.  Even with -E, parsing
6553     always stops at a positional parameter equal to `-' or `--'. See
6554     also -F.
6555
6556     The OPT description must be one of the following.  Any of the
6557     special characters can appear in the option name provided it is
6558     preceded by a backslash.
6559
6560
6561    NAME
6562    NAME+
6563          The NAME is the name of the option without the leading `-'.
6564          To specify a GNU-style long option, one of the usual two
6565          leading `-' must be included in NAME; for example, a `--file'
6566          option is represented by a NAME of `-file'.
6567
6568          If a `+' appears after NAME, the option is appended to ARRAY
6569          each time it is found in the positional parameters; without
6570          the `+' only the _last_ occurrence of the option is preserved.
6571
6572          If one of these forms is used, the option takes no argument,
6573          so parsing stops if the next positional parameter does not
6574          also begin with `-' (unless the -E option is used).
6575
6576    NAME:
6577    NAME:-
6578    NAME::
6579          If one or two colons are given, the option takes an argument;
6580          with one colon, the argument is mandatory and with two colons
6581          it is optional.  The argument is appended to the ARRAY after
6582          the option itself.
6583
6584          An optional argument is put into the same array element as
6585          the option name (note that this makes empty strings as
6586          arguments indistinguishable).  A mandatory argument is added
6587          as a separate element unless the `:-' form is used, in which
6588          case the argument is put into the same element.
6589
6590          A `+' as described above may appear between the NAME and the
6591          first colon.
6592
6593
6594     In all cases, option-arguments must appear either immediately
6595     following the option in the same positional parameter or in the
6596     next one. Even an optional argument may appear in the next
6597     parameter, unless it begins with a `-'.  There is no special
6598     handling of `=' as with GNU-style argument parsers; given the SPEC
6599     `-foo:', the positional parameter `--foo=bar' is parsed as `--foo'
6600     with an argument of `=bar'.
6601
6602     When the names of two options that take no arguments overlap, the
6603     longest one wins, so that parsing for the SPECs `-foo -foobar'
6604     (for example) is unambiguous. However, due to the aforementioned
6605     handling of option-arguments, ambiguities may arise when at least
6606     one overlapping SPEC takes an argument, as in `-foo: -foobar'. In
6607     that case, the last matching SPEC wins.
6608
6609     The options of zparseopts itself cannot be stacked because, for
6610     example, the stack `-DEK' is indistinguishable from a SPEC for the
6611     GNU-style long option `--DEK'.  The options of zparseopts itself
6612     are:
6613
6614
6615    -a ARRAY
6616          As described above, this names the default array in which to
6617          store the recognised options.
6618
6619    -A ASSOC
6620          If this is given, the options and their values are also put
6621          into an associative array with the option names as keys and
6622          the arguments (if any) as the values.
6623
6624    -D
6625          If this option is given, all options found are removed from
6626          the positional parameters of the calling shell or shell
6627          function, up to but not including any not described by the
6628          SPECs.  If the first such parameter is `-' or `--', it is
6629          removed as well.  This is similar to using the shift builtin.
6630
6631    -E
6632          This changes the parsing rules to _not_ stop at the first
6633          string that isn't described by one of the SPECs.  It can be
6634          used to test for or (if used together with -D) extract
6635          options and their arguments, ignoring all other options and
6636          arguments that may be in the positional parameters.  As
6637          indicated above, parsing still stops at the first `-' or `--'
6638          not described by a SPEC, but it is not removed when used with
6639          -D.
6640
6641    -F
6642          If this option is given, zparseopts immediately stops at the
6643          first option-like parameter not described by one of the
6644          SPECs, prints an error message, and returns status 1.
6645          Removal (-D) and extraction (-E) are not performed, and
6646          option arrays are not updated.  This provides basic
6647          validation for the given options.
6648
6649          Note that the appearance in the positional parameters of an
6650          option without its required argument always aborts parsing
6651          and returns an error as described above regardless of whether
6652          this option is used.
6653
6654    -K
6655          With this option, the arrays specified with the -a option and
6656          with the `=ARRAY' forms are kept unchanged when none of the
6657          SPECs for them is used.  Otherwise the entire array is
6658          replaced when any of the SPECs is used.  Individual elements
6659          of associative arrays specified with the -A option are
6660          preserved by -K.  This allows assignment of default values to
6661          arrays before calling zparseopts.
6662
6663    -M
6664          This changes the assignment rules to implement a map among
6665          equivalent option names.  If any SPEC uses the `=ARRAY' form,
6666          the string ARRAY is interpreted as the name of another SPEC,
6667          which is used to choose where to store the values.  If no
6668          other SPEC is found, the values are stored as usual.  This
6669          changes only the way the values are stored, not the way $* is
6670          parsed, so results may be unpredictable if the `NAME+'
6671          specifier is used inconsistently.
6672
6673
6674     For example,
6675
6676
6677          set -- -a -bx -c y -cz baz -cend
6678          zparseopts a=foo b:=bar c+:=bar
6679
6680     will have the effect of
6681
6682
6683          foo=(-a)
6684          bar=(-b x -c y -c z)
6685
6686     The arguments from `baz' on will not be used.
6687
6688     As an example for the -E option, consider:
6689
6690
6691          set -- -a x -b y -c z arg1 arg2
6692          zparseopts -E -D b:=bar
6693
6694     will have the effect of
6695
6696
6697          bar=(-b y)
6698          set -- -a x -c z arg1 arg2
6699
6700     I.e., the option -b and its arguments are taken from the
6701     positional parameters and put into the array bar.
6702
6703     The -M option can be used like this:
6704
6705
6706          set -- -a -bx -c y -cz baz -cend
6707          zparseopts -A bar -M a=foo b+: c:=b
6708
6709     to have the effect of
6710
6711
6712          foo=(-a)
6713          bar=(-a '' -b xyz)
6714
6715
6716
6717File: zsh.info,  Node: Calendar Function System,  Next: TCP Function System,  Prev: Zsh Modules,  Up: Top
6718
671923 Calendar Function System
6720***************************
6721
6722
6723
672423.1 Description
6725================
6726
6727The shell is supplied with a series of functions to replace and enhance
6728the traditional Unix calendar programme, which warns the user of
6729imminent or future events, details of which are stored in a text file
6730(typically calendar in the user's home directory).  The version
6731provided here includes a mechanism for alerting the user when an event
6732is due.
6733
6734In addition functions age, before and after are provided that can be
6735used in a glob qualifier; they allow files to be selected based on
6736their modification times.
6737
6738The format of the calendar file and the dates used there in and in the
6739age function are described first, then the functions that can be called
6740to examine and modify the calendar file.
6741
6742The functions here depend on the availability of the zsh/datetime
6743module which is usually installed with the shell.  The library function
6744strptime() must be available; it is present on most recent operating
6745systems.
6746
6747
6748
6749* Menu:
6750
6751* Calendar File and Date Formats::
6752* Calendar System User Functions::
6753* Calendar Styles::
6754* Calendar Utility Functions::
6755* Calendar Bugs::
6756
6757
6758
6759File: zsh.info,  Node: Calendar File and Date Formats,  Next: Calendar System User Functions,  Up: Calendar Function System
6760
676123.2 File and Date Formats
6762==========================
6763
6764
6765
676623.2.1 Calendar File Format
6767---------------------------
6768
6769The calendar file is by default ~/calendar.  This can be configured by
6770the calendar-file style, see *Note Calendar Styles::.  The basic format
6771consists of a series of separate lines, with no indentation, each
6772including a date and time specification followed by a description of
6773the event.
6774
6775Various enhancements to this format are supported, based on the syntax
6776of Emacs calendar mode.  An indented line indicates a continuation line
6777that continues the description of the event from the preceding line
6778(note the date may not be continued in this way).  An initial ampersand
6779(&) is ignored for compatibility.
6780
6781An indented line on which the first non-whitespace character is # is
6782not displayed with the calendar entry, but is still scanned for
6783information.  This can be used to hide information useful to the
6784calendar system but not to the user, such as the unique identifier used
6785by calendar_add.
6786
6787The Emacs extension that a date with no description may refer to a
6788number of succeeding events at different times is not supported.
6789
6790Unless the done-file style has been altered, any events which have been
6791processed are appended to the file with the same name as the calendar
6792file with the suffix .done, hence ~/calendar.done by default.
6793
6794An example is shown below.
6795
6796
6797
679823.2.2 Date Format
6799------------------
6800
6801The format of the date and time is designed to allow flexibility without
6802admitting ambiguity.  (The words `date' and `time' are both used in the
6803documentation below; except where specifically noted this implies a
6804string that may include both a date and a time specification.)  Note
6805that there is no localization support; month and day names must be in
6806English and separator characters are fixed.  Matching is case
6807insensitive, and only the first three letters of the names are
6808significant, although as a special case a form beginning "month" does
6809not match "Monday".  Furthermore, time zones are not handled; all times
6810are assumed to be local.
6811
6812It is recommended that, rather than exploring the intricacies of the
6813system, users find a date format that is natural to them and stick to
6814it.  This will avoid unexpected effects.  Various key facts should be
6815noted.
6816
6817
6818   * In particular, note the confusion between MONTH/DAY/YEAR and
6819     DAY/MONTH/YEAR when the month is numeric; these formats should be
6820     avoided if at all possible.  Many alternatives are available.
6821
6822   * The year must be given in full to avoid confusion, and only years
6823     from 1900 to 2099 inclusive are matched.
6824
6825The following give some obvious examples; users finding here a format
6826they like and not subject to vagaries of style may skip the full
6827description.  As dates and times are matched separately (even though
6828the time may be embedded in the date), any date format may be mixed
6829with any format for the time of day provide the separators are clear
6830(whitespace, colons, commas).
6831
6832
6833     2007/04/03 13:13
6834     2007/04/03:13:13
6835     2007/04/03 1:13 pm
6836     3rd April 2007, 13:13
6837     April 3rd 2007 1:13 p.m.
6838     Apr 3, 2007 13:13
6839     Tue Apr 03 13:13:00 2007
6840     13:13 2007/apr/3
6841
6842More detailed rules follow.
6843
6844Times are parsed and extracted before dates.  They must use colons to
6845separate hours and minutes, though a dot is allowed before seconds if
6846they are present.  This limits time formats to the following:
6847
6848
6849   * HH:MM[:SS[.FFFFF]] [am|pm|a.m.|p.m.]
6850
6851   * HH:MM.SS[.FFFFF] [am|pm|a.m.|p.m.]
6852
6853Here, square brackets indicate optional elements, possibly with
6854alternatives.  Fractions of a second are recognised but ignored.  For
6855absolute times (the normal format require by the calendar file and the
6856age, before and after functions) a date is mandatory but a time of day
6857is not; the time returned is at the start of the date.  One variation
6858is allowed: if a.m. or p.m. or one of their variants is present, an
6859hour without a minute is allowed, e.g. 3 p.m..
6860
6861Time zones are not handled, though if one is matched following a time
6862specification it will be removed to allow a surrounding date to be
6863parsed.  This only happens if the format of the timezone is not too
6864unusual.  The following are examples of forms that are understood:
6865
6866
6867     +0100
6868     GMT
6869     GMT-7
6870     CET+1CDT
6871
6872Any part of the timezone that is not numeric must have exactly three
6873capital letters in the name.
6874
6875Dates suffer from the ambiguity between DD/MM/YYYY and MM/DD/YYYY.  It
6876is recommended this form is avoided with purely numeric dates, but use
6877of ordinals, eg. 3rd/04/2007, will resolve the ambiguity as the ordinal
6878is always parsed as the day of the month.  Years must be four digits
6879(and the first two must be 19 or 20); 03/04/08 is not recognised.  Other
6880numbers may have leading zeroes, but they are not required.  The
6881following are handled:
6882
6883
6884   * YYYY/MM/DD
6885
6886   * YYYY-MM-DD
6887
6888   * YYYY/MNM/DD
6889
6890   * YYYY-MNM-DD
6891
6892   * DD[th|st|rd] MNM[,] [ YYYY ]
6893
6894   * MNM DD[th|st|rd][,] [ YYYY ]
6895
6896   * DD[th|st|rd]/MM[,] YYYY
6897
6898   * DD[th|st|rd]/MM/YYYY
6899
6900   * MM/DD[th|st|rd][,] YYYY
6901
6902   * MM/DD[th|st|rd]/YYYY
6903
6904Here, MNM is at least the first three letters of a month name, matched
6905case-insensitively.  The remainder of the month name may appear but its
6906contents are irrelevant, so janissary, febrile, martial, apricot,
6907maybe, junta, etc. are happily handled.
6908
6909Where the year is shown as optional, the current year is assumed.  There
6910are only two such cases, the form Jun 20 or 14 September (the only two
6911commonly occurring forms, apart from a "the" in some forms of English,
6912which isn't currently supported).  Such dates will of course become
6913ambiguous in the future, so should ideally be avoided.
6914
6915Times may follow dates with a colon, e.g. 1965/07/12:09:45; this is in
6916order to provide a format with no whitespace.  A comma and whitespace
6917are allowed, e.g. 1965/07/12, 09:45.  Currently the order of these
6918separators is not checked, so illogical formats such as 1965/07/12, :
6919,09:45 will also be matched.  For simplicity such variations are not
6920shown in the list above.  Otherwise, a time is only recognised as being
6921associated with a date if there is only whitespace in between, or if the
6922time was embedded in the date.
6923
6924Days of the week are not normally scanned, but will be ignored if they
6925occur at the start of the date pattern only.  However, in contexts
6926where it is useful to specify dates relative to today, days of the week
6927with no other date specification may be given.  The day is assumed to
6928be either today or within the past week.  Likewise, the words yesterday,
6929today and tomorrow are handled.  All matches are case-insensitive.
6930Hence if today is Monday, then Sunday is equivalent to yesterday,
6931Monday is equivalent to today, but Tuesday gives a date six days ago.
6932This is not generally useful within the calendar file.  Dates in this
6933format may be combined with a time specification; for example Tomorrow,
69348 p.m..
6935
6936For example, the standard date format:
6937
6938
6939     Fri Aug 18 17:00:48 BST 2006
6940
6941is handled by matching HH:MM:SS and removing it together with the
6942matched (but unused) time zone.  This leaves the following:
6943
6944
6945     Fri Aug 18 2006
6946
6947Fri is ignored and the rest is matched according to the standard rules.
6948
6949
6950
695123.2.3 Relative Time Format
6952---------------------------
6953
6954In certain places relative times are handled.  Here, a date is not
6955allowed; instead a combination of various supported periods are
6956allowed, together with an optional time.  The periods must be in order
6957from most to least significant.
6958
6959In some cases, a more accurate calculation is possible when there is an
6960anchor date:  offsets of months or years pick the correct day, rather
6961than being rounded, and it is possible to pick a particular day in a
6962month as `(1st Friday)', etc., as described in more detail below.
6963
6964Anchors are available in the following cases.  If one or two times are
6965passed to the function calendar, the start time acts an anchor for the
6966end time when the end time is relative (even if the start time is
6967implicit).  When examining calendar files, the scheduled event being
6968examined anchors the warning time when it is given explicitly by means
6969of the WARN keyword; likewise, the scheduled event anchors a repetition
6970period when given by the RPT keyword, so that specifications such as
6971RPT 2 months, 3rd Thursday are handled properly.  Finally, the -R
6972argument to calendar_scandate directly provides an anchor for relative
6973calculations.
6974
6975The periods handled, with possible abbreviations are:
6976
6977
6978Years
6979     years, yrs, ys, year, yr, y, yearly.  A year is 365.25 days unless
6980     there is an anchor.
6981
6982Months
6983     months, mons, mnths, mths, month, mon, mnth, mth, monthly.  Note
6984     that m, ms, mn, mns are ambiguous and are _not_ handled.  A month
6985     is a period of 30 days rather than a calendar month unless there
6986     is an anchor.
6987
6988Weeks
6989     weeks, wks, ws, week, wk, w, weekly
6990
6991Days
6992     days, dys, ds, day, dy, d, daily
6993
6994Hours
6995     hours, hrs, hs, hour, hr, h, hourly
6996
6997Minutes
6998     minutes, mins, minute, min, but _not_ m, ms, mn or mns
6999
7000Seconds
7001     seconds, secs, ss, second, sec, s
7002
7003
7004Spaces between the numbers are optional, but are required between items,
7005although a comma may be used (with or without spaces).
7006
7007The forms yearly to hourly allow the number to be omitted; it is
7008assumed to be 1.  For example, 1 d and daily are equivalent.  Note that
7009using those forms with plurals is confusing; 2 yearly is the same as 2
7010years, _not_ twice yearly, so it is recommended they only be used
7011without numbers.
7012
7013When an anchor time is present, there is an extension to handle regular
7014events in the form of the Nth SOMEday of the month.  Such a
7015specification must occur immediately after any year and month
7016specification, but before any time of day, and must be in the form
7017N(th|st|rd) DAY, for example 1st Tuesday or 3rd Monday.  As in other
7018places, days are matched case insensitively, must be in English, and
7019only the first three letters are significant except that a form
7020beginning `month' does not match `Monday'.  No attempt is made to
7021sanitize the resulting date; attempts to squeeze too many occurrences
7022into a month will push the day into the next month (but in the obvious
7023fashion, retaining the correct day of the week).
7024
7025Here are some examples:
7026
7027
7028     30 years 3 months 4 days 3:42:41
7029     14 days 5 hours
7030     Monthly, 3rd Thursday
7031     4d,10hr
7032
7033
703423.2.4 Example
7035--------------
7036
7037Here is an example calendar file.  It uses a consistent date format, as
7038recommended above.
7039
7040
7041     Feb 1, 2006 14:30 Pointless bureaucratic meeting
7042     Mar 27, 2006 11:00 Mutual recrimination and finger pointing
7043       Bring water pistol and waterproofs
7044     Mar 31, 2006 14:00 Very serious managerial pontification
7045       # UID 12C7878A9A50
7046     Apr 10, 2006 13:30 Even more pointless blame assignment exercise WARN 30 mins
7047     May 18, 2006 16:00 Regular moaning session RPT monthly, 3rd Thursday
7048
7049The second entry has a continuation line.  The third entry has a
7050continuation line that will not be shown when the entry is displayed,
7051but the unique identifier will be used by the calendar_add function when
7052updating the event.  The fourth entry will produce a warning 30 minutes
7053before the event (to allow you to equip yourself appropriately).  The
7054fifth entry repeats after a month on the 3rd Thursday, i.e. June 15,
70552006, at the same time.
7056
7057
7058
7059