1ZSHMODULES(1) General Commands Manual ZSHMODULES(1)
2
3
4
6 zshmodules - zsh loadable modules
7
9 Some optional parts of zsh are in modules, separate from the core of
10 the shell. Each of these modules may be linked in to the shell at
11 build time, or can be dynamically linked while the shell is running if
12 the installation supports this feature. Modules are linked at runtime
13 with the zmodload command, see zshbuiltins(1).
14
15 The modules that are bundled with the zsh distribution are:
16
17 zsh/attr
18 Builtins for manipulating extended attributes (xattr).
19
20 zsh/cap
21 Builtins for manipulating POSIX.1e (POSIX.6) capability (privi‐
22 lege) sets.
23
24 zsh/clone
25 A builtin that can clone a running shell onto another terminal.
26
27 zsh/compctl
28 The compctl builtin for controlling completion.
29
30 zsh/complete
31 The basic completion code.
32
33 zsh/complist
34 Completion listing extensions.
35
36 zsh/computil
37 A module with utility builtins needed for the shell function
38 based completion system.
39
40 zsh/curses
41 curses windowing commands
42
43 zsh/datetime
44 Some date/time commands and parameters.
45
46 zsh/db/gdbm
47 Builtins for managing associative array parameters tied to GDBM
48 databases.
49
50 zsh/deltochar
51 A ZLE function duplicating EMACS' zap-to-char.
52
53 zsh/example
54 An example of how to write a module.
55
56 zsh/files
57 Some basic file manipulation commands as builtins.
58
59 zsh/langinfo
60 Interface to locale information.
61
62 zsh/mapfile
63 Access to external files via a special associative array.
64
65 zsh/mathfunc
66 Standard scientific functions for use in mathematical evalua‐
67 tions.
68
69 zsh/nearcolor
70 Map colours to the nearest colour in the available palette.
71
72 zsh/newuser
73 Arrange for files for new users to be installed.
74
75 zsh/parameter
76 Access to internal hash tables via special associative arrays.
77
78 zsh/pcre
79 Interface to the PCRE library.
80
81 zsh/param/private
82 Builtins for managing private-scoped parameters in function con‐
83 text.
84
85 zsh/regex
86 Interface to the POSIX regex library.
87
88 zsh/sched
89 A builtin that provides a timed execution facility within the
90 shell.
91
92 zsh/net/socket
93 Manipulation of Unix domain sockets
94
95 zsh/stat
96 A builtin command interface to the stat system call.
97
98 zsh/system
99 A builtin interface to various low-level system features.
100
101 zsh/net/tcp
102 Manipulation of TCP sockets
103
104 zsh/termcap
105 Interface to the termcap database.
106
107 zsh/terminfo
108 Interface to the terminfo database.
109
110 zsh/zftp
111 A builtin FTP client.
112
113 zsh/zle
114 The Zsh Line Editor, including the bindkey and vared builtins.
115
116 zsh/zleparameter
117 Access to internals of the Zsh Line Editor via parameters.
118
119 zsh/zprof
120 A module allowing profiling for shell functions.
121
122 zsh/zpty
123 A builtin for starting a command in a pseudo-terminal.
124
125 zsh/zselect
126 Block and return when file descriptors are ready.
127
128 zsh/zutil
129 Some utility builtins, e.g. the one for supporting configuration
130 via styles.
131
133 The zsh/attr module is used for manipulating extended attributes. The
134 -h option causes all commands to operate on symbolic links instead of
135 their targets. The builtins in this module are:
136
137 zgetattr [ -h ] filename attribute [ parameter ]
138 Get the extended attribute attribute from the specified file‐
139 name. If the optional argument parameter is given, the attribute
140 is set on that parameter instead of being printed to stdout.
141
142 zsetattr [ -h ] filename attribute value
143 Set the extended attribute attribute on the specified filename
144 to value.
145
146 zdelattr [ -h ] filename attribute
147 Remove the extended attribute attribute from the specified file‐
148 name.
149
150 zlistattr [ -h ] filename [ parameter ]
151 List the extended attributes currently set on the specified
152 filename. If the optional argument parameter is given, the list
153 of attributes is set on that parameter instead of being printed
154 to stdout.
155
156 zgetattr and zlistattr allocate memory dynamically. If the attribute
157 or list of attributes grows between the allocation and the call to get
158 them, they return 2. On all other errors, 1 is returned. This allows
159 the calling function to check for this case and retry.
160
162 The zsh/cap module is used for manipulating POSIX.1e (POSIX.6) capabil‐
163 ity sets. If the operating system does not support this interface, the
164 builtins defined by this module will do nothing. The builtins in this
165 module are:
166
167 cap [ capabilities ]
168 Change the shell's process capability sets to the specified
169 capabilities, otherwise display the shell's current capabili‐
170 ties.
171
172 getcap filename ...
173 This is a built-in implementation of the POSIX standard utility.
174 It displays the capability sets on each specified filename.
175
176 setcap capabilities filename ...
177 This is a built-in implementation of the POSIX standard utility.
178 It sets the capability sets on each specified filename to the
179 specified capabilities.
180
182 The zsh/clone module makes available one builtin command:
183
184 clone tty
185 Creates a forked instance of the current shell, attached to the
186 specified tty. In the new shell, the PID, PPID and TTY special
187 parameters are changed appropriately. $! is set to zero in the
188 new shell, and to the new shell's PID in the original shell.
189
190 The return status of the builtin is zero in both shells if suc‐
191 cessful, and non-zero on error.
192
193 The target of clone should be an unused terminal, such as an
194 unused virtual console or a virtual terminal created by
195
196 xterm -e sh -c 'trap : INT QUIT TSTP; tty;
197 while :; do sleep 100000000; done'
198
199 Some words of explanation are warranted about this long xterm
200 command line: when doing clone on a pseudo-terminal, some other
201 session ("session" meant as a unix session group, or SID) is
202 already owning the terminal. Hence the cloned zsh cannot acquire
203 the pseudo-terminal as a controlling tty. That means two things:
204
205 · the job control signals will go to the
206 sh-started-by-xterm process group (that's why we disable
207 INT QUIT and TSTP with trap; otherwise the while loop
208 could get suspended or killed)
209
210 · the cloned shell will have job control disabled, and the
211 job control keys (control-C, control-\ and control-Z)
212 will not work.
213
214 This does not apply when cloning to an unused vc.
215
216 Cloning to a used (and unprepared) terminal will result in two
217 processes reading simultaneously from the same terminal, with
218 input bytes going randomly to either process.
219
220 clone is mostly useful as a shell built-in replacement for
221 openvt.
222
224 The zsh/compctl module makes available two builtin commands. compctl,
225 is the old, deprecated way to control completions for ZLE. See zshcom‐
226 pctl(1). The other builtin command, compcall can be used in
227 user-defined completion widgets, see zshcompwid(1).
228
230 The zsh/complete module makes available several builtin commands which
231 can be used in user-defined completion widgets, see zshcompwid(1).
232
234 The zsh/complist module offers three extensions to completion listings:
235 the ability to highlight matches in such a list, the ability to scroll
236 through long lists and a different style of menu completion.
237
238 Colored completion listings
239 Whenever one of the parameters ZLS_COLORS or ZLS_COLOURS is set and the
240 zsh/complist module is loaded or linked into the shell, completion
241 lists will be colored. Note, however, that complist will not automati‐
242 cally be loaded if it is not linked in: on systems with dynamic load‐
243 ing, `zmodload zsh/complist' is required.
244
245 The parameters ZLS_COLORS and ZLS_COLOURS describe how matches are
246 highlighted. To turn on highlighting an empty value suffices, in which
247 case all the default values given below will be used. The format of
248 the value of these parameters is the same as used by the GNU version of
249 the ls command: a colon-separated list of specifications of the form
250 `name=value'. The name may be one of the following strings, most of
251 which specify file types for which the value will be used. The strings
252 and their default values are:
253
254 no 0 for normal text (i.e. when displaying something other than a
255 matched file)
256
257 fi 0 for regular files
258
259 di 32 for directories
260
261 ln 36 for symbolic links. If this has the special value target, sym‐
262 bolic links are dereferenced and the target file used to deter‐
263 mine the display format.
264
265 pi 31 for named pipes (FIFOs)
266
267 so 33 for sockets
268
269 bd 44;37
270 for block devices
271
272 cd 44;37
273 for character devices
274
275 or none
276 for a symlink to nonexistent file (default is the value defined
277 for ln)
278
279 mi none
280 for a non-existent file (default is the value defined for fi);
281 this code is currently not used
282
283 su 37;41
284 for files with setuid bit set
285
286 sg 30;43
287 for files with setgid bit set
288
289 tw 30;42
290 for world writable directories with sticky bit set
291
292 ow 34;43
293 for world writable directories without sticky bit set
294
295 sa none
296 for files with an associated suffix alias; this is only tested
297 after specific suffixes, as described below
298
299 st 37;44
300 for directories with sticky bit set but not world writable
301
302 ex 35 for executable files
303
304 lc \e[ for the left code (see below)
305
306 rc m for the right code
307
308 tc 0 for the character indicating the file type printed after file‐
309 names if the LIST_TYPES option is set
310
311 sp 0 for the spaces printed after matches to align the next column
312
313 ec none
314 for the end code
315
316 Apart from these strings, the name may also be an asterisk (`*') fol‐
317 lowed by any string. The value given for such a string will be used for
318 all files whose name ends with the string. The name may also be an
319 equals sign (`=') followed by a pattern; the EXTENDED_GLOB option will
320 be turned on for evaluation of the pattern. The value given for this
321 pattern will be used for all matches (not just filenames) whose display
322 string are matched by the pattern. Definitions for the form with the
323 leading equal sign take precedence over the values defined for file
324 types, which in turn take precedence over the form with the leading
325 asterisk (file extensions).
326
327 The leading-equals form also allows different parts of the displayed
328 strings to be colored differently. For this, the pattern has to use
329 the `(#b)' globbing flag and pairs of parentheses surrounding the parts
330 of the strings that are to be colored differently. In this case the
331 value may consist of more than one color code separated by equal signs.
332 The first code will be used for all parts for which no explicit code is
333 specified and the following codes will be used for the parts matched by
334 the sub-patterns in parentheses. For example, the specification
335 `=(#b)(?)*(?)=0=3=7' will be used for all matches which are at least
336 two characters long and will use the code `3' for the first character,
337 `7' for the last character and `0' for the rest.
338
339 All three forms of name may be preceded by a pattern in parentheses.
340 If this is given, the value will be used only for matches in groups
341 whose names are matched by the pattern given in the parentheses. For
342 example, `(g*)m*=43' highlights all matches beginning with `m' in
343 groups whose names begin with `g' using the color code `43'. In case
344 of the `lc', `rc', and `ec' codes, the group pattern is ignored.
345
346 Note also that all patterns are tried in the order in which they appear
347 in the parameter value until the first one matches which is then used.
348 Patterns may be matched against completions, descriptions (possibly
349 with spaces appended for padding), or lines consisting of a completion
350 followed by a description. For consistent coloring it may be necessary
351 to use more than one pattern or a pattern with backreferences.
352
353 When printing a match, the code prints the value of lc, the value for
354 the file-type or the last matching specification with a `*', the value
355 of rc, the string to display for the match itself, and then the value
356 of ec if that is defined or the values of lc, no, and rc if ec is not
357 defined.
358
359 The default values are ISO 6429 (ANSI) compliant and can be used on
360 vt100 compatible terminals such as xterms. On monochrome terminals the
361 default values will have no visible effect. The colors function from
362 the contribution can be used to get associative arrays containing the
363 codes for ANSI terminals (see the section `Other Functions' in zshcon‐
364 trib(1)). For example, after loading colors, one could use
365 `$color[red]' to get the code for foreground color red and
366 `$color[bg-green]' for the code for background color green.
367
368 If the completion system invoked by compinit is used, these parameters
369 should not be set directly because the system controls them itself.
370 Instead, the list-colors style should be used (see the section `Comple‐
371 tion System Configuration' in zshcompsys(1)).
372
373 Scrolling in completion listings
374 To enable scrolling through a completion list, the LISTPROMPT parameter
375 must be set. Its value will be used as the prompt; if it is the empty
376 string, a default prompt will be used. The value may contain escapes
377 of the form `%x'. It supports the escapes `%B', `%b', `%S', `%s',
378 `%U', `%u', `%F', `%f', `%K', `%k' and `%{...%}' used also in shell
379 prompts as well as three pairs of additional sequences: a `%l' or `%L'
380 is replaced by the number of the last line shown and the total number
381 of lines in the form `number/total'; a `%m' or `%M' is replaced with
382 the number of the last match shown and the total number of matches; and
383 `%p' or `%P' is replaced with `Top', `Bottom' or the position of the
384 first line shown in percent of the total number of lines, respectively.
385 In each of these cases the form with the uppercase letter will be
386 replaced with a string of fixed width, padded to the right with spaces,
387 while the lowercase form will not be padded.
388
389 If the parameter LISTPROMPT is set, the completion code will not ask if
390 the list should be shown. Instead it immediately starts displaying the
391 list, stopping after the first screenful, showing the prompt at the
392 bottom, waiting for a keypress after temporarily switching to the
393 listscroll keymap. Some of the zle functions have a special meaning
394 while scrolling lists:
395
396 send-break
397 stops listing discarding the key pressed
398
399 accept-line, down-history, down-line-or-history
400 down-line-or-search, vi-down-line-or-history
401 scrolls forward one line
402
403 complete-word, menu-complete, expand-or-complete
404 expand-or-complete-prefix, menu-complete-or-expand
405 scrolls forward one screenful
406
407 accept-search
408 stop listing but take no other action
409
410 Every other character stops listing and immediately processes the key
411 as usual. Any key that is not bound in the listscroll keymap or that
412 is bound to undefined-key is looked up in the keymap currently
413 selected.
414
415 As for the ZLS_COLORS and ZLS_COLOURS parameters, LISTPROMPT should not
416 be set directly when using the shell function based completion system.
417 Instead, the list-prompt style should be used.
418
419 Menu selection
420 The zsh/complist module also offers an alternative style of selecting
421 matches from a list, called menu selection, which can be used if the
422 shell is set up to return to the last prompt after showing a completion
423 list (see the ALWAYS_LAST_PROMPT option in zshoptions(1)).
424
425 Menu selection can be invoked directly by the widget menu-select
426 defined by this module. This is a standard ZLE widget that can be
427 bound to a key in the usual way as described in zshzle(1).
428
429 Alternatively, the parameter MENUSELECT can be set to an integer, which
430 gives the minimum number of matches that must be present before menu
431 selection is automatically turned on. This second method requires that
432 menu completion be started, either directly from a widget such as
433 menu-complete, or due to one of the options MENU_COMPLETE or AUTO_MENU
434 being set. If MENUSELECT is set, but is 0, 1 or empty, menu selection
435 will always be started during an ambiguous menu completion.
436
437 When using the completion system based on shell functions, the MENUSE‐
438 LECT parameter should not be used (like the ZLS_COLORS and ZLS_COLOURS
439 parameters described above). Instead, the menu style should be used
440 with the select=... keyword.
441
442 After menu selection is started, the matches will be listed. If there
443 are more matches than fit on the screen, only the first screenful is
444 shown. The matches to insert into the command line can be selected
445 from this list. In the list one match is highlighted using the value
446 for ma from the ZLS_COLORS or ZLS_COLOURS parameter. The default value
447 for this is `7' which forces the selected match to be highlighted using
448 standout mode on a vt100-compatible terminal. If neither ZLS_COLORS
449 nor ZLS_COLOURS is set, the same terminal control sequence as for the
450 `%S' escape in prompts is used.
451
452 If there are more matches than fit on the screen and the parameter
453 MENUPROMPT is set, its value will be shown below the matches. It sup‐
454 ports the same escape sequences as LISTPROMPT, but the number of the
455 match or line shown will be that of the one where the mark is placed.
456 If its value is the empty string, a default prompt will be used.
457
458 The MENUSCROLL parameter can be used to specify how the list is
459 scrolled. If the parameter is unset, this is done line by line, if it
460 is set to `0' (zero), the list will scroll half the number of lines of
461 the screen. If the value is positive, it gives the number of lines to
462 scroll and if it is negative, the list will be scrolled the number of
463 lines of the screen minus the (absolute) value.
464
465 As for the ZLS_COLORS, ZLS_COLOURS and LISTPROMPT parameters, neither
466 MENUPROMPT nor MENUSCROLL should be set directly when using the shell
467 function based completion system. Instead, the select-prompt and
468 select-scroll styles should be used.
469
470 The completion code sometimes decides not to show all of the matches in
471 the list. These hidden matches are either matches for which the com‐
472 pletion function which added them explicitly requested that they not
473 appear in the list (using the -n option of the compadd builtin command)
474 or they are matches which duplicate a string already in the list
475 (because they differ only in things like prefixes or suffixes that are
476 not displayed). In the list used for menu selection, however, even
477 these matches are shown so that it is possible to select them. To
478 highlight such matches the hi and du capabilities in the ZLS_COLORS and
479 ZLS_COLOURS parameters are supported for hidden matches of the first
480 and second kind, respectively.
481
482 Selecting matches is done by moving the mark around using the zle move‐
483 ment functions. When not all matches can be shown on the screen at the
484 same time, the list will scroll up and down when crossing the top or
485 bottom line. The following zle functions have special meaning during
486 menu selection. Note that the following always perform the same task
487 within the menu selection map and cannot be replaced by user defined
488 widgets, nor can the set of functions be extended:
489
490 accept-line, accept-search
491 accept the current match and leave menu selection (but do not
492 cause the command line to be accepted)
493
494 send-break
495 leaves menu selection and restores the previous contents of the
496 command line
497
498 redisplay, clear-screen
499 execute their normal function without leaving menu selection
500
501 accept-and-hold, accept-and-menu-complete
502 accept the currently inserted match and continue selection
503 allowing to select the next match to insert into the line
504
505 accept-and-infer-next-history
506 accepts the current match and then tries completion with menu
507 selection again; in the case of files this allows one to select
508 a directory and immediately attempt to complete files in it; if
509 there are no matches, a message is shown and one can use undo to
510 go back to completion on the previous level, every other key
511 leaves menu selection (including the other zle functions which
512 are otherwise special during menu selection)
513
514 undo removes matches inserted during the menu selection by one of the
515 three functions before
516
517 down-history, down-line-or-history
518 vi-down-line-or-history, down-line-or-search
519 moves the mark one line down
520
521 up-history, up-line-or-history
522 vi-up-line-or-history, up-line-or-search
523 moves the mark one line up
524
525 forward-char, vi-forward-char
526 moves the mark one column right
527
528 backward-char, vi-backward-char
529 moves the mark one column left
530
531 forward-word, vi-forward-word
532 vi-forward-word-end, emacs-forward-word
533 moves the mark one screenful down
534
535 backward-word, vi-backward-word, emacs-backward-word
536 moves the mark one screenful up
537
538 vi-forward-blank-word, vi-forward-blank-word-end
539 moves the mark to the first line of the next group of matches
540
541 vi-backward-blank-word
542 moves the mark to the last line of the previous group of matches
543
544 beginning-of-history
545 moves the mark to the first line
546
547 end-of-history
548 moves the mark to the last line
549
550 beginning-of-buffer-or-history, beginning-of-line
551 beginning-of-line-hist, vi-beginning-of-line
552 moves the mark to the leftmost column
553
554 end-of-buffer-or-history, end-of-line
555 end-of-line-hist, vi-end-of-line
556 moves the mark to the rightmost column
557
558 complete-word, menu-complete, expand-or-complete
559 expand-or-complete-prefix, menu-expand-or-complete
560 moves the mark to the next match
561
562 reverse-menu-complete
563 moves the mark to the previous match
564
565 vi-insert
566 this toggles between normal and interactive mode; in interactive
567 mode the keys bound to self-insert and self-insert-unmeta insert
568 into the command line as in normal editing mode but without
569 leaving menu selection; after each character completion is tried
570 again and the list changes to contain only the new matches; the
571 completion widgets make the longest unambiguous string be
572 inserted in the command line and undo and backward-delete-char
573 go back to the previous set of matches
574
575 history-incremental-search-forward
576 history-incremental-search-backward
577 this starts incremental searches in the list of completions dis‐
578 played; in this mode, accept-line only leaves incremental
579 search, going back to the normal menu selection mode
580
581 All movement functions wrap around at the edges; any other zle function
582 not listed leaves menu selection and executes that function. It is
583 possible to make widgets in the above list do the same by using the
584 form of the widget with a `.' in front. For example, the widget
585 `.accept-line' has the effect of leaving menu selection and accepting
586 the entire command line.
587
588 During this selection the widget uses the keymap menuselect. Any key
589 that is not defined in this keymap or that is bound to undefined-key is
590 looked up in the keymap currently selected. This is used to ensure
591 that the most important keys used during selection (namely the cursor
592 keys, return, and TAB) have sensible defaults. However, keys in the
593 menuselect keymap can be modified directly using the bindkey builtin
594 command (see zshmodules(1)). For example, to make the return key leave
595 menu selection without accepting the match currently selected one could
596 call
597
598 bindkey -M menuselect '^M' send-break
599
600 after loading the zsh/complist module.
601
603 The zsh/computil module adds several builtin commands that are used by
604 some of the completion functions in the completion system based on
605 shell functions (see zshcompsys(1) ). Except for compquote these
606 builtin commands are very specialised and thus not very interesting
607 when writing your own completion functions. In summary, these builtin
608 commands are:
609
610 comparguments
611 This is used by the _arguments function to do the argument and
612 command line parsing. Like compdescribe it has an option -i to
613 do the parsing and initialize some internal state and various
614 options to access the state information to decide what should be
615 completed.
616
617 compdescribe
618 This is used by the _describe function to build the displays for
619 the matches and to get the strings to add as matches with their
620 options. On the first call one of the options -i or -I should
621 be supplied as the first argument. In the first case, display
622 strings without the descriptions will be generated, in the sec‐
623 ond case, the string used to separate the matches from their
624 descriptions must be given as the second argument and the
625 descriptions (if any) will be shown. All other arguments are
626 like the definition arguments to _describe itself.
627
628 Once compdescribe has been called with either the -i or the -I
629 option, it can be repeatedly called with the -g option and the
630 names of four parameters as its arguments. This will step
631 through the different sets of matches and store the value of
632 compstate[list] in the first scalar, the options for compadd in
633 the second array, the matches in the third array, and the
634 strings to be displayed in the completion listing in the fourth
635 array. The arrays may then be directly given to compadd to reg‐
636 ister the matches with the completion code.
637
638 compfiles
639 Used by the _path_files function to optimize complex recursive
640 filename generation (globbing). It does three things. With the
641 -p and -P options it builds the glob patterns to use, including
642 the paths already handled and trying to optimize the patterns
643 with respect to the prefix and suffix from the line and the
644 match specification currently used. The -i option does the
645 directory tests for the ignore-parents style and the -r option
646 tests if a component for some of the matches are equal to the
647 string on the line and removes all other matches if that is
648 true.
649
650 compgroups
651 Used by the _tags function to implement the internals of the
652 group-order style. This only takes its arguments as names of
653 completion groups and creates the groups for it (all six types:
654 sorted and unsorted, both without removing duplicates, with
655 removing all duplicates and with removing consecutive dupli‐
656 cates).
657
658 compquote [ -p ] names ...
659 There may be reasons to write completion functions that have to
660 add the matches using the -Q option to compadd and perform quot‐
661 ing themselves. Instead of interpreting the first character of
662 the all_quotes key of the compstate special association and
663 using the q flag for parameter expansions, one can use this
664 builtin command. The arguments are the names of scalar or array
665 parameters and the values of these parameters are quoted as
666 needed for the innermost quoting level. If the -p option is
667 given, quoting is done as if there is some prefix before the
668 values of the parameters, so that a leading equal sign will not
669 be quoted.
670
671 The return status is non-zero in case of an error and zero oth‐
672 erwise.
673
674 comptags
675 comptry
676 These implement the internals of the tags mechanism.
677
678 compvalues
679 Like comparguments, but for the _values function.
680
682 The zsh/curses module makes available one builtin command and various
683 parameters.
684
685 Builtin
686 zcurses init
687 zcurses end
688 zcurses addwin targetwin nlines ncols begin_y begin_x [ parentwin ]
689 zcurses delwin targetwin
690 zcurses refresh [ targetwin ... ]
691 zcurses touch targetwin ...
692 zcurses move targetwin new_y new_x
693 zcurses clear targetwin [ redraw | eol | bot ]
694 zcurses position targetwin array
695 zcurses char targetwin character
696 zcurses string targetwin string
697 zcurses border targetwin border
698 zcurses attr targetwin [ [+|-]attribute | fg_col/bg_col ] [...]
699 zcurses bg targetwin [ [+|-]attribute | fg_col/bg_col | @char ] [...]
700 zcurses scroll targetwin [ on | off | [+|-]lines ]
701 zcurses input targetwin [ param [ kparam [ mparam ] ] ]
702 zcurses mouse [ delay num | [+|-]motion ]
703 zcurses timeout targetwin intval
704 zcurses querychar targetwin [ param ]
705 zcurses resize height width [ endwin | nosave | endwin_nosave ]
706 Manipulate curses windows. All uses of this command should be
707 bracketed by `zcurses init' to initialise use of curses, and
708 `zcurses end' to end it; omitting `zcurses end' can cause the
709 terminal to be in an unwanted state.
710
711 The subcommand addwin creates a window with nlines lines and
712 ncols columns. Its upper left corner will be placed at row
713 begin_y and column begin_x of the screen. targetwin is a string
714 and refers to the name of a window that is not currently
715 assigned. Note in particular the curses convention that verti‐
716 cal values appear before horizontal values.
717
718 If addwin is given an existing window as the final argument, the
719 new window is created as a subwindow of parentwin. This differs
720 from an ordinary new window in that the memory of the window
721 contents is shared with the parent's memory. Subwindows must be
722 deleted before their parent. Note that the coordinates of sub‐
723 windows are relative to the screen, not the parent, as with
724 other windows.
725
726 Use the subcommand delwin to delete a window created with
727 addwin. Note that end does not implicitly delete windows, and
728 that delwin does not erase the screen image of the window.
729
730 The window corresponding to the full visible screen is called
731 stdscr; it always exists after `zcurses init' and cannot be
732 delete with delwin.
733
734 The subcommand refresh will refresh window targetwin; this is
735 necessary to make any pending changes (such as characters you
736 have prepared for output with char) visible on the screen.
737 refresh without an argument causes the screen to be cleared and
738 redrawn. If multiple windows are given, the screen is updated
739 once at the end.
740
741 The subcommand touch marks the targetwins listed as changed.
742 This is necessary before refreshing windows if a window that was
743 in front of another window (which may be stdscr) is deleted.
744
745 The subcommand move moves the cursor position in targetwin to
746 new coordinates new_y and new_x. Note that the subcommand
747 string (but not the subcommand char) advances the cursor posi‐
748 tion over the characters added.
749
750 The subcommand clear erases the contents of targetwin. One (and
751 no more than one) of three options may be specified. With the
752 option redraw, in addition the next refresh of targetwin will
753 cause the screen to be cleared and repainted. With the option
754 eol, targetwin is only cleared to the end of the current cursor
755 line. With the option bot, targetwin is cleared to the end of
756 the window, i.e everything to the right and below the cursor is
757 cleared.
758
759 The subcommand position writes various positions associated with
760 targetwin into the array named array. These are, in order:
761 - The y and x coordinates of the cursor relative to the top
762 left of targetwin
763 - The y and x coordinates of the top left of targetwin on
764 the screen
765 - The size of targetwin in y and x dimensions.
766
767 Outputting characters and strings are achieved by char and
768 string respectively.
769
770 To draw a border around window targetwin, use border. Note that
771 the border is not subsequently handled specially: in other
772 words, the border is simply a set of characters output at the
773 edge of the window. Hence it can be overwritten, can scroll off
774 the window, etc.
775
776 The subcommand attr will set targetwin's attributes or fore‐
777 ground/background color pair for any successive character out‐
778 put. Each attribute given on the line may be prepended by a +
779 to set or a - to unset that attribute; + is assumed if absent.
780 The attributes supported are blink, bold, dim, reverse, stand‐
781 out, and underline.
782
783 Each fg_col/bg_col attribute (to be read as `fg_col on bg_col')
784 sets the foreground and background color for character output.
785 The color default is sometimes available (in particular if the
786 library is ncurses), specifying the foreground or background
787 color with which the terminal started. The color pair
788 default/default is always available. To use more than the 8
789 named colors (red, green, etc.) construct the fg_col/bg_col
790 pairs where fg_col and bg_col are decimal integers, e.g 128/200.
791 The maximum color value is 254 if the terminal supports 256 col‐
792 ors.
793
794 bg overrides the color and other attributes of all characters in
795 the window. Its usual use is to set the background initially,
796 but it will overwrite the attributes of any characters at the
797 time when it is called. In addition to the arguments allowed
798 with attr, an argument @char specifies a character to be shown
799 in otherwise blank areas of the window. Owing to limitations of
800 curses this cannot be a multibyte character (use of ASCII char‐
801 acters only is recommended). As the specified set of attributes
802 override the existing background, turning attributes off in the
803 arguments is not useful, though this does not cause an error.
804
805 The subcommand scroll can be used with on or off to enabled or
806 disable scrolling of a window when the cursor would otherwise
807 move below the window due to typing or output. It can also be
808 used with a positive or negative integer to scroll the window up
809 or down the given number of lines without changing the current
810 cursor position (which therefore appears to move in the opposite
811 direction relative to the window). In the second case, if
812 scrolling is off it is temporarily turned on to allow the window
813 to be scrolled.
814
815 The subcommand input reads a single character from the window
816 without echoing it back. If param is supplied the character is
817 assigned to the parameter param, else it is assigned to the
818 parameter REPLY.
819
820 If both param and kparam are supplied, the key is read in `key‐
821 pad' mode. In this mode special keys such as function keys and
822 arrow keys return the name of the key in the parameter kparam.
823 The key names are the macros defined in the curses.h or
824 ncurses.h with the prefix `KEY_' removed; see also the descrip‐
825 tion of the parameter zcurses_keycodes below. Other keys cause
826 a value to be set in param as before. On a successful return
827 only one of param or kparam contains a non-empty string; the
828 other is set to an empty string.
829
830 If mparam is also supplied, input attempts to handle mouse
831 input. This is only available with the ncurses library; mouse
832 handling can be detected by checking for the exit status of
833 `zcurses mouse' with no arguments. If a mouse button is clicked
834 (or double- or triple-clicked, or pressed or released with a
835 configurable delay from being clicked) then kparam is set to the
836 string MOUSE, and mparam is set to an array consisting of the
837 following elements:
838 - An identifier to discriminate different input devices;
839 this is only rarely useful.
840 - The x, y and z coordinates of the mouse click relative to
841 the full screen, as three elements in that order (i.e.
842 the y coordinate is, unusually, after the x coordinate).
843 The z coordinate is only available for a few unusual
844 input devices and is otherwise set to zero.
845 - Any events that occurred as separate items; usually there
846 will be just one. An event consists of PRESSED,
847 RELEASED, CLICKED, DOUBLE_CLICKED or TRIPLE_CLICKED fol‐
848 lowed immediately (in the same element) by the number of
849 the button.
850 - If the shift key was pressed, the string SHIFT.
851 - If the control key was pressed, the string CTRL.
852 - If the alt key was pressed, the string ALT.
853
854 Not all mouse events may be passed through to the terminal win‐
855 dow; most terminal emulators handle some mouse events them‐
856 selves. Note that the ncurses manual implies that using input
857 both with and without mouse handling may cause the mouse cursor
858 to appear and disappear.
859
860 The subcommand mouse can be used to configure the use of the
861 mouse. There is no window argument; mouse options are global.
862 `zcurses mouse' with no arguments returns status 0 if mouse han‐
863 dling is possible, else status 1. Otherwise, the possible argu‐
864 ments (which may be combined on the same command line) are as
865 follows. delay num sets the maximum delay in milliseconds
866 between press and release events to be considered as a click;
867 the value 0 disables click resolution, and the default is one
868 sixth of a second. motion proceeded by an optional `+' (the
869 default) or - turns on or off reporting of mouse motion in addi‐
870 tion to clicks, presses and releases, which are always reported.
871 However, it appears reports for mouse motion are not currently
872 implemented.
873
874 The subcommand timeout specifies a timeout value for input from
875 targetwin. If intval is negative, `zcurses input' waits indefi‐
876 nitely for a character to be typed; this is the default. If
877 intval is zero, `zcurses input' returns immediately; if there is
878 typeahead it is returned, else no input is done and status 1 is
879 returned. If intval is positive, `zcurses input' waits intval
880 milliseconds for input and if there is none at the end of that
881 period returns status 1.
882
883 The subcommand querychar queries the character at the current
884 cursor position. The return values are stored in the array
885 named param if supplied, else in the array reply. The first
886 value is the character (which may be a multibyte character if
887 the system supports them); the second is the color pair in the
888 usual fg_col/bg_col notation, or 0 if color is not supported.
889 Any attributes other than color that apply to the character, as
890 set with the subcommand attr, appear as additional elements.
891
892 The subcommand resize resizes stdscr and all windows to given
893 dimensions (windows that stick out from the new dimensions are
894 resized down). The underlying curses extension (resize_term
895 call) can be unavailable. To verify, zeroes can be used for
896 height and width. If the result of the subcommand is 0,
897 resize_term is available (2 otherwise). Tests show that resizing
898 can be normally accomplished by calling zcurses end and zcurses
899 refresh. The resize subcommand is provided for versatility. Mul‐
900 tiple system configurations have been checked and zcurses end
901 and zcurses refresh are still needed for correct terminal state
902 after resize. To invoke them with resize, use endwin argument.
903 Using nosave argument will cause new terminal state to not be
904 saved internally by zcurses. This is also provided for versatil‐
905 ity and should normally be not needed.
906
907 Parameters
908 ZCURSES_COLORS
909 Readonly integer. The maximum number of colors the terminal
910 supports. This value is initialised by the curses library and
911 is not available until the first time zcurses init is run.
912
913 ZCURSES_COLOR_PAIRS
914 Readonly integer. The maximum number of color pairs
915 fg_col/bg_col that may be defined in `zcurses attr' commands;
916 note this limit applies to all color pairs that have been used
917 whether or not they are currently active. This value is ini‐
918 tialised by the curses library and is not available until the
919 first time zcurses init is run.
920
921 zcurses_attrs
922 Readonly array. The attributes supported by zsh/curses; avail‐
923 able as soon as the module is loaded.
924
925 zcurses_colors
926 Readonly array. The colors supported by zsh/curses; available
927 as soon as the module is loaded.
928
929 zcurses_keycodes
930 Readonly array. The values that may be returned in the second
931 parameter supplied to `zcurses input' in the order in which they
932 are defined internally by curses. Not all function keys are
933 listed, only F0; curses reserves space for F0 up to F63.
934
935 zcurses_windows
936 Readonly array. The current list of windows, i.e. all windows
937 that have been created with `zcurses addwin' and not removed
938 with `zcurses delwin'.
939
941 The zsh/datetime module makes available one builtin command:
942
943 strftime [ -s scalar ] format [ epochtime [ nanoseconds ] ]
944 strftime -r [ -q ] [ -s scalar ] format timestring
945 Output the date in the format specified. With no epochtime, the
946 current system date/time is used; optionally, epochtime may be
947 used to specify the number of seconds since the epoch, and
948 nanoseconds may additionally be used to specify the number of
949 nanoseconds past the second (otherwise that number is assumed to
950 be 0). See strftime(3) for details. The zsh extensions
951 described in the section EXPANSION OF PROMPT SEQUENCES in zsh‐
952 misc(1) are also available.
953
954 -q Run quietly; suppress printing of all error messages
955 described below. Errors for invalid epochtime values are
956 always printed.
957
958 -r With the option -r (reverse), use format to parse the
959 input string timestring and output the number of seconds
960 since the epoch at which the time occurred. The parsing
961 is implemented by the system function strptime; see strp‐
962 time(3). This means that zsh format extensions are not
963 available, but for reverse lookup they are not required.
964
965 In most implementations of strftime any timezone in the
966 timestring is ignored and the local timezone declared by
967 the TZ environment variable is used; other parameters are
968 set to zero if not present.
969
970 If timestring does not match format the command returns
971 status 1 and prints an error message. If timestring
972 matches format but not all characters in timestring were
973 used, the conversion succeeds but also prints an error
974 message.
975
976 If either of the system functions strptime or mktime is
977 not available, status 2 is returned and an error message
978 is printed.
979
980 -s scalar
981 Assign the date string (or epoch time in seconds if -r is
982 given) to scalar instead of printing it.
983
984 Note that depending on the system's declared integral time type,
985 strftime may produce incorrect results for epoch times greater
986 than 2147483647 which corresponds to 2038-01-19 03:14:07 +0000.
987
988 The zsh/datetime module makes available several parameters; all are
989 readonly:
990
991 EPOCHREALTIME
992 A floating point value representing the number of seconds since
993 the epoch. The notional accuracy is to nanoseconds if the
994 clock_gettime call is available and to microseconds otherwise,
995 but in practice the range of double precision floating point and
996 shell scheduling latencies may be significant effects.
997
998 EPOCHSECONDS
999 An integer value representing the number of seconds since the
1000 epoch.
1001
1002 epochtime
1003 An array value containing the number of seconds since the epoch
1004 in the first element and the remainder of the time since the
1005 epoch in nanoseconds in the second element. To ensure the two
1006 elements are consistent the array should be copied or otherwise
1007 referenced as a single substitution before the values are used.
1008 The following idiom may be used:
1009
1010 for secs nsecs in $epochtime; do
1011 ...
1012 done
1013
1015 The zsh/db/gdbm module is used to create "tied" associative arrays that
1016 interface to database files. If the GDBM interface is not available,
1017 the builtins defined by this module will report an error. This module
1018 is also intended as a prototype for creating additional database inter‐
1019 faces, so the ztie builtin may move to a more generic module in the
1020 future.
1021
1022 The builtins in this module are:
1023
1024 ztie -d db/gdbm -f filename [ -r ] arrayname
1025 Open the GDBM database identified by filename and, if success‐
1026 ful, create the associative array arrayname linked to the file.
1027 To create a local tied array, the parameter must first be
1028 declared, so commands similar to the following would be executed
1029 inside a function scope:
1030
1031 local -A sampledb
1032 ztie -d db/gdbm -f sample.gdbm sampledb
1033
1034 The -r option opens the database file for reading only, creating
1035 a parameter with the readonly attribute. Without this option,
1036 using `ztie' on a file for which the user does not have write
1037 permission is an error. If writable, the database is opened
1038 synchronously so fields changed in arrayname are immediately
1039 written to filename.
1040
1041 Changes to the file modes filename after it has been opened do
1042 not alter the state of arrayname, but `typeset -r arrayname'
1043 works as expected.
1044
1045 zuntie [ -u ] arrayname ...
1046 Close the GDBM database associated with each arrayname and then
1047 unset the parameter. The -u option forces an unset of parame‐
1048 ters made readonly with `ztie -r'.
1049
1050 This happens automatically if the parameter is explicitly unset
1051 or its local scope (function) ends. Note that a readonly param‐
1052 eter may not be explicitly unset, so the only way to unset a
1053 global parameter created with `ztie -r' is to use `zuntie -u'.
1054
1055 zgdbmpath parametername
1056 Put path to database file assigned to parametername into REPLY
1057 scalar.
1058
1059 zgdbm_tied
1060 Array holding names of all tied parameters.
1061
1062 The fields of an associative array tied to GDBM are neither cached nor
1063 otherwise stored in memory, they are read from or written to the data‐
1064 base on each reference. Thus, for example, the values in a readonly
1065 array may be changed by a second writer of the same database file.
1066
1068 The zsh/deltochar module makes available two ZLE functions:
1069
1070 delete-to-char
1071 Read a character from the keyboard, and delete from the cursor
1072 position up to and including the next (or, with repeat count n,
1073 the nth) instance of that character. Negative repeat counts
1074 mean delete backwards.
1075
1076 zap-to-char
1077 This behaves like delete-to-char, except that the final occur‐
1078 rence of the character itself is not deleted.
1079
1081 The zsh/example module makes available one builtin command:
1082
1083 example [ -flags ] [ args ... ]
1084 Displays the flags and arguments it is invoked with.
1085
1086 The purpose of the module is to serve as an example of how to write a
1087 module.
1088
1090 The zsh/files module makes available some common commands for file
1091 manipulation as builtins; these commands are probably not needed for
1092 many normal situations but can be useful in emergency recovery situa‐
1093 tions with constrained resources. The commands do not implement all
1094 features now required by relevant standards committees.
1095
1096 For all commands, a variant beginning zf_ is also available and loaded
1097 automatically. Using the features capability of zmodload will let you
1098 load only those names you want. Note that it's possible to load only
1099 the builtins with zsh-specific names using the following command:
1100
1101 zmodload -m -F zsh/files b:zf_\*
1102
1103 The commands loaded by default are:
1104
1105 chgrp [ -hRs ] group filename ...
1106 Changes group of files specified. This is equivalent to chown
1107 with a user-spec argument of `:group'.
1108
1109 chmod [ -Rs ] mode filename ...
1110 Changes mode of files specified.
1111
1112 The specified mode must be in octal.
1113
1114 The -R option causes chmod to recursively descend into directo‐
1115 ries, changing the mode of all files in the directory after
1116 changing the mode of the directory itself.
1117
1118 The -s option is a zsh extension to chmod functionality. It
1119 enables paranoid behaviour, intended to avoid security problems
1120 involving a chmod being tricked into affecting files other than
1121 the ones intended. It will refuse to follow symbolic links, so
1122 that (for example) ``chmod 600 /tmp/foo/passwd'' can't acciden‐
1123 tally chmod /etc/passwd if /tmp/foo happens to be a link to
1124 /etc. It will also check where it is after leaving directories,
1125 so that a recursive chmod of a deep directory tree can't end up
1126 recursively chmoding /usr as a result of directories being moved
1127 up the tree.
1128
1129 chown [ -hRs ] user-spec filename ...
1130 Changes ownership and group of files specified.
1131
1132 The user-spec can be in four forms:
1133
1134 user change owner to user; do not change group
1135 user:: change owner to user; do not change group
1136 user: change owner to user; change group to user's primary
1137 group
1138 user:group
1139 change owner to user; change group to group
1140 :group do not change owner; change group to group
1141
1142 In each case, the `:' may instead be a `.'. The rule is that if
1143 there is a `:' then the separator is `:', otherwise if there is
1144 a `.' then the separator is `.', otherwise there is no separa‐
1145 tor.
1146
1147 Each of user and group may be either a username (or group name,
1148 as appropriate) or a decimal user ID (group ID). Interpretation
1149 as a name takes precedence, if there is an all-numeric username
1150 (or group name).
1151
1152 If the target is a symbolic link, the -h option causes chown to
1153 set the ownership of the link instead of its target.
1154
1155 The -R option causes chown to recursively descend into directo‐
1156 ries, changing the ownership of all files in the directory after
1157 changing the ownership of the directory itself.
1158
1159 The -s option is a zsh extension to chown functionality. It
1160 enables paranoid behaviour, intended to avoid security problems
1161 involving a chown being tricked into affecting files other than
1162 the ones intended. It will refuse to follow symbolic links, so
1163 that (for example) ``chown luser /tmp/foo/passwd'' can't acci‐
1164 dentally chown /etc/passwd if /tmp/foo happens to be a link to
1165 /etc. It will also check where it is after leaving directories,
1166 so that a recursive chown of a deep directory tree can't end up
1167 recursively chowning /usr as a result of directories being moved
1168 up the tree.
1169
1170 ln [ -dfhins ] filename dest
1171 ln [ -dfhins ] filename ... dir
1172 Creates hard (or, with -s, symbolic) links. In the first form,
1173 the specified destination is created, as a link to the specified
1174 filename. In the second form, each of the filenames is taken in
1175 turn, and linked to a pathname in the specified directory that
1176 has the same last pathname component.
1177
1178 Normally, ln will not attempt to create hard links to directo‐
1179 ries. This check can be overridden using the -d option. Typi‐
1180 cally only the super-user can actually succeed in creating hard
1181 links to directories. This does not apply to symbolic links in
1182 any case.
1183
1184 By default, existing files cannot be replaced by links. The -i
1185 option causes the user to be queried about replacing existing
1186 files. The -f option causes existing files to be silently
1187 deleted, without querying. -f takes precedence.
1188
1189 The -h and -n options are identical and both exist for compati‐
1190 bility; either one indicates that if the target is a symlink
1191 then it should not be dereferenced. Typically this is used in
1192 combination with -sf so that if an existing link points to a
1193 directory then it will be removed, instead of followed. If this
1194 option is used with multiple filenames and the target is a sym‐
1195 bolic link pointing to a directory then the result is an error.
1196
1197 mkdir [ -p ] [ -m mode ] dir ...
1198 Creates directories. With the -p option, non-existing parent
1199 directories are first created if necessary, and there will be no
1200 complaint if the directory already exists. The -m option can be
1201 used to specify (in octal) a set of file permissions for the
1202 created directories, otherwise mode 777 modified by the current
1203 umask (see umask(2)) is used.
1204
1205 mv [ -fi ] filename dest
1206 mv [ -fi ] filename ... dir
1207 Moves files. In the first form, the specified filename is moved
1208 to the specified destination. In the second form, each of the
1209 filenames is taken in turn, and moved to a pathname in the spec‐
1210 ified directory that has the same last pathname component.
1211
1212 By default, the user will be queried before replacing any file
1213 that the user cannot write to, but writable files will be
1214 silently removed. The -i option causes the user to be queried
1215 about replacing any existing files. The -f option causes any
1216 existing files to be silently deleted, without querying. -f
1217 takes precedence.
1218
1219 Note that this mv will not move files across devices. Histori‐
1220 cal versions of mv, when actual renaming is impossible, fall
1221 back on copying and removing files; if this behaviour is
1222 desired, use cp and rm manually. This may change in a future
1223 version.
1224
1225 rm [ -dfiRrs ] filename ...
1226 Removes files and directories specified.
1227
1228 Normally, rm will not remove directories (except with the -R or
1229 -r options). The -d option causes rm to try removing directo‐
1230 ries with unlink (see unlink(2)), the same method used for
1231 files. Typically only the super-user can actually succeed in
1232 unlinking directories in this way. -d takes precedence over -R
1233 and -r.
1234
1235 By default, the user will be queried before removing any file
1236 that the user cannot write to, but writable files will be
1237 silently removed. The -i option causes the user to be queried
1238 about removing any files. The -f option causes files to be
1239 silently deleted, without querying, and suppresses all error
1240 indications. -f takes precedence.
1241
1242 The -R and -r options cause rm to recursively descend into
1243 directories, deleting all files in the directory before removing
1244 the directory with the rmdir system call (see rmdir(2)).
1245
1246 The -s option is a zsh extension to rm functionality. It
1247 enables paranoid behaviour, intended to avoid common security
1248 problems involving a root-run rm being tricked into removing
1249 files other than the ones intended. It will refuse to follow
1250 symbolic links, so that (for example) ``rm /tmp/foo/passwd''
1251 can't accidentally remove /etc/passwd if /tmp/foo happens to be
1252 a link to /etc. It will also check where it is after leaving
1253 directories, so that a recursive removal of a deep directory
1254 tree can't end up recursively removing /usr as a result of
1255 directories being moved up the tree.
1256
1257 rmdir dir ...
1258 Removes empty directories specified.
1259
1260 sync Calls the system call of the same name (see sync(2)), which
1261 flushes dirty buffers to disk. It might return before the I/O
1262 has actually been completed.
1263
1265 The zsh/langinfo module makes available one parameter:
1266
1267 langinfo
1268 An associative array that maps langinfo elements to their val‐
1269 ues.
1270
1271 Your implementation may support a number of the following keys:
1272
1273 CODESET, D_T_FMT, D_FMT, T_FMT, RADIXCHAR, THOUSEP, YESEXPR,
1274 NOEXPR, CRNCYSTR, ABDAY_{1..7}, DAY_{1..7}, ABMON_{1..12},
1275 MON_{1..12}, T_FMT_AMPM, AM_STR, PM_STR, ERA, ERA_D_FMT,
1276 ERA_D_T_FMT, ERA_T_FMT, ALT_DIGITS
1277
1279 The zsh/mapfile module provides one special associative array parameter
1280 of the same name.
1281
1282 mapfile
1283 This associative array takes as keys the names of files; the
1284 resulting value is the content of the file. The value is
1285 treated identically to any other text coming from a parameter.
1286 The value may also be assigned to, in which case the file in
1287 question is written (whether or not it originally existed); or
1288 an element may be unset, which will delete the file in question.
1289 For example, `vared mapfile[myfile]' works as expected, editing
1290 the file `myfile'.
1291
1292 When the array is accessed as a whole, the keys are the names of
1293 files in the current directory, and the values are empty (to
1294 save a huge overhead in memory). Thus ${(k)mapfile} has the
1295 same effect as the glob operator *(D), since files beginning
1296 with a dot are not special. Care must be taken with expressions
1297 such as rm ${(k)mapfile}, which will delete every file in the
1298 current directory without the usual `rm *' test.
1299
1300 The parameter mapfile may be made read-only; in that case, files
1301 referenced may not be written or deleted.
1302
1303 A file may conveniently be read into an array as one line per
1304 element with the form `array=("${(f@)mapfile[filename]}")'. The
1305 double quotes and the `@' are necessary to prevent empty lines
1306 from being removed. Note that if the file ends with a newline,
1307 the shell will split on the final newline, generating an addi‐
1308 tional empty field; this can be suppressed by using
1309 `array=("${(f@)${mapfile[filename]%$'\n'}}")'.
1310
1311 Limitations
1312 Although reading and writing of the file in question is efficiently
1313 handled, zsh's internal memory management may be arbitrarily baroque;
1314 however, mapfile is usually very much more efficient than anything
1315 involving a loop. Note in particular that the whole contents of the
1316 file will always reside physically in memory when accessed (possibly
1317 multiple times, due to standard parameter substitution operations). In
1318 particular, this means handling of sufficiently long files (greater
1319 than the machine's swap space, or than the range of the pointer type)
1320 will be incorrect.
1321
1322 No errors are printed or flagged for non-existent, unreadable, or
1323 unwritable files, as the parameter mechanism is too low in the shell
1324 execution hierarchy to make this convenient.
1325
1326 It is unfortunate that the mechanism for loading modules does not yet
1327 allow the user to specify the name of the shell parameter to be given
1328 the special behaviour.
1329
1331 The zsh/mathfunc module provides standard mathematical functions for
1332 use when evaluating mathematical formulae. The syntax agrees with nor‐
1333 mal C and FORTRAN conventions, for example,
1334
1335 (( f = sin(0.3) ))
1336
1337 assigns the sine of 0.3 to the parameter f.
1338
1339 Most functions take floating point arguments and return a floating
1340 point value. However, any necessary conversions from or to integer
1341 type will be performed automatically by the shell. Apart from atan
1342 with a second argument and the abs, int and float functions, all func‐
1343 tions behave as noted in the manual page for the corresponding C func‐
1344 tion, except that any arguments out of range for the function in ques‐
1345 tion will be detected by the shell and an error reported.
1346
1347 The following functions take a single floating point argument: acos,
1348 acosh, asin, asinh, atan, atanh, cbrt, ceil, cos, cosh, erf, erfc, exp,
1349 expm1, fabs, floor, gamma, j0, j1, lgamma, log, log10, log1p, log2,
1350 logb, sin, sinh, sqrt, tan, tanh, y0, y1. The atan function can
1351 optionally take a second argument, in which case it behaves like the C
1352 function atan2. The ilogb function takes a single floating point argu‐
1353 ment, but returns an integer.
1354
1355 The function signgam takes no arguments, and returns an integer, which
1356 is the C variable of the same name, as described in gamma(3). Note
1357 that it is therefore only useful immediately after a call to gamma or
1358 lgamma. Note also that `signgam()' and `signgam' are distinct expres‐
1359 sions.
1360
1361 The functions min, max, and sum are defined not in this module but in
1362 the zmathfunc autoloadable function, described in the section `Mathe‐
1363 matical Functions' in zshcontrib(1).
1364
1365 The following functions take two floating point arguments: copysign,
1366 fmod, hypot, nextafter.
1367
1368 The following take an integer first argument and a floating point sec‐
1369 ond argument: jn, yn.
1370
1371 The following take a floating point first argument and an integer sec‐
1372 ond argument: ldexp, scalb.
1373
1374 The function abs does not convert the type of its single argument; it
1375 returns the absolute value of either a floating point number or an
1376 integer. The functions float and int convert their arguments into a
1377 floating point or integer value (by truncation) respectively.
1378
1379 Note that the C pow function is available in ordinary math evaluation
1380 as the `**' operator and is not provided here.
1381
1382 The function rand48 is available if your system's mathematical library
1383 has the function erand48(3). It returns a pseudo-random floating point
1384 number between 0 and 1. It takes a single string optional argument.
1385
1386 If the argument is not present, the random number seed is initialised
1387 by three calls to the rand(3) function --- this produces the same ran‐
1388 dom numbers as the next three values of $RANDOM.
1389
1390 If the argument is present, it gives the name of a scalar parameter
1391 where the current random number seed will be stored. On the first
1392 call, the value must contain at least twelve hexadecimal digits (the
1393 remainder of the string is ignored), or the seed will be initialised in
1394 the same manner as for a call to rand48 with no argument. Subsequent
1395 calls to rand48(param) will then maintain the seed in the parameter
1396 param as a string of twelve hexadecimal digits, with no base signifier.
1397 The random number sequences for different parameters are completely
1398 independent, and are also independent from that used by calls to rand48
1399 with no argument.
1400
1401 For example, consider
1402
1403 print $(( rand48(seed) ))
1404 print $(( rand48() ))
1405 print $(( rand48(seed) ))
1406
1407 Assuming $seed does not exist, it will be initialised by the first
1408 call. In the second call, the default seed is initialised; note, how‐
1409 ever, that because of the properties of rand() there is a correlation
1410 between the seeds used for the two initialisations, so for more secure
1411 uses, you should generate your own 12-byte seed. The third call
1412 returns to the same sequence of random numbers used in the first call,
1413 unaffected by the intervening rand48().
1414
1416 The zsh/nearcolor module replaces colours specified as hex triplets
1417 with the nearest colour in the 88 or 256 colour palettes that are
1418 widely used by terminal emulators. By default, 24-bit true colour
1419 escape codes are generated when colours are specified using hex
1420 triplets. These are not supported by all terminals. The purpose of
1421 this module is to make it easier to define colour preferences in a form
1422 that can work across a range of terminal emulators.
1423
1424 Aside from the default colour, the ANSI standard for terminal escape
1425 codes provides for eight colours. The bright attribute brings this to
1426 sixteen. These basic colours are commonly used in terminal applications
1427 due to being widely supported. Expanded 88 and 256 colour palettes are
1428 also common and, while the first sixteen colours vary somewhat between
1429 terminals and configurations, these add a generally consistent and pre‐
1430 dictable set of colours.
1431
1432 In order to use the zsh/nearcolor module, it only needs to be loaded.
1433 Thereafter, whenever a colour is specified using a hex triplet, it will
1434 be compared against each of the available colours and the closest will
1435 be selected. The first sixteen colours are never matched in this
1436 process due to being unpredictable.
1437
1438 It isn't possible to reliably detect support for true colour in the
1439 terminal emulator. It is therefore recommended to be selective in load‐
1440 ing the zsh/nearcolor module. For example, the following checks the
1441 COLORTERM environment variable:
1442
1443 [[ $COLORTERM = *(24bit|truecolor)* ]] || zmodload zsh/nearcolor
1444
1445 Note that some terminals accept the true color escape codes but map
1446 them internally to a more limited palette in a similar manner to the
1447 zsh/nearcolor module.
1448
1450 The zsh/newuser module is loaded at boot if it is available, the RCS
1451 option is set, and the PRIVILEGED option is not set (all three are true
1452 by default). This takes place immediately after commands in the global
1453 zshenv file (typically /etc/zshenv), if any, have been executed. If
1454 the module is not available it is silently ignored by the shell; the
1455 module may safely be removed from $MODULE_PATH by the administrator if
1456 it is not required.
1457
1458 On loading, the module tests if any of the start-up files .zshenv,
1459 .zprofile, .zshrc or .zlogin exist in the directory given by the envi‐
1460 ronment variable ZDOTDIR, or the user's home directory if that is not
1461 set. The test is not performed and the module halts processing if the
1462 shell was in an emulation mode (i.e. had been invoked as some other
1463 shell than zsh).
1464
1465 If none of the start-up files were found, the module then looks for the
1466 file newuser first in a sitewide directory, usually the parent direc‐
1467 tory of the site-functions directory, and if that is not found the mod‐
1468 ule searches in a version-specific directory, usually the parent of the
1469 functions directory containing version-specific functions. (These
1470 directories can be configured when zsh is built using the
1471 --enable-site-scriptdir=dir and --enable-scriptdir=dir flags to config‐
1472 ure, respectively; the defaults are prefix/share/zsh and pre‐
1473 fix/share/zsh/$ZSH_VERSION where the default prefix is /usr/local.)
1474
1475 If the file newuser is found, it is then sourced in the same manner as
1476 a start-up file. The file is expected to contain code to install
1477 start-up files for the user, however any valid shell code will be exe‐
1478 cuted.
1479
1480 The zsh/newuser module is then unconditionally unloaded.
1481
1482 Note that it is possible to achieve exactly the same effect as the
1483 zsh/newuser module by adding code to /etc/zshenv. The module exists
1484 simply to allow the shell to make arrangements for new users without
1485 the need for intervention by package maintainers and system administra‐
1486 tors.
1487
1488 The script supplied with the module invokes the shell function
1489 zsh-newuser-install. This may be invoked directly by the user even if
1490 the zsh/newuser module is disabled. Note, however, that if the module
1491 is not installed the function will not be installed either. The func‐
1492 tion is documented in the section User Configuration Functions in zsh‐
1493 contrib(1).
1494
1496 The zsh/parameter module gives access to some of the internal hash
1497 tables used by the shell by defining some special parameters.
1498
1499 options
1500 The keys for this associative array are the names of the options
1501 that can be set and unset using the setopt and unsetopt
1502 builtins. The value of each key is either the string on if the
1503 option is currently set, or the string off if the option is
1504 unset. Setting a key to one of these strings is like setting or
1505 unsetting the option, respectively. Unsetting a key in this
1506 array is like setting it to the value off.
1507
1508 commands
1509 This array gives access to the command hash table. The keys are
1510 the names of external commands, the values are the pathnames of
1511 the files that would be executed when the command would be
1512 invoked. Setting a key in this array defines a new entry in this
1513 table in the same way as with the hash builtin. Unsetting a key
1514 as in `unset "commands[foo]"' removes the entry for the given
1515 key from the command hash table.
1516
1517 functions
1518 This associative array maps names of enabled functions to their
1519 definitions. Setting a key in it is like defining a function
1520 with the name given by the key and the body given by the value.
1521 Unsetting a key removes the definition for the function named by
1522 the key.
1523
1524 dis_functions
1525 Like functions but for disabled functions.
1526
1527 functions_source
1528 This readonly associative array maps names of enabled functions
1529 to the name of the file containing the source of the function.
1530
1531 For an autoloaded function that has already been loaded, or
1532 marked for autoload with an absolute path, or that has had its
1533 path resolved with `functions -r', this is the file found for
1534 autoloading, resolved to an absolute path.
1535
1536 For a function defined within the body of a script or sourced
1537 file, this is the name of that file. In this case, this is the
1538 exact path originally used to that file, which may be a relative
1539 path.
1540
1541 For any other function, including any defined at an interactive
1542 prompt or an autoload function whose path has not yet been
1543 resolved, this is the empty string. However, the hash element
1544 is reported as defined just so long as the function is present:
1545 the keys to this hash are the same as those to $functions.
1546
1547 dis_functions_source
1548 Like functions_source but for disabled functions.
1549
1550 builtins
1551 This associative array gives information about the builtin com‐
1552 mands currently enabled. The keys are the names of the builtin
1553 commands and the values are either `undefined' for builtin com‐
1554 mands that will automatically be loaded from a module if invoked
1555 or `defined' for builtin commands that are already loaded.
1556
1557 dis_builtins
1558 Like builtins but for disabled builtin commands.
1559
1560 reswords
1561 This array contains the enabled reserved words.
1562
1563 dis_reswords
1564 Like reswords but for disabled reserved words.
1565
1566 patchars
1567 This array contains the enabled pattern characters.
1568
1569 dis_patchars
1570 Like patchars but for disabled pattern characters.
1571
1572 aliases
1573 This maps the names of the regular aliases currently enabled to
1574 their expansions.
1575
1576 dis_aliases
1577 Like aliases but for disabled regular aliases.
1578
1579 galiases
1580 Like aliases, but for global aliases.
1581
1582 dis_galiases
1583 Like galiases but for disabled global aliases.
1584
1585 saliases
1586 Like raliases, but for suffix aliases.
1587
1588 dis_saliases
1589 Like saliases but for disabled suffix aliases.
1590
1591 parameters
1592 The keys in this associative array are the names of the parame‐
1593 ters currently defined. The values are strings describing the
1594 type of the parameter, in the same format used by the t parame‐
1595 ter flag, see zshexpn(1) . Setting or unsetting keys in this
1596 array is not possible.
1597
1598 modules
1599 An associative array giving information about modules. The keys
1600 are the names of the modules loaded, registered to be
1601 autoloaded, or aliased. The value says which state the named
1602 module is in and is one of the strings `loaded', `autoloaded',
1603 or `alias:name', where name is the name the module is aliased
1604 to.
1605
1606 Setting or unsetting keys in this array is not possible.
1607
1608 dirstack
1609 A normal array holding the elements of the directory stack. Note
1610 that the output of the dirs builtin command includes one more
1611 directory, the current working directory.
1612
1613 history
1614 This associative array maps history event numbers to the full
1615 history lines. Although it is presented as an associative
1616 array, the array of all values (${history[@]}) is guaranteed to
1617 be returned in order from most recent to oldest history event,
1618 that is, by decreasing history event number.
1619
1620 historywords
1621 A special array containing the words stored in the history.
1622 These also appear in most to least recent order.
1623
1624 jobdirs
1625 This associative array maps job numbers to the directories from
1626 which the job was started (which may not be the current direc‐
1627 tory of the job).
1628
1629 The keys of the associative arrays are usually valid job num‐
1630 bers, and these are the values output with, for example,
1631 ${(k)jobdirs}. Non-numeric job references may be used when
1632 looking up a value; for example, ${jobdirs[%+]} refers to the
1633 current job.
1634
1635 jobtexts
1636 This associative array maps job numbers to the texts of the com‐
1637 mand lines that were used to start the jobs.
1638
1639 Handling of the keys of the associative array is as described
1640 for jobdirs above.
1641
1642 jobstates
1643 This associative array gives information about the states of the
1644 jobs currently known. The keys are the job numbers and the val‐
1645 ues are strings of the form `job-state:mark:pid=state...'. The
1646 job-state gives the state the whole job is currently in, one of
1647 `running', `suspended', or `done'. The mark is `+' for the cur‐
1648 rent job, `-' for the previous job and empty otherwise. This is
1649 followed by one `:pid=state' for every process in the job. The
1650 pids are, of course, the process IDs and the state describes the
1651 state of that process.
1652
1653 Handling of the keys of the associative array is as described
1654 for jobdirs above.
1655
1656 nameddirs
1657 This associative array maps the names of named directories to
1658 the pathnames they stand for.
1659
1660 userdirs
1661 This associative array maps user names to the pathnames of their
1662 home directories.
1663
1664 usergroups
1665 This associative array maps names of system groups of which the
1666 current user is a member to the corresponding group identifiers.
1667 The contents are the same as the groups output by the id com‐
1668 mand.
1669
1670 funcfiletrace
1671 This array contains the absolute line numbers and corresponding
1672 file names for the point where the current function, sourced
1673 file, or (if EVAL_LINENO is set) eval command was called. The
1674 array is of the same length as funcsourcetrace and functrace,
1675 but differs from funcsourcetrace in that the line and file are
1676 the point of call, not the point of definition, and differs from
1677 functrace in that all values are absolute line numbers in files,
1678 rather than relative to the start of a function, if any.
1679
1680 funcsourcetrace
1681 This array contains the file names and line numbers of the
1682 points where the functions, sourced files, and (if EVAL_LINENO
1683 is set) eval commands currently being executed were defined.
1684 The line number is the line where the `function name' or `name
1685 ()' started. In the case of an autoloaded function the line
1686 number is reported as zero. The format of each element is file‐
1687 name:lineno.
1688
1689 For functions autoloaded from a file in native zsh format, where
1690 only the body of the function occurs in the file, or for files
1691 that have been executed by the source or `.' builtins, the trace
1692 information is shown as filename:0, since the entire file is the
1693 definition. The source file name is resolved to an absolute
1694 path when the function is loaded or the path to it otherwise
1695 resolved.
1696
1697 Most users will be interested in the information in the func‐
1698 filetrace array instead.
1699
1700 funcstack
1701 This array contains the names of the functions, sourced files,
1702 and (if EVAL_LINENO is set) eval commands. currently being exe‐
1703 cuted. The first element is the name of the function using the
1704 parameter.
1705
1706 The standard shell array zsh_eval_context can be used to deter‐
1707 mine the type of shell construct being executed at each depth:
1708 note, however, that is in the opposite order, with the most
1709 recent item last, and it is more detailed, for example including
1710 an entry for toplevel, the main shell code being executed either
1711 interactively or from a script, which is not present in $func‐
1712 stack.
1713
1714 functrace
1715 This array contains the names and line numbers of the callers
1716 corresponding to the functions currently being executed. The
1717 format of each element is name:lineno. Callers are also shown
1718 for sourced files; the caller is the point where the source or
1719 `.' command was executed.
1720
1722 The zsh/pcre module makes some commands available as builtins:
1723
1724 pcre_compile [ -aimxs ] PCRE
1725 Compiles a perl-compatible regular expression.
1726
1727 Option -a will force the pattern to be anchored. Option -i will
1728 compile a case-insensitive pattern. Option -m will compile a
1729 multi-line pattern; that is, ^ and $ will match newlines within
1730 the pattern. Option -x will compile an extended pattern,
1731 wherein whitespace and # comments are ignored. Option -s makes
1732 the dot metacharacter match all characters, including those that
1733 indicate newline.
1734
1735 pcre_study
1736 Studies the previously-compiled PCRE which may result in faster
1737 matching.
1738
1739 pcre_match [ -v var ] [ -a arr ] [ -n offset ] [ -b ] string
1740 Returns successfully if string matches the previously-compiled
1741 PCRE.
1742
1743 Upon successful match, if the expression captures substrings
1744 within parentheses, pcre_match will set the array match to those
1745 substrings, unless the -a option is given, in which case it will
1746 set the array arr. Similarly, the variable MATCH will be set to
1747 the entire matched portion of the string, unless the -v option
1748 is given, in which case the variable var will be set. No vari‐
1749 ables are altered if there is no successful match. A -n option
1750 starts searching for a match from the byte offset position in
1751 string. If the -b option is given, the variable ZPCRE_OP will
1752 be set to an offset pair string, representing the byte offset
1753 positions of the entire matched portion within the string. For
1754 example, a ZPCRE_OP set to "32 45" indicates that the matched
1755 portion began on byte offset 32 and ended on byte offset 44.
1756 Here, byte offset position 45 is the position directly after the
1757 matched portion. Keep in mind that the byte position isn't nec‐
1758 essarily the same as the character position when UTF-8 charac‐
1759 ters are involved. Consequently, the byte offset positions are
1760 only to be relied on in the context of using them for subsequent
1761 searches on string, using an offset position as an argument to
1762 the -n option. This is mostly used to implement the "find all
1763 non-overlapping matches" functionality.
1764
1765 A simple example of "find all non-overlapping matches":
1766
1767 string="The following zip codes: 78884 90210 99513"
1768 pcre_compile -m "\d{5}"
1769 accum=()
1770 pcre_match -b -- $string
1771 while [[ $? -eq 0 ]] do
1772 b=($=ZPCRE_OP)
1773 accum+=$MATCH
1774 pcre_match -b -n $b[2] -- $string
1775 done
1776 print -l $accum
1777
1778 The zsh/pcre module makes available the following test condition:
1779
1780 expr -pcre-match pcre
1781 Matches a string against a perl-compatible regular expression.
1782
1783 For example,
1784
1785 [[ "$text" -pcre-match ^d+$ ]] &&
1786 print text variable contains only "d's".
1787
1788 If the REMATCH_PCRE option is set, the =~ operator is equivalent
1789 to -pcre-match, and the NO_CASE_MATCH option may be used. Note
1790 that NO_CASE_MATCH never applies to the pcre_match builtin,
1791 instead use the -i switch of pcre_compile.
1792
1794 The zsh/param/private module is used to create parameters whose scope
1795 is limited to the current function body, and not to other functions
1796 called by the current function.
1797
1798 This module provides a single autoloaded builtin:
1799
1800 private [ {+|-}AHUahlprtux ] [ {+|-}EFLRZi [ n ] ] [ name[=value] ... ]
1801 The private builtin accepts all the same options and arguments
1802 as local (zshbuiltins(1)) except for the `-T' option. Tied
1803 parameters may not be made private.
1804
1805 If used at the top level (outside a function scope), private
1806 creates a normal parameter in the same manner as declare or
1807 typeset. A warning about this is printed if WARN_CREATE_GLOBAL
1808 is set (zshoptions(1)). Used inside a function scope, private
1809 creates a local parameter similar to one declared with local,
1810 except having special properties noted below.
1811
1812 Special parameters which expose or manipulate internal shell
1813 state, such as ARGC, argv, COLUMNS, LINES, UID, EUID, IFS,
1814 PROMPT, RANDOM, SECONDS, etc., cannot be made private unless the
1815 `-h' option is used to hide the special meaning of the parame‐
1816 ter. This may change in the future.
1817
1818 As with other typeset equivalents, private is both a builtin and a
1819 reserved word, so arrays may be assigned with parenthesized word list
1820 name=(value...) syntax. However, the reserved word `private' is not
1821 available until zsh/param/private is loaded, so care must be taken with
1822 order of execution and parsing for function definitions which use pri‐
1823 vate. To compensate for this, the module also adds the option `-P' to
1824 the `local' builtin to declare private parameters.
1825
1826 For example, this construction fails if zsh/param/private has not yet
1827 been loaded when `bad_declaration' is defined:
1828 bad_declaration() {
1829 zmodload zsh/param/private
1830 private array=( one two three )
1831 }
1832
1833 This construction works because local is already a keyword, and the
1834 module is loaded before the statement is executed:
1835 good_declaration() {
1836 zmodload zsh/param/private
1837 local -P array=( one two three )
1838 }
1839
1840 The following is usable in scripts but may have trouble with autoload:
1841 zmodload zsh/param/private
1842 iffy_declaration() {
1843 private array=( one two three )
1844 }
1845
1846 The private builtin may always be used with scalar assignments and for
1847 declarations without assignments.
1848
1849 Parameters declared with private have the following properties:
1850
1851 · Within the function body where it is declared, the parameter
1852 behaves as a local, except as noted above for tied or special
1853 parameters.
1854
1855 · The type of a parameter declared private cannot be changed in
1856 the scope where it was declared, even if the parameter is unset.
1857 Thus an array cannot be assigned to a private scalar, etc.
1858
1859 · Within any other function called by the declaring function, the
1860 private parameter does NOT hide other parameters of the same
1861 name, so for example a global parameter of the same name is vis‐
1862 ible and may be assigned or unset. This includes calls to
1863 anonymous functions, although that may also change in the
1864 future.
1865
1866 · An exported private remains in the environment of inner scopes
1867 but appears unset for the current shell in those scopes. Gener‐
1868 ally, exporting private parameters should be avoided.
1869
1870 Note that this differs from the static scope defined by compiled lan‐
1871 guages derived from C, in that the a new call to the same function cre‐
1872 ates a new scope, i.e., the parameter is still associated with the call
1873 stack rather than with the function definition. It differs from ksh
1874 `typeset -S' because the syntax used to define the function has no
1875 bearing on whether the parameter scope is respected.
1876
1878 The zsh/regex module makes available the following test condition:
1879
1880 expr -regex-match regex
1881 Matches a string against a POSIX extended regular expression.
1882 On successful match, matched portion of the string will normally
1883 be placed in the MATCH variable. If there are any capturing
1884 parentheses within the regex, then the match array variable will
1885 contain those. If the match is not successful, then the vari‐
1886 ables will not be altered.
1887
1888 For example,
1889
1890 [[ alphabetical -regex-match ^a([^a]+)a([^a]+)a ]] &&
1891 print -l $MATCH X $match
1892
1893 If the option REMATCH_PCRE is not set, then the =~ operator will
1894 automatically load this module as needed and will invoke the
1895 -regex-match operator.
1896
1897 If BASH_REMATCH is set, then the array BASH_REMATCH will be set
1898 instead of MATCH and match.
1899
1901 The zsh/sched module makes available one builtin command and one param‐
1902 eter.
1903
1904 sched [-o] [+]hh:mm[:ss] command ...
1905 sched [-o] [+]seconds command ...
1906 sched [ -item ]
1907 Make an entry in the scheduled list of commands to execute. The
1908 time may be specified in either absolute or relative time, and
1909 either as hours, minutes and (optionally) seconds separated by a
1910 colon, or seconds alone. An absolute number of seconds indi‐
1911 cates the time since the epoch (1970/01/01 00:00); this is use‐
1912 ful in combination with the features in the zsh/datetime module,
1913 see the zsh/datetime module entry in zshmodules(1).
1914
1915 With no arguments, prints the list of scheduled commands. If
1916 the scheduled command has the -o flag set, this is shown at the
1917 start of the command.
1918
1919 With the argument `-item', removes the given item from the list.
1920 The numbering of the list is continuous and entries are in time
1921 order, so the numbering can change when entries are added or
1922 deleted.
1923
1924 Commands are executed either immediately before a prompt, or
1925 while the shell's line editor is waiting for input. In the lat‐
1926 ter case it is useful to be able to produce output that does not
1927 interfere with the line being edited. Providing the option -o
1928 causes the shell to clear the command line before the event and
1929 redraw it afterwards. This should be used with any scheduled
1930 event that produces visible output to the terminal; it is not
1931 needed, for example, with output that updates a terminal emula‐
1932 tor's title bar.
1933
1934 To effect changes to the editor buffer when an event executes,
1935 use the `zle' command with no arguments to test whether the edi‐
1936 tor is active, and if it is, then use `zle widget' to access the
1937 editor via the named widget.
1938
1939 The sched builtin is not made available by default when the
1940 shell starts in a mode emulating another shell. It can be made
1941 available with the command `zmodload -F zsh/sched b:sched'.
1942
1943 zsh_scheduled_events
1944 A readonly array corresponding to the events scheduled by the
1945 sched builtin. The indices of the array correspond to the num‐
1946 bers shown when sched is run with no arguments (provided that
1947 the KSH_ARRAYS option is not set). The value of the array con‐
1948 sists of the scheduled time in seconds since the epoch (see the
1949 section `The zsh/datetime Module' for facilities for using this
1950 number), followed by a colon, followed by any options (which may
1951 be empty but will be preceded by a `-' otherwise), followed by a
1952 colon, followed by the command to be executed.
1953
1954 The sched builtin should be used for manipulating the events.
1955 Note that this will have an immediate effect on the contents of
1956 the array, so that indices may become invalid.
1957
1959 The zsh/net/socket module makes available one builtin command:
1960
1961 zsocket [ -altv ] [ -d fd ] [ args ]
1962 zsocket is implemented as a builtin to allow full use of shell
1963 command line editing, file I/O, and job control mechanisms.
1964
1965 Outbound Connections
1966 zsocket [ -v ] [ -d fd ] filename
1967 Open a new Unix domain connection to filename. The shell param‐
1968 eter REPLY will be set to the file descriptor associated with
1969 that connection. Currently, only stream connections are sup‐
1970 ported.
1971
1972 If -d is specified, its argument will be taken as the target
1973 file descriptor for the connection.
1974
1975 In order to elicit more verbose output, use -v.
1976
1977 File descriptors can be closed with normal shell syntax when no
1978 longer needed, for example:
1979
1980 exec {REPLY}>&-
1981
1982 Inbound Connections
1983 zsocket -l [ -v ] [ -d fd ] filename
1984 zsocket -l will open a socket listening on filename. The shell
1985 parameter REPLY will be set to the file descriptor associated
1986 with that listener. The file descriptor remains open in sub‐
1987 shells and forked external executables.
1988
1989 If -d is specified, its argument will be taken as the target
1990 file descriptor for the connection.
1991
1992 In order to elicit more verbose output, use -v.
1993
1994 zsocket -a [ -tv ] [ -d targetfd ] listenfd
1995 zsocket -a will accept an incoming connection to the socket
1996 associated with listenfd. The shell parameter REPLY will be set
1997 to the file descriptor associated with the inbound connection.
1998 The file descriptor remains open in subshells and forked exter‐
1999 nal executables.
2000
2001 If -d is specified, its argument will be taken as the target
2002 file descriptor for the connection.
2003
2004 If -t is specified, zsocket will return if no incoming connec‐
2005 tion is pending. Otherwise it will wait for one.
2006
2007 In order to elicit more verbose output, use -v.
2008
2010 The zsh/stat module makes available one builtin command under two pos‐
2011 sible names:
2012
2013 zstat [ -gnNolLtTrs ] [ -f fd ] [ -H hash ] [ -A array ] [ -F fmt ]
2014 [ +element ] [ file ... ]
2015 stat ...
2016 The command acts as a front end to the stat system call (see
2017 stat(2)). The same command is provided with two names; as the
2018 name stat is often used by an external command it is recommended
2019 that only the zstat form of the command is used. This can be
2020 arranged by loading the module with the command `zmodload -F
2021 zsh/stat b:zstat'.
2022
2023 If the stat call fails, the appropriate system error message
2024 printed and status 1 is returned. The fields of struct stat
2025 give information about the files provided as arguments to the
2026 command. In addition to those available from the stat call, an
2027 extra element `link' is provided. These elements are:
2028
2029 device The number of the device on which the file resides.
2030
2031 inode The unique number of the file on this device (`inode'
2032 number).
2033
2034 mode The mode of the file; that is, the file's type and access
2035 permissions. With the -s option, this will be returned
2036 as a string corresponding to the first column in the dis‐
2037 play of the ls -l command.
2038
2039 nlink The number of hard links to the file.
2040
2041 uid The user ID of the owner of the file. With the -s
2042 option, this is displayed as a user name.
2043
2044 gid The group ID of the file. With the -s option, this is
2045 displayed as a group name.
2046
2047 rdev The raw device number. This is only useful for special
2048 devices.
2049
2050 size The size of the file in bytes.
2051
2052 atime
2053 mtime
2054 ctime The last access, modification and inode change times of
2055 the file, respectively, as the number of seconds since
2056 midnight GMT on 1st January, 1970. With the -s option,
2057 these are printed as strings for the local time zone; the
2058 format can be altered with the -F option, and with the -g
2059 option the times are in GMT.
2060
2061 blksize
2062 The number of bytes in one allocation block on the device
2063 on which the file resides.
2064
2065 block The number of disk blocks used by the file.
2066
2067 link If the file is a link and the -L option is in effect,
2068 this contains the name of the file linked to, otherwise
2069 it is empty. Note that if this element is selected
2070 (``zstat +link'') then the -L option is automatically
2071 used.
2072
2073 A particular element may be selected by including its name pre‐
2074 ceded by a `+' in the option list; only one element is allowed.
2075 The element may be shortened to any unique set of leading char‐
2076 acters. Otherwise, all elements will be shown for all files.
2077
2078 Options:
2079
2080 -A array
2081 Instead of displaying the results on standard output,
2082 assign them to an array, one struct stat element per
2083 array element for each file in order. In this case nei‐
2084 ther the name of the element nor the name of the files
2085 appears in array unless the -t or -n options were given,
2086 respectively. If -t is given, the element name appears
2087 as a prefix to the appropriate array element; if -n is
2088 given, the file name appears as a separate array element
2089 preceding all the others. Other formatting options are
2090 respected.
2091
2092 -H hash
2093 Similar to -A, but instead assign the values to hash.
2094 The keys are the elements listed above. If the -n option
2095 is provided then the name of the file is included in the
2096 hash with key name.
2097
2098 -f fd Use the file on file descriptor fd instead of named
2099 files; no list of file names is allowed in this case.
2100
2101 -F fmt Supplies a strftime (see strftime(3)) string for the for‐
2102 matting of the time elements. The format string supports
2103 all of the zsh extensions described in the section EXPAN‐
2104 SION OF PROMPT SEQUENCES in zshmisc(1). The -s option is
2105 implied.
2106
2107 -g Show the time elements in the GMT time zone. The -s
2108 option is implied.
2109
2110 -l List the names of the type elements (to standard output
2111 or an array as appropriate) and return immediately; argu‐
2112 ments, and options other than -A, are ignored.
2113
2114 -L Perform an lstat (see lstat(2)) rather than a stat system
2115 call. In this case, if the file is a link, information
2116 about the link itself rather than the target file is
2117 returned. This option is required to make the link ele‐
2118 ment useful. It's important to note that this is the
2119 exact opposite from ls(1), etc.
2120
2121 -n Always show the names of files. Usually these are only
2122 shown when output is to standard output and there is more
2123 than one file in the list.
2124
2125 -N Never show the names of files.
2126
2127 -o If a raw file mode is printed, show it in octal, which is
2128 more useful for human consumption than the default of
2129 decimal. A leading zero will be printed in this case.
2130 Note that this does not affect whether a raw or formatted
2131 file mode is shown, which is controlled by the -r and -s
2132 options, nor whether a mode is shown at all.
2133
2134 -r Print raw data (the default format) alongside string data
2135 (the -s format); the string data appears in parentheses
2136 after the raw data.
2137
2138 -s Print mode, uid, gid and the three time elements as
2139 strings instead of numbers. In each case the format is
2140 like that of ls -l.
2141
2142 -t Always show the type names for the elements of struct
2143 stat. Usually these are only shown when output is to
2144 standard output and no individual element has been
2145 selected.
2146
2147 -T Never show the type names of the struct stat elements.
2148
2150 The zsh/system module makes available various builtin commands and
2151 parameters.
2152
2153 Builtins
2154 syserror [ -e errvar ] [ -p prefix ] [ errno | errname ]
2155 This command prints out the error message associated with errno,
2156 a system error number, followed by a newline to standard error.
2157
2158 Instead of the error number, a name errname, for example ENOENT,
2159 may be used. The set of names is the same as the contents of
2160 the array errnos, see below.
2161
2162 If the string prefix is given, it is printed in front of the
2163 error message, with no intervening space.
2164
2165 If errvar is supplied, the entire message, without a newline, is
2166 assigned to the parameter names errvar and nothing is output.
2167
2168 A return status of 0 indicates the message was successfully
2169 printed (although it may not be useful if the error number was
2170 out of the system's range), a return status of 1 indicates an
2171 error in the parameters, and a return status of 2 indicates the
2172 error name was not recognised (no message is printed for this).
2173
2174
2175 sysopen [ -arw ] [ -m permissions ] [ -o options ]
2176 -u fd file
2177 This command opens a file. The -r, -w and -a flags indicate
2178 whether the file should be opened for reading, writing and
2179 appending, respectively. The -m option allows the initial per‐
2180 missions to use when creating a file to be specified in octal
2181 form. The file descriptor is specified with -u. Either an
2182 explicit file descriptor in the range 0 to 9 can be specified or
2183 a variable name can be given to which the file descriptor number
2184 will be assigned.
2185
2186 The -o option allows various system specific options to be spec‐
2187 ified as a comma-separated list. The following is a list of pos‐
2188 sible options. Note that, depending on the system, some may not
2189 be available.
2190 cloexec
2191 mark file to be closed when other programs are executed
2192 (else the file descriptor remains open in subshells and
2193 forked external executables)
2194
2195 create
2196 creat create file if it does not exist
2197
2198 excl create file, error if it already exists
2199
2200 noatime
2201 suppress updating of the file atime
2202
2203 nofollow
2204 fail if file is a symbolic link
2205
2206 sync request that writes wait until data has been physically
2207 written
2208
2209 truncate
2210 trunc truncate file to size 0
2211
2212 To close the file, use one of the following:
2213
2214 exec {fd}<&-
2215 exec {fd}>&-
2216
2217
2218 sysread [ -c countvar ] [ -i infd ] [ -o outfd ]
2219 [ -s bufsize ] [ -t timeout ] [ param ]
2220 Perform a single system read from file descriptor infd, or zero
2221 if that is not given. The result of the read is stored in param
2222 or REPLY if that is not given. If countvar is given, the number
2223 of bytes read is assigned to the parameter named by countvar.
2224
2225 The maximum number of bytes read is bufsize or 8192 if that is
2226 not given, however the command returns as soon as any number of
2227 bytes was successfully read.
2228
2229 If timeout is given, it specifies a timeout in seconds, which
2230 may be zero to poll the file descriptor. This is handled by the
2231 poll system call if available, otherwise the select system call
2232 if available.
2233
2234 If outfd is given, an attempt is made to write all the bytes
2235 just read to the file descriptor outfd. If this fails, because
2236 of a system error other than EINTR or because of an internal zsh
2237 error during an interrupt, the bytes read but not written are
2238 stored in the parameter named by param if supplied (no default
2239 is used in this case), and the number of bytes read but not
2240 written is stored in the parameter named by countvar if that is
2241 supplied. If it was successful, countvar contains the full num‐
2242 ber of bytes transferred, as usual, and param is not set.
2243
2244 The error EINTR (interrupted system call) is handled internally
2245 so that shell interrupts are transparent to the caller. Any
2246 other error causes a return.
2247
2248 The possible return statuses are
2249 0 At least one byte of data was successfully read and, if
2250 appropriate, written.
2251
2252 1 There was an error in the parameters to the command.
2253 This is the only error for which a message is printed to
2254 standard error.
2255
2256 2 There was an error on the read, or on polling the input
2257 file descriptor for a timeout. The parameter ERRNO gives
2258 the error.
2259
2260 3 Data were successfully read, but there was an error writ‐
2261 ing them to outfd. The parameter ERRNO gives the error.
2262
2263 4 The attempt to read timed out. Note this does not set
2264 ERRNO as this is not a system error.
2265
2266 5 No system error occurred, but zero bytes were read. This
2267 usually indicates end of file. The parameters are set
2268 according to the usual rules; no write to outfd is
2269 attempted.
2270
2271 sysseek [ -u fd ] [ -w start|end|current ] offset
2272 The current file position at which future reads and writes will
2273 take place is adjusted to the specified byte offset. The offset
2274 is evaluated as a math expression. The -u option allows the file
2275 descriptor to be specified. By default the offset is specified
2276 relative to the start or the file but, with the -w option, it is
2277 possible to specify that the offset should be relative to the
2278 current position or the end of the file.
2279
2280 syswrite [ -c countvar ] [ -o outfd ] data
2281 The data (a single string of bytes) are written to the file
2282 descriptor outfd, or 1 if that is not given, using the write
2283 system call. Multiple write operations may be used if the first
2284 does not write all the data.
2285
2286 If countvar is given, the number of byte written is stored in
2287 the parameter named by countvar; this may not be the full length
2288 of data if an error occurred.
2289
2290 The error EINTR (interrupted system call) is handled internally
2291 by retrying; otherwise an error causes the command to return.
2292 For example, if the file descriptor is set to non-blocking out‐
2293 put, an error EAGAIN (on some systems, EWOULDBLOCK) may result
2294 in the command returning early.
2295
2296 The return status may be 0 for success, 1 for an error in the
2297 parameters to the command, or 2 for an error on the write; no
2298 error message is printed in the last case, but the parameter
2299 ERRNO will reflect the error that occurred.
2300
2301 zsystem flock [ -t timeout ] [ -f var ] [-er] file
2302 zsystem flock -u fd_expr
2303 The builtin zsystem's subcommand flock performs advisory file
2304 locking (via the fcntl(2) system call) over the entire contents
2305 of the given file. This form of locking requires the processes
2306 accessing the file to cooperate; its most obvious use is between
2307 two instances of the shell itself.
2308
2309 In the first form the named file, which must already exist, is
2310 locked by opening a file descriptor to the file and applying a
2311 lock to the file descriptor. The lock terminates when the shell
2312 process that created the lock exits; it is therefore often con‐
2313 venient to create file locks within subshells, since the lock is
2314 automatically released when the subshell exits. Note that use
2315 of the print builtin with the -u option will, as a side effect,
2316 release the lock, as will redirection to the file in the shell
2317 holding the lock. To work around this use a subshell, e.g.
2318 `(print message) >> file'. Status 0 is returned if the lock
2319 succeeds, else status 1.
2320
2321 In the second form the file descriptor given by the arithmetic
2322 expression fd_expr is closed, releasing a lock. The file
2323 descriptor can be queried by using the `-f var' form during the
2324 lock; on a successful lock, the shell variable var is set to the
2325 file descriptor used for locking. The lock will be released if
2326 the file descriptor is closed by any other means, for example
2327 using `exec {var}>&-'; however, the form described here performs
2328 a safety check that the file descriptor is in use for file lock‐
2329 ing.
2330
2331 By default the shell waits indefinitely for the lock to succeed.
2332 The option -t timeout specifies a timeout for the lock in sec‐
2333 onds; currently this must be an integer. The shell will attempt
2334 to lock the file once a second during this period. If the
2335 attempt times out, status 2 is returned.
2336
2337 If the option -e is given, the file descriptor for the lock is
2338 preserved when the shell uses exec to start a new process; oth‐
2339 erwise it is closed at that point and the lock released.
2340
2341 If the option -r is given, the lock is only for reading, other‐
2342 wise it is for reading and writing. The file descriptor is
2343 opened accordingly.
2344
2345 zsystem supports subcommand
2346 The builtin zsystem's subcommand supports tests whether a given
2347 subcommand is supported. It returns status 0 if so, else status
2348 1. It operates silently unless there was a syntax error (i.e.
2349 the wrong number of arguments), in which case status 255 is
2350 returned. Status 1 can indicate one of two things: subcommand
2351 is known but not supported by the current operating system, or
2352 subcommand is not known (possibly because this is an older ver‐
2353 sion of the shell before it was implemented).
2354
2355 Math Functions
2356 systell(fd)
2357 The systell math function returns the current file position for
2358 the file descriptor passed as an argument.
2359
2360 Parameters
2361 errnos A readonly array of the names of errors defined on the system.
2362 These are typically macros defined in C by including the system
2363 header file errno.h. The index of each name (assuming the
2364 option KSH_ARRAYS is unset) corresponds to the error number.
2365 Error numbers num before the last known error which have no name
2366 are given the name Enum in the array.
2367
2368 Note that aliases for errors are not handled; only the canonical
2369 name is used.
2370
2371 sysparams
2372 A readonly associative array. The keys are:
2373
2374 pid Returns the process ID of the current process, even in
2375 subshells. Compare $$, which returns the process ID of
2376 the main shell process.
2377
2378 ppid Returns the process ID of the parent of the current
2379 process, even in subshells. Compare $PPID, which returns
2380 the process ID of the parent of the main shell process.
2381
2382 procsubstpid
2383 Returns the process ID of the last process started for
2384 process substitution, i.e. the <(...) and >(...) expan‐
2385 sions.
2386
2388 The zsh/net/tcp module makes available one builtin command:
2389
2390 ztcp [ -acflLtv ] [ -d fd ] [ args ]
2391 ztcp is implemented as a builtin to allow full use of shell com‐
2392 mand line editing, file I/O, and job control mechanisms.
2393
2394 If ztcp is run with no options, it will output the contents of
2395 its session table.
2396
2397 If it is run with only the option -L, it will output the con‐
2398 tents of the session table in a format suitable for automatic
2399 parsing. The option is ignored if given with a command to open
2400 or close a session. The output consists of a set of lines, one
2401 per session, each containing the following elements separated by
2402 spaces:
2403
2404 File descriptor
2405 The file descriptor in use for the connection. For nor‐
2406 mal inbound (I) and outbound (O) connections this may be
2407 read and written by the usual shell mechanisms. However,
2408 it should only be close with `ztcp -c'.
2409
2410 Connection type
2411 A letter indicating how the session was created:
2412
2413 Z A session created with the zftp command.
2414
2415 L A connection opened for listening with `ztcp -l'.
2416
2417 I An inbound connection accepted with `ztcp -a'.
2418
2419 O An outbound connection created with `ztcp host
2420 ...'.
2421
2422 The local host
2423 This is usually set to an all-zero IP address as the
2424 address of the localhost is irrelevant.
2425
2426 The local port
2427 This is likely to be zero unless the connection is for
2428 listening.
2429
2430 The remote host
2431 This is the fully qualified domain name of the peer, if
2432 available, else an IP address. It is an all-zero IP
2433 address for a session opened for listening.
2434
2435 The remote port
2436 This is zero for a connection opened for listening.
2437
2438 Outbound Connections
2439 ztcp [ -v ] [ -d fd ] host [ port ]
2440 Open a new TCP connection to host. If the port is omitted, it
2441 will default to port 23. The connection will be added to the
2442 session table and the shell parameter REPLY will be set to the
2443 file descriptor associated with that connection.
2444
2445 If -d is specified, its argument will be taken as the target
2446 file descriptor for the connection.
2447
2448 In order to elicit more verbose output, use -v.
2449
2450 Inbound Connections
2451 ztcp -l [ -v ] [ -d fd ] port
2452 ztcp -l will open a socket listening on TCP port. The socket
2453 will be added to the session table and the shell parameter REPLY
2454 will be set to the file descriptor associated with that lis‐
2455 tener.
2456
2457 If -d is specified, its argument will be taken as the target
2458 file descriptor for the connection.
2459
2460 In order to elicit more verbose output, use -v.
2461
2462 ztcp -a [ -tv ] [ -d targetfd ] listenfd
2463 ztcp -a will accept an incoming connection to the port associ‐
2464 ated with listenfd. The connection will be added to the session
2465 table and the shell parameter REPLY will be set to the file
2466 descriptor associated with the inbound connection.
2467
2468 If -d is specified, its argument will be taken as the target
2469 file descriptor for the connection.
2470
2471 If -t is specified, ztcp will return if no incoming connection
2472 is pending. Otherwise it will wait for one.
2473
2474 In order to elicit more verbose output, use -v.
2475
2476 Closing Connections
2477 ztcp -cf [ -v ] [ fd ]
2478 ztcp -c [ -v ] [ fd ]
2479 ztcp -c will close the socket associated with fd. The socket
2480 will be removed from the session table. If fd is not specified,
2481 ztcp will close everything in the session table.
2482
2483 Normally, sockets registered by zftp (see zshmodules(1) ) cannot
2484 be closed this way. In order to force such a socket closed, use
2485 -f.
2486
2487 In order to elicit more verbose output, use -v.
2488
2489 Example
2490 Here is how to create a TCP connection between two instances of zsh.
2491 We need to pick an unassigned port; here we use the randomly chosen
2492 5123.
2493
2494 On host1,
2495 zmodload zsh/net/tcp
2496 ztcp -l 5123
2497 listenfd=$REPLY
2498 ztcp -a $listenfd
2499 fd=$REPLY
2500 The second from last command blocks until there is an incoming connec‐
2501 tion.
2502
2503 Now create a connection from host2 (which may, of course, be the same
2504 machine):
2505 zmodload zsh/net/tcp
2506 ztcp host1 5123
2507 fd=$REPLY
2508
2509 Now on each host, $fd contains a file descriptor for talking to the
2510 other. For example, on host1:
2511 print This is a message >&$fd
2512 and on host2:
2513 read -r line <&$fd; print -r - $line
2514 prints `This is a message'.
2515
2516 To tidy up, on host1:
2517 ztcp -c $listenfd
2518 ztcp -c $fd
2519 and on host2
2520 ztcp -c $fd
2521
2523 The zsh/termcap module makes available one builtin command:
2524
2525 echotc cap [ arg ... ]
2526 Output the termcap value corresponding to the capability cap,
2527 with optional arguments.
2528
2529 The zsh/termcap module makes available one parameter:
2530
2531 termcap
2532 An associative array that maps termcap capability codes to their
2533 values.
2534
2536 The zsh/terminfo module makes available one builtin command:
2537
2538 echoti cap [ arg ]
2539 Output the terminfo value corresponding to the capability cap,
2540 instantiated with arg if applicable.
2541
2542 The zsh/terminfo module makes available one parameter:
2543
2544 terminfo
2545 An associative array that maps terminfo capability names to
2546 their values.
2547
2549 The zsh/zftp module makes available one builtin command:
2550
2551 zftp subcommand [ args ]
2552 The zsh/zftp module is a client for FTP (file transfer proto‐
2553 col). It is implemented as a builtin to allow full use of shell
2554 command line editing, file I/O, and job control mechanisms.
2555 Often, users will access it via shell functions providing a more
2556 powerful interface; a set is provided with the zsh distribution
2557 and is described in zshzftpsys(1). However, the zftp command is
2558 entirely usable in its own right.
2559
2560 All commands consist of the command name zftp followed by the
2561 name of a subcommand. These are listed below. The return sta‐
2562 tus of each subcommand is supposed to reflect the success or
2563 failure of the remote operation. See a description of the vari‐
2564 able ZFTP_VERBOSE for more information on how responses from the
2565 server may be printed.
2566
2567 Subcommands
2568 open host[:port] [ user [ password [ account ] ] ]
2569 Open a new FTP session to host, which may be the name of a
2570 TCP/IP connected host or an IP number in the standard dot nota‐
2571 tion. If the argument is in the form host:port, open a connec‐
2572 tion to TCP port port instead of the standard FTP port 21. This
2573 may be the name of a TCP service or a number: see the descrip‐
2574 tion of ZFTP_PORT below for more information.
2575
2576 If IPv6 addresses in colon format are used, the host should be
2577 surrounded by quoted square brackets to distinguish it from the
2578 port, for example '[fe80::203:baff:fe02:8b56]'. For consistency
2579 this is allowed with all forms of host.
2580
2581 Remaining arguments are passed to the login subcommand. Note
2582 that if no arguments beyond host are supplied, open will not
2583 automatically call login. If no arguments at all are supplied,
2584 open will use the parameters set by the params subcommand.
2585
2586 After a successful open, the shell variables ZFTP_HOST,
2587 ZFTP_PORT, ZFTP_IP and ZFTP_SYSTEM are available; see `Vari‐
2588 ables' below.
2589
2590 login [ name [ password [ account ] ] ]
2591 user [ name [ password [ account ] ] ]
2592 Login the user name with parameters password and account. Any
2593 of the parameters can be omitted, and will be read from standard
2594 input if needed (name is always needed). If standard input is a
2595 terminal, a prompt for each one will be printed on standard
2596 error and password will not be echoed. If any of the parameters
2597 are not used, a warning message is printed.
2598
2599 After a successful login, the shell variables ZFTP_USER,
2600 ZFTP_ACCOUNT and ZFTP_PWD are available; see `Variables' below.
2601
2602 This command may be re-issued when a user is already logged in,
2603 and the server will first be reinitialized for a new user.
2604
2605 params [ host [ user [ password [ account ] ] ] ]
2606 params -
2607 Store the given parameters for a later open command with no
2608 arguments. Only those given on the command line will be remem‐
2609 bered. If no arguments are given, the parameters currently set
2610 are printed, although the password will appear as a line of
2611 stars; the return status is one if no parameters were set, zero
2612 otherwise.
2613
2614 Any of the parameters may be specified as a `?', which may need
2615 to be quoted to protect it from shell expansion. In this case,
2616 the appropriate parameter will be read from stdin as with the
2617 login subcommand, including special handling of password. If
2618 the `?' is followed by a string, that is used as the prompt for
2619 reading the parameter instead of the default message (any neces‐
2620 sary punctuation and whitespace should be included at the end of
2621 the prompt). The first letter of the parameter (only) may be
2622 quoted with a `\'; hence an argument "\\$word" guarantees that
2623 the string from the shell parameter $word will be treated liter‐
2624 ally, whether or not it begins with a `?'.
2625
2626 If instead a single `-' is given, the existing parameters, if
2627 any, are deleted. In that case, calling open with no arguments
2628 will cause an error.
2629
2630 The list of parameters is not deleted after a close, however it
2631 will be deleted if the zsh/zftp module is unloaded.
2632
2633 For example,
2634
2635 zftp params ftp.elsewhere.xx juser '?Password for juser: '
2636
2637 will store the host ftp.elsewhere.xx and the user juser and then
2638 prompt the user for the corresponding password with the given
2639 prompt.
2640
2641 test Test the connection; if the server has reported that it has
2642 closed the connection (maybe due to a timeout), return status 2;
2643 if no connection was open anyway, return status 1; else return
2644 status 0. The test subcommand is silent, apart from messages
2645 printed by the $ZFTP_VERBOSE mechanism, or error messages if the
2646 connection closes. There is no network overhead for this test.
2647
2648 The test is only supported on systems with either the select(2)
2649 or poll(2) system calls; otherwise the message `not supported on
2650 this system' is printed instead.
2651
2652 The test subcommand will automatically be called at the start of
2653 any other subcommand for the current session when a connection
2654 is open.
2655
2656 cd directory
2657 Change the remote directory to directory. Also alters the shell
2658 variable ZFTP_PWD.
2659
2660 cdup Change the remote directory to the one higher in the directory
2661 tree. Note that cd .. will also work correctly on non-UNIX sys‐
2662 tems.
2663
2664 dir [ arg ... ]
2665 Give a (verbose) listing of the remote directory. The args are
2666 passed directly to the server. The command's behaviour is imple‐
2667 mentation dependent, but a UNIX server will typically interpret
2668 args as arguments to the ls command and with no arguments return
2669 the result of `ls -l'. The directory is listed to standard out‐
2670 put.
2671
2672 ls [ arg ... ]
2673 Give a (short) listing of the remote directory. With no arg,
2674 produces a raw list of the files in the directory, one per line.
2675 Otherwise, up to vagaries of the server implementation, behaves
2676 similar to dir.
2677
2678 type [ type ]
2679 Change the type for the transfer to type, or print the current
2680 type if type is absent. The allowed values are `A' (ASCII), `I'
2681 (Image, i.e. binary), or `B' (a synonym for `I').
2682
2683 The FTP default for a transfer is ASCII. However, if zftp finds
2684 that the remote host is a UNIX machine with 8-bit byes, it will
2685 automatically switch to using binary for file transfers upon
2686 open. This can subsequently be overridden.
2687
2688 The transfer type is only passed to the remote host when a data
2689 connection is established; this command involves no network
2690 overhead.
2691
2692 ascii The same as type A.
2693
2694 binary The same as type I.
2695
2696 mode [ S | B ]
2697 Set the mode type to stream (S) or block (B). Stream mode is
2698 the default; block mode is not widely supported.
2699
2700 remote file ...
2701 local [ file ... ]
2702 Print the size and last modification time of the remote or local
2703 files. If there is more than one item on the list, the name of
2704 the file is printed first. The first number is the file size,
2705 the second is the last modification time of the file in the for‐
2706 mat CCYYMMDDhhmmSS consisting of year, month, date, hour, min‐
2707 utes and seconds in GMT. Note that this format, including the
2708 length, is guaranteed, so that time strings can be directly com‐
2709 pared via the [[ builtin's < and > operators, even if they are
2710 too long to be represented as integers.
2711
2712 Not all servers support the commands for retrieving this infor‐
2713 mation. In that case, the remote command will print nothing and
2714 return status 2, compared with status 1 for a file not found.
2715
2716 The local command (but not remote) may be used with no argu‐
2717 ments, in which case the information comes from examining file
2718 descriptor zero. This is the same file as seen by a put command
2719 with no further redirection.
2720
2721 get file ...
2722 Retrieve all files from the server, concatenating them and send‐
2723 ing them to standard output.
2724
2725 put file ...
2726 For each file, read a file from standard input and send that to
2727 the remote host with the given name.
2728
2729 append file ...
2730 As put, but if the remote file already exists, data is appended
2731 to it instead of overwriting it.
2732
2733 getat file point
2734 putat file point
2735 appendat file point
2736 Versions of get, put and append which will start the transfer at
2737 the given point in the remote file. This is useful for append‐
2738 ing to an incomplete local file. However, note that this abil‐
2739 ity is not universally supported by servers (and is not quite
2740 the behaviour specified by the standard).
2741
2742 delete file ...
2743 Delete the list of files on the server.
2744
2745 mkdir directory
2746 Create a new directory directory on the server.
2747
2748 rmdir directory
2749 Delete the directory directory on the server.
2750
2751 rename old-name new-name
2752 Rename file old-name to new-name on the server.
2753
2754 site arg ...
2755 Send a host-specific command to the server. You will probably
2756 only need this if instructed by the server to use it.
2757
2758 quote arg ...
2759 Send the raw FTP command sequence to the server. You should be
2760 familiar with the FTP command set as defined in RFC959 before
2761 doing this. Useful commands may include STAT and HELP. Note
2762 also the mechanism for returning messages as described for the
2763 variable ZFTP_VERBOSE below, in particular that all messages
2764 from the control connection are sent to standard error.
2765
2766 close
2767 quit Close the current data connection. This unsets the shell param‐
2768 eters ZFTP_HOST, ZFTP_PORT, ZFTP_IP, ZFTP_SYSTEM, ZFTP_USER,
2769 ZFTP_ACCOUNT, ZFTP_PWD, ZFTP_TYPE and ZFTP_MODE.
2770
2771 session [ sessname ]
2772 Allows multiple FTP sessions to be used at once. The name of
2773 the session is an arbitrary string of characters; the default
2774 session is called `default'. If this command is called without
2775 an argument, it will list all the current sessions; with an
2776 argument, it will either switch to the existing session called
2777 sessname, or create a new session of that name.
2778
2779 Each session remembers the status of the connection, the set of
2780 connection-specific shell parameters (the same set as are unset
2781 when a connection closes, as given in the description of close),
2782 and any user parameters specified with the params subcommand.
2783 Changing to a previous session restores those values; changing
2784 to a new session initialises them in the same way as if zftp had
2785 just been loaded. The name of the current session is given by
2786 the parameter ZFTP_SESSION.
2787
2788 rmsession [ sessname ]
2789 Delete a session; if a name is not given, the current session is
2790 deleted. If the current session is deleted, the earliest exist‐
2791 ing session becomes the new current session, otherwise the cur‐
2792 rent session is not changed. If the session being deleted is
2793 the only one, a new session called `default' is created and
2794 becomes the current session; note that this is a new session
2795 even if the session being deleted is also called `default'. It
2796 is recommended that sessions not be deleted while background
2797 commands which use zftp are still active.
2798
2799 Parameters
2800 The following shell parameters are used by zftp. Currently none of
2801 them are special.
2802
2803 ZFTP_TMOUT
2804 Integer. The time in seconds to wait for a network operation to
2805 complete before returning an error. If this is not set when the
2806 module is loaded, it will be given the default value 60. A
2807 value of zero turns off timeouts. If a timeout occurs on the
2808 control connection it will be closed. Use a larger value if
2809 this occurs too frequently.
2810
2811 ZFTP_IP
2812 Readonly. The IP address of the current connection in dot nota‐
2813 tion.
2814
2815 ZFTP_HOST
2816 Readonly. The hostname of the current remote server. If the
2817 host was opened as an IP number, ZFTP_HOST contains that
2818 instead; this saves the overhead for a name lookup, as IP num‐
2819 bers are most commonly used when a nameserver is unavailable.
2820
2821 ZFTP_PORT
2822 Readonly. The number of the remote TCP port to which the con‐
2823 nection is open (even if the port was originally specified as a
2824 named service). Usually this is the standard FTP port, 21.
2825
2826 In the unlikely event that your system does not have the appro‐
2827 priate conversion functions, this appears in network byte order.
2828 If your system is little-endian, the port then consists of two
2829 swapped bytes and the standard port will be reported as 5376.
2830 In that case, numeric ports passed to zftp open will also need
2831 to be in this format.
2832
2833 ZFTP_SYSTEM
2834 Readonly. The system type string returned by the server in
2835 response to an FTP SYST request. The most interesting case is a
2836 string beginning "UNIX Type: L8", which ensures maximum compati‐
2837 bility with a local UNIX host.
2838
2839 ZFTP_TYPE
2840 Readonly. The type to be used for data transfers , either `A'
2841 or `I'. Use the type subcommand to change this.
2842
2843 ZFTP_USER
2844 Readonly. The username currently logged in, if any.
2845
2846 ZFTP_ACCOUNT
2847 Readonly. The account name of the current user, if any. Most
2848 servers do not require an account name.
2849
2850 ZFTP_PWD
2851 Readonly. The current directory on the server.
2852
2853 ZFTP_CODE
2854 Readonly. The three digit code of the last FTP reply from the
2855 server as a string. This can still be read after the connection
2856 is closed, and is not changed when the current session changes.
2857
2858 ZFTP_REPLY
2859 Readonly. The last line of the last reply sent by the server.
2860 This can still be read after the connection is closed, and is
2861 not changed when the current session changes.
2862
2863 ZFTP_SESSION
2864 Readonly. The name of the current FTP session; see the descrip‐
2865 tion of the session subcommand.
2866
2867 ZFTP_PREFS
2868 A string of preferences for altering aspects of zftp's behav‐
2869 iour. Each preference is a single character. The following are
2870 defined:
2871
2872 P Passive: attempt to make the remote server initiate data
2873 transfers. This is slightly more efficient than sendport
2874 mode. If the letter S occurs later in the string, zftp
2875 will use sendport mode if passive mode is not available.
2876
2877 S Sendport: initiate transfers by the FTP PORT command.
2878 If this occurs before any P in the string, passive mode
2879 will never be attempted.
2880
2881 D Dumb: use only the bare minimum of FTP commands. This
2882 prevents the variables ZFTP_SYSTEM and ZFTP_PWD from
2883 being set, and will mean all connections default to ASCII
2884 type. It may prevent ZFTP_SIZE from being set during a
2885 transfer if the server does not send it anyway (many
2886 servers do).
2887
2888 If ZFTP_PREFS is not set when zftp is loaded, it will be set to
2889 a default of `PS', i.e. use passive mode if available, otherwise
2890 fall back to sendport mode.
2891
2892 ZFTP_VERBOSE
2893 A string of digits between 0 and 5 inclusive, specifying which
2894 responses from the server should be printed. All responses go
2895 to standard error. If any of the numbers 1 to 5 appear in the
2896 string, raw responses from the server with reply codes beginning
2897 with that digit will be printed to standard error. The first
2898 digit of the three digit reply code is defined by RFC959 to cor‐
2899 respond to:
2900
2901 1. A positive preliminary reply.
2902
2903 2. A positive completion reply.
2904
2905 3. A positive intermediate reply.
2906
2907 4. A transient negative completion reply.
2908
2909 5. A permanent negative completion reply.
2910
2911 It should be noted that, for unknown reasons, the reply `Service
2912 not available', which forces termination of a connection, is
2913 classified as 421, i.e. `transient negative', an interesting
2914 interpretation of the word `transient'.
2915
2916 The code 0 is special: it indicates that all but the last line
2917 of multiline replies read from the server will be printed to
2918 standard error in a processed format. By convention, servers
2919 use this mechanism for sending information for the user to read.
2920 The appropriate reply code, if it matches the same response,
2921 takes priority.
2922
2923 If ZFTP_VERBOSE is not set when zftp is loaded, it will be set
2924 to the default value 450, i.e., messages destined for the user
2925 and all errors will be printed. A null string is valid and
2926 specifies that no messages should be printed.
2927
2928 Functions
2929 zftp_chpwd
2930 If this function is set by the user, it is called every time the
2931 directory changes on the server, including when a user is logged
2932 in, or when a connection is closed. In the last case, $ZFTP_PWD
2933 will be unset; otherwise it will reflect the new directory.
2934
2935 zftp_progress
2936 If this function is set by the user, it will be called during a
2937 get, put or append operation each time sufficient data has been
2938 received from the host. During a get, the data is sent to stan‐
2939 dard output, so it is vital that this function should write to
2940 standard error or directly to the terminal, not to standard out‐
2941 put.
2942
2943 When it is called with a transfer in progress, the following
2944 additional shell parameters are set:
2945
2946 ZFTP_FILE
2947 The name of the remote file being transferred from or to.
2948
2949 ZFTP_TRANSFER
2950 A G for a get operation and a P for a put operation.
2951
2952 ZFTP_SIZE
2953 The total size of the complete file being transferred:
2954 the same as the first value provided by the remote and
2955 local subcommands for a particular file. If the server
2956 cannot supply this value for a remote file being
2957 retrieved, it will not be set. If input is from a pipe
2958 the value may be incorrect and correspond simply to a
2959 full pipe buffer.
2960
2961 ZFTP_COUNT
2962 The amount of data so far transferred; a number between
2963 zero and $ZFTP_SIZE, if that is set. This number is
2964 always available.
2965
2966 The function is initially called with ZFTP_TRANSFER set appro‐
2967 priately and ZFTP_COUNT set to zero. After the transfer is fin‐
2968 ished, the function will be called one more time with
2969 ZFTP_TRANSFER set to GF or PF, in case it wishes to tidy up. It
2970 is otherwise never called twice with the same value of
2971 ZFTP_COUNT.
2972
2973 Sometimes the progress meter may cause disruption. It is up to
2974 the user to decide whether the function should be defined and to
2975 use unfunction when necessary.
2976
2977 Problems
2978 A connection may not be opened in the left hand side of a pipe as this
2979 occurs in a subshell and the file information is not updated in the
2980 main shell. In the case of type or mode changes or closing the connec‐
2981 tion in a subshell, the information is returned but variables are not
2982 updated until the next call to zftp. Other status changes in subshells
2983 will not be reflected by changes to the variables (but should be other‐
2984 wise harmless).
2985
2986 Deleting sessions while a zftp command is active in the background can
2987 have unexpected effects, even if it does not use the session being
2988 deleted. This is because all shell subprocesses share information on
2989 the state of all connections, and deleting a session changes the order‐
2990 ing of that information.
2991
2992 On some operating systems, the control connection is not valid after a
2993 fork(), so that operations in subshells, on the left hand side of a
2994 pipeline, or in the background are not possible, as they should be.
2995 This is presumably a bug in the operating system.
2996
2998 The zsh/zle module contains the Zsh Line Editor. See zshzle(1).
2999
3001 The zsh/zleparameter module defines two special parameters that can be
3002 used to access internal information of the Zsh Line Editor (see zsh‐
3003 zle(1)).
3004
3005 keymaps
3006 This array contains the names of the keymaps currently defined.
3007
3008 widgets
3009 This associative array contains one entry per widget. The name
3010 of the widget is the key and the value gives information about
3011 the widget. It is either
3012 the string `builtin' for builtin widgets,
3013 a string of the form `user:name' for user-defined widgets,
3014 where name is the name of the shell function implementing
3015 the widget,
3016 a string of the form `completion:type:name'
3017 for completion widgets,
3018 or a null value if the widget is not yet fully defined. In
3019 the penultimate case, type is the name of the builtin widget the
3020 completion widget imitates in its behavior and name is the name
3021 of the shell function implementing the completion widget.
3022
3024 When loaded, the zsh/zprof causes shell functions to be profiled. The
3025 profiling results can be obtained with the zprof builtin command made
3026 available by this module. There is no way to turn profiling off other
3027 than unloading the module.
3028
3029 zprof [ -c ]
3030 Without the -c option, zprof lists profiling results to standard
3031 output. The format is comparable to that of commands like
3032 gprof.
3033
3034 At the top there is a summary listing all functions that were
3035 called at least once. This summary is sorted in decreasing
3036 order of the amount of time spent in each. The lines contain
3037 the number of the function in order, which is used in other
3038 parts of the list in suffixes of the form `[num]', then the num‐
3039 ber of calls made to the function. The next three columns list
3040 the time in milliseconds spent in the function and its descen‐
3041 dants, the average time in milliseconds spent in the function
3042 and its descendants per call and the percentage of time spent in
3043 all shell functions used in this function and its descendants.
3044 The following three columns give the same information, but
3045 counting only the time spent in the function itself. The final
3046 column shows the name of the function.
3047
3048 After the summary, detailed information about every function
3049 that was invoked is listed, sorted in decreasing order of the
3050 amount of time spent in each function and its descendants. Each
3051 of these entries consists of descriptions for the functions that
3052 called the function described, the function itself, and the
3053 functions that were called from it. The description for the
3054 function itself has the same format as in the summary (and shows
3055 the same information). The other lines don't show the number of
3056 the function at the beginning and have their function named
3057 indented to make it easier to distinguish the line showing the
3058 function described in the section from the surrounding lines.
3059
3060 The information shown in this case is almost the same as in the
3061 summary, but only refers to the call hierarchy being displayed.
3062 For example, for a calling function the column showing the total
3063 running time lists the time spent in the described function and
3064 its descendants only for the times when it was called from that
3065 particular calling function. Likewise, for a called function,
3066 this columns lists the total time spent in the called function
3067 and its descendants only for the times when it was called from
3068 the function described.
3069
3070 Also in this case, the column showing the number of calls to a
3071 function also shows a slash and then the total number of invoca‐
3072 tions made to the called function.
3073
3074 As long as the zsh/zprof module is loaded, profiling will be
3075 done and multiple invocations of the zprof builtin command will
3076 show the times and numbers of calls since the module was loaded.
3077 With the -c option, the zprof builtin command will reset its
3078 internal counters and will not show the listing.
3079
3081 The zsh/zpty module offers one builtin:
3082
3083 zpty [ -e ] [ -b ] name [ arg ... ]
3084 The arguments following name are concatenated with spaces
3085 between, then executed as a command, as if passed to the eval
3086 builtin. The command runs under a newly assigned pseudo-termi‐
3087 nal; this is useful for running commands non-interactively which
3088 expect an interactive environment. The name is not part of the
3089 command, but is used to refer to this command in later calls to
3090 zpty.
3091
3092 With the -e option, the pseudo-terminal is set up so that input
3093 characters are echoed.
3094
3095 With the -b option, input to and output from the pseudo-terminal
3096 are made non-blocking.
3097
3098 The shell parameter REPLY is set to the file descriptor assigned
3099 to the master side of the pseudo-terminal. This allows the ter‐
3100 minal to be monitored with ZLE descriptor handlers (see zsh‐
3101 zle(1)) or manipulated with sysread and syswrite (see THE
3102 ZSH/SYSTEM MODULE in zshmodules(1)). Warning: Use of sysread
3103 and syswrite is not recommended; use zpty -r and zpty -w unless
3104 you know exactly what you are doing.
3105
3106 zpty -d [ name ... ]
3107 The second form, with the -d option, is used to delete commands
3108 previously started, by supplying a list of their names. If no
3109 name is given, all commands are deleted. Deleting a command
3110 causes the HUP signal to be sent to the corresponding process.
3111
3112 zpty -w [ -n ] name [ string ... ]
3113 The -w option can be used to send the to command name the given
3114 strings as input (separated by spaces). If the -n option is not
3115 given, a newline is added at the end.
3116
3117 If no string is provided, the standard input is copied to the
3118 pseudo-terminal; this may stop before copying the full input if
3119 the pseudo-terminal is non-blocking. The exact input is always
3120 copied: the -n option is not applied.
3121
3122 Note that the command under the pseudo-terminal sees this input
3123 as if it were typed, so beware when sending special tty driver
3124 characters such as word-erase, line-kill, and end-of-file.
3125
3126 zpty -r [ -mt ] name [ param [ pattern ] ]
3127 The -r option can be used to read the output of the command
3128 name. With only a name argument, the output read is copied to
3129 the standard output. Unless the pseudo-terminal is non-block‐
3130 ing, copying continues until the command under the pseudo-termi‐
3131 nal exits; when non-blocking, only as much output as is immedi‐
3132 ately available is copied. The return status is zero if any
3133 output is copied.
3134
3135 When also given a param argument, at most one line is read and
3136 stored in the parameter named param. Less than a full line may
3137 be read if the pseudo-terminal is non-blocking. The return sta‐
3138 tus is zero if at least one character is stored in param.
3139
3140 If a pattern is given as well, output is read until the whole
3141 string read matches the pattern, even in the non-blocking case.
3142 The return status is zero if the string read matches the pat‐
3143 tern, or if the command has exited but at least one character
3144 could still be read. If the option -m is present, the return
3145 status is zero only if the pattern matches. As of this writing,
3146 a maximum of one megabyte of output can be consumed this way; if
3147 a full megabyte is read without matching the pattern, the return
3148 status is non-zero.
3149
3150 In all cases, the return status is non-zero if nothing could be
3151 read, and is 2 if this is because the command has finished.
3152
3153 If the -r option is combined with the -t option, zpty tests
3154 whether output is available before trying to read. If no output
3155 is available, zpty immediately returns the status 1. When used
3156 with a pattern, the behaviour on a failed poll is similar to
3157 when the command has exited: the return value is zero if at
3158 least one character could still be read even if the pattern
3159 failed to match.
3160
3161 zpty -t name
3162 The -t option without the -r option can be used to test whether
3163 the command name is still running. It returns a zero status if
3164 the command is running and a non-zero value otherwise.
3165
3166 zpty [ -L ]
3167 The last form, without any arguments, is used to list the com‐
3168 mands currently defined. If the -L option is given, this is
3169 done in the form of calls to the zpty builtin.
3170
3172 The zsh/zselect module makes available one builtin command:
3173
3174 zselect [ -rwe ] [ -t timeout ] [ -a array ] [ -A assoc ] [ fd ... ]
3175 The zselect builtin is a front-end to the `select' system call,
3176 which blocks until a file descriptor is ready for reading or
3177 writing, or has an error condition, with an optional timeout.
3178 If this is not available on your system, the command prints an
3179 error message and returns status 2 (normal errors return status
3180 1). For more information, see your systems documentation for
3181 select(3). Note there is no connection with the shell builtin
3182 of the same name.
3183
3184 Arguments and options may be intermingled in any order.
3185 Non-option arguments are file descriptors, which must be decimal
3186 integers. By default, file descriptors are to be tested for
3187 reading, i.e. zselect will return when data is available to be
3188 read from the file descriptor, or more precisely, when a read
3189 operation from the file descriptor will not block. After a -r,
3190 -w and -e, the given file descriptors are to be tested for read‐
3191 ing, writing, or error conditions. These options and an arbi‐
3192 trary list of file descriptors may be given in any order.
3193
3194 (The presence of an `error condition' is not well defined in the
3195 documentation for many implementations of the select system
3196 call. According to recent versions of the POSIX specification,
3197 it is really an exception condition, of which the only standard
3198 example is out-of-band data received on a socket. So zsh users
3199 are unlikely to find the -e option useful.)
3200
3201 The option `-t timeout' specifies a timeout in hundredths of a
3202 second. This may be zero, in which case the file descriptors
3203 will simply be polled and zselect will return immediately. It
3204 is possible to call zselect with no file descriptors and a
3205 non-zero timeout for use as a finer-grained replacement for
3206 `sleep'; note, however, the return status is always 1 for a
3207 timeout.
3208
3209 The option `-a array' indicates that array should be set to
3210 indicate the file descriptor(s) which are ready. If the option
3211 is not given, the array reply will be used for this purpose.
3212 The array will contain a string similar to the arguments for
3213 zselect. For example,
3214
3215 zselect -t 0 -r 0 -w 1
3216
3217 might return immediately with status 0 and $reply containing `-r
3218 0 -w 1' to show that both file descriptors are ready for the
3219 requested operations.
3220
3221 The option `-A assoc' indicates that the associative array assoc
3222 should be set to indicate the file descriptor(s) which are
3223 ready. This option overrides the option -a, nor will reply be
3224 modified. The keys of assoc are the file descriptors, and the
3225 corresponding values are any of the characters `rwe' to indicate
3226 the condition.
3227
3228 The command returns status 0 if some file descriptors are ready
3229 for reading. If the operation timed out, or a timeout of 0 was
3230 given and no file descriptors were ready, or there was an error,
3231 it returns status 1 and the array will not be set (nor modified
3232 in any way). If there was an error in the select operation the
3233 appropriate error message is printed.
3234
3236 The zsh/zutil module only adds some builtins:
3237
3238 zstyle [ -L [ metapattern [ style ] ] ]
3239 zstyle [ -e | - | -- ] pattern style string ...
3240 zstyle -d [ pattern [ style ... ] ]
3241 zstyle -g name [ pattern [ style ] ]
3242 zstyle -{a|b|s} context style name [ sep ]
3243 zstyle -{T|t} context style [ string ... ]
3244 zstyle -m context style pattern
3245 This builtin command is used to define and lookup styles.
3246 Styles are pairs of names and values, where the values consist
3247 of any number of strings. They are stored together with pat‐
3248 terns and lookup is done by giving a string, called the `con‐
3249 text', which is matched against the patterns. The definition
3250 stored for the most specific pattern that matches will be
3251 returned.
3252
3253 A pattern is considered to be more specific than another if it
3254 contains more components (substrings separated by colons) or if
3255 the patterns for the components are more specific, where simple
3256 strings are considered to be more specific than patterns and
3257 complex patterns are considered to be more specific than the
3258 pattern `*'. A `*' in the pattern will match zero or more char‐
3259 acters in the context; colons are not treated specially in this
3260 regard. If two patterns are equally specific, the tie is broken
3261 in favour of the pattern that was defined first.
3262
3263 Example
3264
3265 For example, to define your preferred form of precipitation
3266 depending on which city you're in, you might set the following
3267 in your zshrc:
3268
3269 zstyle ':weather:europe:*' preferred-precipitation rain
3270 zstyle ':weather:europe:germany:* preferred-precipitation none
3271 zstyle ':weather:europe:germany:*:munich' preferred-precipitation snow
3272
3273 Then, the fictional `weather' plugin might run under the hood a
3274 command such as
3275
3276 zstyle -s ":weather:${continent}:${country}:${county}:${city}" preferred-precipitation REPLY
3277
3278 in order to retrieve your preference into the scalar variable
3279 $REPLY.
3280
3281 Usage
3282
3283 The forms that operate on patterns are the following.
3284
3285 zstyle [ -L [ metapattern [ style ] ] ]
3286 Without arguments, lists style definitions. Styles are
3287 shown in alphabetic order and patterns are shown in the
3288 order zstyle will test them.
3289
3290 If the -L option is given, listing is done in the form of
3291 calls to zstyle. The optional first argument, metapat‐
3292 tern, is a pattern which will be matched against the
3293 string supplied as pattern when the style was defined.
3294 Note: this means, for example, `zstyle -L ":comple‐
3295 tion:*"' will match any supplied pattern beginning `:com‐
3296 pletion:', not just ":completion:*": use ':comple‐
3297 tion:\*' to match that. The optional second argument
3298 limits the output to a specific style (not a pattern).
3299 -L is not compatible with any other options.
3300
3301 zstyle [ - | -- | -e ] pattern style string ...
3302 Defines the given style for the pattern with the strings
3303 as the value. If the -e option is given, the strings
3304 will be concatenated (separated by spaces) and the
3305 resulting string will be evaluated (in the same way as it
3306 is done by the eval builtin command) when the style is
3307 looked up. In this case the parameter `reply' must be
3308 assigned to set the strings returned after the evalua‐
3309 tion. Before evaluating the value, reply is unset, and
3310 if it is still unset after the evaluation, the style is
3311 treated as if it were not set.
3312
3313 zstyle -d [ pattern [ style ... ] ]
3314 Delete style definitions. Without arguments all defini‐
3315 tions are deleted, with a pattern all definitions for
3316 that pattern are deleted and if any styles are given,
3317 then only those styles are deleted for the pattern.
3318
3319 zstyle -g name [ pattern [ style ] ]
3320 Retrieve a style definition. The name is used as the name
3321 of an array in which the results are stored. Without any
3322 further arguments, all patterns defined are returned.
3323 With a pattern the styles defined for that pattern are
3324 returned and with both a pattern and a style, the value
3325 strings of that combination is returned.
3326
3327 The other forms can be used to look up or test styles for a
3328 given context.
3329
3330 zstyle -s context style name [ sep ]
3331 The parameter name is set to the value of the style
3332 interpreted as a string. If the value contains several
3333 strings they are concatenated with spaces (or with the
3334 sep string if that is given) between them.
3335
3336 Return 0 if the style is set, 1 otherwise.
3337
3338 zstyle -b context style name
3339 The value is stored in name as a boolean, i.e. as the
3340 string `yes' if the value has only one string and that
3341 string is equal to one of `yes', `true', `on', or `1'. If
3342 the value is any other string or has more than one
3343 string, the parameter is set to `no'.
3344
3345 Return 0 if name is set to `yes', 1 otherwise.
3346
3347 zstyle -a context style name
3348 The value is stored in name as an array. If name is
3349 declared as an associative array, the first, third, etc.
3350 strings are used as the keys and the other strings are
3351 used as the values.
3352
3353 Return 0 if the style is set, 1 otherwise.
3354
3355 zstyle -t context style [ string ... ]
3356 zstyle -T context style [ string ... ]
3357 Test the value of a style, i.e. the -t option only
3358 returns a status (sets $?). Without any string the
3359 return status is zero if the style is defined for at
3360 least one matching pattern, has only one string in its
3361 value, and that is equal to one of `true', `yes', `on' or
3362 `1'. If any strings are given the status is zero if and
3363 only if at least one of the strings is equal to at least
3364 one of the strings in the value. If the style is defined
3365 but doesn't match, the return status is 1. If the style
3366 is not defined, the status is 2.
3367
3368 The -T option tests the values of the style like -t, but
3369 it returns status zero (rather than 2) if the style is
3370 not defined for any matching pattern.
3371
3372 zstyle -m context style pattern
3373 Match a value. Returns status zero if the pattern matches
3374 at least one of the strings in the value.
3375
3376 zformat -f param format spec ...
3377 zformat -a array sep spec ...
3378 This builtin provides two different forms of formatting. The
3379 first form is selected with the -f option. In this case the for‐
3380 mat string will be modified by replacing sequences starting with
3381 a percent sign in it with strings from the specs. Each spec
3382 should be of the form `char:string' which will cause every
3383 appearance of the sequence `%char' in format to be replaced by
3384 the string. The `%' sequence may also contain optional minimum
3385 and maximum field width specifications between the `%' and the
3386 `char' in the form `%min.maxc', i.e. the minimum field width is
3387 given first and if the maximum field width is used, it has to be
3388 preceded by a dot. Specifying a minimum field width makes the
3389 result be padded with spaces to the right if the string is
3390 shorter than the requested width. Padding to the left can be
3391 achieved by giving a negative minimum field width. If a maximum
3392 field width is specified, the string will be truncated after
3393 that many characters. After all `%' sequences for the given
3394 specs have been processed, the resulting string is stored in the
3395 parameter param.
3396
3397 The %-escapes also understand ternary expressions in the form
3398 used by prompts. The % is followed by a `(' and then an ordi‐
3399 nary format specifier character as described above. There may
3400 be a set of digits either before or after the `('; these specify
3401 a test number, which defaults to zero. Negative numbers are
3402 also allowed. An arbitrary delimiter character follows the for‐
3403 mat specifier, which is followed by a piece of `true' text, the
3404 delimiter character again, a piece of `false' text, and a clos‐
3405 ing parenthesis. The complete expression (without the digits)
3406 thus looks like `%(X.text1.text2)', except that the `.' charac‐
3407 ter is arbitrary. The value given for the format specifier in
3408 the char:string expressions is evaluated as a mathematical
3409 expression, and compared with the test number. If they are the
3410 same, text1 is output, else text2 is output. A parenthesis may
3411 be escaped in text2 as %). Either of text1 or text2 may contain
3412 nested %-escapes.
3413
3414 For example:
3415
3416 zformat -f REPLY "The answer is '%3(c.yes.no)'." c:3
3417
3418 outputs "The answer is 'yes'." to REPLY since the value for the
3419 format specifier c is 3, agreeing with the digit argument to the
3420 ternary expression.
3421
3422 The second form, using the -a option, can be used for aligning
3423 strings. Here, the specs are of the form `left:right' where
3424 `left' and `right' are arbitrary strings. These strings are
3425 modified by replacing the colons by the sep string and padding
3426 the left strings with spaces to the right so that the sep
3427 strings in the result (and hence the right strings after them)
3428 are all aligned if the strings are printed below each other.
3429 All strings without a colon are left unchanged and all strings
3430 with an empty right string have the trailing colon removed. In
3431 both cases the lengths of the strings are not used to determine
3432 how the other strings are to be aligned. A colon in the left
3433 string can be escaped with a backslash. The resulting strings
3434 are stored in the array.
3435
3436 zregexparse
3437 This implements some internals of the _regex_arguments function.
3438
3439 zparseopts [ -D -E -F -K -M ] [ -a array ] [ -A assoc ] [ - ] spec ...
3440 This builtin simplifies the parsing of options in positional
3441 parameters, i.e. the set of arguments given by $*. Each spec
3442 describes one option and must be of the form `opt[=array]'. If
3443 an option described by opt is found in the positional parameters
3444 it is copied into the array specified with the -a option; if the
3445 optional `=array' is given, it is instead copied into that
3446 array, which should be declared as a normal array and never as
3447 an associative array.
3448
3449 Note that it is an error to give any spec without an `=array'
3450 unless one of the -a or -A options is used.
3451
3452 Unless the -E option is given, parsing stops at the first string
3453 that isn't described by one of the specs. Even with -E, parsing
3454 always stops at a positional parameter equal to `-' or `--'. See
3455 also -F.
3456
3457 The opt description must be one of the following. Any of the
3458 special characters can appear in the option name provided it is
3459 preceded by a backslash.
3460
3461 name
3462 name+ The name is the name of the option without the leading
3463 `-'. To specify a GNU-style long option, one of the
3464 usual two leading `-' must be included in name; for exam‐
3465 ple, a `--file' option is represented by a name of
3466 `-file'.
3467
3468 If a `+' appears after name, the option is appended to
3469 array each time it is found in the positional parameters;
3470 without the `+' only the last occurrence of the option is
3471 preserved.
3472
3473 If one of these forms is used, the option takes no argu‐
3474 ment, so parsing stops if the next positional parameter
3475 does not also begin with `-' (unless the -E option is
3476 used).
3477
3478 name:
3479 name:-
3480 name:: If one or two colons are given, the option takes an argu‐
3481 ment; with one colon, the argument is mandatory and with
3482 two colons it is optional. The argument is appended to
3483 the array after the option itself.
3484
3485 An optional argument is put into the same array element
3486 as the option name (note that this makes empty strings as
3487 arguments indistinguishable). A mandatory argument is
3488 added as a separate element unless the `:-' form is used,
3489 in which case the argument is put into the same element.
3490
3491 A `+' as described above may appear between the name and
3492 the first colon.
3493
3494 In all cases, option-arguments must appear either immediately
3495 following the option in the same positional parameter or in the
3496 next one. Even an optional argument may appear in the next
3497 parameter, unless it begins with a `-'. There is no special
3498 handling of `=' as with GNU-style argument parsers; given the
3499 spec `-foo:', the positional parameter `--foo=bar' is parsed as
3500 `--foo' with an argument of `=bar'.
3501
3502 When the names of two options that take no arguments overlap,
3503 the longest one wins, so that parsing for the specs `-foo -foo‐
3504 bar' (for example) is unambiguous. However, due to the aforemen‐
3505 tioned handling of option-arguments, ambiguities may arise when
3506 at least one overlapping spec takes an argument, as in `-foo:
3507 -foobar'. In that case, the last matching spec wins.
3508
3509 The options of zparseopts itself cannot be stacked because, for
3510 example, the stack `-DEK' is indistinguishable from a spec for
3511 the GNU-style long option `--DEK'. The options of zparseopts
3512 itself are:
3513
3514 -a array
3515 As described above, this names the default array in which
3516 to store the recognised options.
3517
3518 -A assoc
3519 If this is given, the options and their values are also
3520 put into an associative array with the option names as
3521 keys and the arguments (if any) as the values.
3522
3523 -D If this option is given, all options found are removed
3524 from the positional parameters of the calling shell or
3525 shell function, up to but not including any not described
3526 by the specs. If the first such parameter is `-' or
3527 `--', it is removed as well. This is similar to using
3528 the shift builtin.
3529
3530 -E This changes the parsing rules to not stop at the first
3531 string that isn't described by one of the specs. It can
3532 be used to test for or (if used together with -D) extract
3533 options and their arguments, ignoring all other options
3534 and arguments that may be in the positional parameters.
3535 As indicated above, parsing still stops at the first `-'
3536 or `--' not described by a spec, but it is not removed
3537 when used with -D.
3538
3539 -F If this option is given, zparseopts immediately stops at
3540 the first option-like parameter not described by one of
3541 the specs, prints an error message, and returns status 1.
3542 Removal (-D) and extraction (-E) are not performed, and
3543 option arrays are not updated. This provides basic vali‐
3544 dation for the given options.
3545
3546 Note that the appearance in the positional parameters of
3547 an option without its required argument always aborts
3548 parsing and returns an error as described above regard‐
3549 less of whether this option is used.
3550
3551 -K With this option, the arrays specified with the -a option
3552 and with the `=array' forms are kept unchanged when none
3553 of the specs for them is used. Otherwise the entire
3554 array is replaced when any of the specs is used. Indi‐
3555 vidual elements of associative arrays specified with the
3556 -A option are preserved by -K. This allows assignment of
3557 default values to arrays before calling zparseopts.
3558
3559 -M This changes the assignment rules to implement a map
3560 among equivalent option names. If any spec uses the
3561 `=array' form, the string array is interpreted as the
3562 name of another spec, which is used to choose where to
3563 store the values. If no other spec is found, the values
3564 are stored as usual. This changes only the way the val‐
3565 ues are stored, not the way $* is parsed, so results may
3566 be unpredictable if the `name+' specifier is used incon‐
3567 sistently.
3568
3569 For example,
3570
3571 set -- -a -bx -c y -cz baz -cend
3572 zparseopts a=foo b:=bar c+:=bar
3573
3574 will have the effect of
3575
3576 foo=(-a)
3577 bar=(-b x -c y -c z)
3578
3579 The arguments from `baz' on will not be used.
3580
3581 As an example for the -E option, consider:
3582
3583 set -- -a x -b y -c z arg1 arg2
3584 zparseopts -E -D b:=bar
3585
3586 will have the effect of
3587
3588 bar=(-b y)
3589 set -- -a x -c z arg1 arg2
3590
3591 I.e., the option -b and its arguments are taken from the posi‐
3592 tional parameters and put into the array bar.
3593
3594 The -M option can be used like this:
3595
3596 set -- -a -bx -c y -cz baz -cend
3597 zparseopts -A bar -M a=foo b+: c:=b
3598
3599 to have the effect of
3600
3601 foo=(-a)
3602 bar=(-a '' -b xyz)
3603
3604
3605
3606zsh 5.8 February 14, 2020 ZSHMODULES(1)