NAME
zshmodules - zsh loadable modules
DESCRIPTION
Some optional parts of zsh are in modules, separate from the core of the shell. Each of these modules may be linked in to the shell at build time, or can be dynamically linked while the shell is running if the installation supports this feature. The modules that are bundled with the zsh distribution are: zzsshh//ccaappBuiltins for manipulating POSIX.1e (POSIX.6) capability (privi-
lege) sets. zzsshh//cclloonnee A builtin that can clone a running shell onto another terminal. zzsshh//ccoommppccttll The ccoommppccttll builtin for controlling completion. zzsshh//ccoommpplleettee The basic completion code. zzsshh//ccoommpplliisstt Completion listing extensions. zzsshh//ccoommppuuttiill A module with utility builtins needed for the shell function based completion system. zzsshh//ddaatteettiimmee Some date/time commands and parameters. zzsshh//ddeellttoocchhaarrA ZLE function duplicating EMACS' zzaapp-ttoo-cchhaarr.
zzsshh//eexxaammppllee An example of how to write a module. zzsshh//ffiilleess Some basic file manipulation commands as builtins. zzsshh//mmaappffiillee Access to external files via a special associative array. zzsshh//mmaatthhffuunnccStandard scientific functions for use in mathematical evalua-
tions. zzsshh//ppaarraammeetteerr Access to internal hash tables via special associative arrays. zzsshh//ppccrree Interface to the PCRE library. zzsshh//sscchheedd A builtin that provides a timed execution facility within the shell. zzsshh//nneett//ssoocckkeett Manipulation of Unix domain sockets zzsshh//ssttaatt A builtin command interface to the ssttaatt system call. zzsshh//ssyysstteemmA builtin interface to various low-level system features.
zzsshh//nneett//ttccpp Manipulation of TCP sockets zzsshh//tteerrmmccaapp Interface to the termcap database. zzsshh//tteerrmmiinnffoo Interface to the terminfo database. zzsshh//zzffttpp A builtin FTP client. zzsshh//zzllee The Zsh Line Editor, including the bbiinnddkkeeyy and vvaarreedd builtins. zzsshh//zzlleeppaarraammeetteerr Access to internals of the Zsh Line Editor via parameters. zzsshh//zzpprrooff A module allowing profiling for shell functions. zzsshh//zzppttyyA builtin for starting a command in a pseudo-terminal.
zzsshh//zzsseelleecctt Block and return when file descriptors are ready. zzsshh//zzuuttiill Some utility builtins, e.g. the one for supporting configuration via styles. TTHHEE ZZSSHH//CCAAPP MMOODDUULLEEThe zzsshh//ccaapp module is used for manipulating POSIX.1e (POSIX.6) capabil-
ity sets. If the operating system does not support this interface, the builtins defined by this module will do nothing. The builtins in this module are: ccaapp [ capabilities ] Change the shell's process capability sets to the specifiedcapabilities, otherwise display the shell's current capabili-
ties. ggeettccaapp filename ...This is a built-in implementation of the POSIX standard utility.
It displays the capability sets on each specified filename. sseettccaapp capabilities filename ...This is a built-in implementation of the POSIX standard utility.
It sets the capability sets on each specified filename to the specified capabilities. TTHHEE ZZSSHH//CCLLOONNEE MMOODDUULLEE The zzsshh//cclloonnee module makes available one builtin command: cclloonnee tty Creates a forked instance of the current shell, attached to the specified tty. In the new shell, the PPIIDD, PPPPIIDD and TTTTYY specialparameters are changed appropriately. $$!! is set to zero in the
new shell, and to the new shell's PID in the original shell.The return value of the builtin is zero in both shells if suc-
cessful, and non-zero on error.
The target of cclloonnee should be an unused terminal, such as an unused virtual console or a virtual terminal created byxterm -e sh -c 'trap : INT QUIT TSTP; tty; while :; do sleep
100000000; done' Some words of explanation are warranted about this long xtermcommand line: when doing clone on a pseudo-terminal, some other
session ("session" meant as a unix session group, or SID) is already owning the terminal. Hence the cloned zsh cannot acquirethe pseudo-terminal as a controlling tty. That means two things:
the job control signals will go to the sh-started-by-xterm
process group (that's why we disable INT QUIT and TSTP with trap; otherwise the while loop could get suspended or killed) the cloned shell will have job control disabled, and the jobcontrol keys (control-C, control-\ and control-Z) will not
work. This does not apply when cloning to an uunnuusseedd vc. Cloning to an used (and unprepared) terminal will result in two processes reading simultaneously from the same terminal, with input bytes going randomly to either process.cclloonnee is mostly useful as a shell built-in replacement for
openvt. TTHHEE ZZSSHH//CCOOMMPPCCTTLL MMOODDUULLEE The zzsshh//ccoommppccttll module makes available two builtin commands. ccoommppccttll,is the old, deprecated way to control completions for ZLE. See zshcom-
pctl(1). The other builtin command, ccoommppccaallll can be used inuser-defined completion widgets, see zshcompwid(1).
TTHHEE ZZSSHH//CCOOMMPPLLEETTEE MMOODDUULLEE The zzsshh//ccoommpplleettee module makes available several builtin commands whichcan be used in user-defined completion widgets, see zshcompwid(1).
TTHHEE ZZSSHH//CCOOMMPPLLIISSTT MMOODDUULLEE The zzsshh//ccoommpplliisstt module offers three extensions to completion listings: the ability to highlight matches in such a list, the ability to scroll through long lists and a different style of menu completion. CCoolloorreedd ccoommpplleettiioonn lliissttiinnggss Whenever one of the parameters ZZLLSSCCOOLLOORRSS or ZZLLSSCCOOLLOOUURRSS is set and the zzsshh//ccoommpplliisstt module is loaded or linked into the shell, completionlists will be colored. Note, however, that ccoommpplliisstt will not automati-
cally be loaded if it is not linked in: on systems with dynamic load-
ing, `zzmmooddllooaadd zzsshh//ccoommpplliisstt' is required. The parameters ZZLLSSCCOOLLOORRSS and ZZLLSSCCOOLLOOUURRSS describe how matches are highlighted. To turn on highlighting an empty value suffices, in which case all the default values given below will be used. The format of the value of these parameters is the same as used by the GNU version ofthe llss command: a colon-separated list of specifications of the form
`name=value'. The name may be one of the following strings, most of which specify file types for which the value will be used. The strings and their default values are: nnoo 00 for normal text (i.e. when displaying something other than a matched file) ffii 00 for regular files ddii 3322 for directories llnn 3366 for symbolic links ppii 3311 for named pipes (FIFOs) ssoo 3333 for sockets bbdd 4444;;3377 for block devices ccdd 4444;;3377 for character devices eexx 3355 for executable files mmii nonefor a non-existent file (default is the value defined for ffii)
llcc \\ee[[ for the left code (see below) rrcc mm for the right codettcc 00 for the character indicating the file type printed after file-
names if the LLIISSTTTTYYPPEESS option is set sspp 00 for the spaces printed after matches to align the next column eecc none for the end codeApart from these strings, the name may also be an asterisk (`**') fol-
lowed by any string. The value given for such a string will be used for all files whose name ends with the string. The name may also be anequals sign (`==') followed by a pattern. The value given for this pat-
tern will be used for all matches (not just filenames) whose display string are matched by the pattern. Definitions for both of these take precedence over the values defined for file types and the form with the leading asterisk takes precedence over the form with the leading equal sign. The last form also allows different parts of the displayed strings tobe colored differently. For this, the pattern has to use the `((##bb))'
globbing flag and pairs of parentheses surrounding the parts of the strings that are to be colored differently. In this case the value may consist of more than one color code separated by equal signs. The first code will be used for all parts for which no explicit code is specified and the following codes will be used for the parts matched bythe sub-patterns in parentheses. For example, the specification
`==((##bb))((??))**((??))==00==33==77' will be used for all matches which are at least
two characters long and will use the code `33' for the first character, `77' for the last character and `00' for the rest. All three forms of name may be preceded by a pattern in parentheses. If this is given, the value will be used only for matches in groups whose names are matched by the pattern given in the parentheses. For example, `((gg**))mm**==4433' highlights all matches beginning with `mm' in groups whose names begin with `gg' using the color code `4433'. In case of the `llcc', `rrcc', and `eecc' codes, the group pattern is ignored. Note also that all patterns are tried in the order in which they appear in the parameter value until the first one matches which is then used. When printing a match, the code prints the value of llcc, the value forthe file-type or the last matching specification with a `**', the value
of rrcc, the string to display for the match itself, and then the value of eecc if that is defined or the values of llcc, nnoo, and rrcc if eecc is not defined. The default values are ISO 6429 (ANSI) compliant and can be used on vt100 compatible terminals such as xxtteerrmms. On monochrome terminals the default values will have no visible effect. The ccoolloorrss function from the contribution can be used to get associative arrays containing thecodes for ANSI terminals (see the section `Other Functions' in zshcon-
trib(1)). For example, after loading ccoolloorrss, one could use `$$ccooll-
oorrss[[rreedd]]' to get the code for foreground color red and `$$ccooll-
oorrss[[bbgg-ggrreeeenn]]' for the code for background color green.
If the completion system invoked by compinit is used, these parameters should not be set directly because the system controls them itself.Instead, the lliisstt-ccoolloorrss style should be used (see the section `Comple-
tion System Configuration' in zshcompsys(1)). SSccrroolllliinngg iinn ccoommpplleettiioonn lliissttiinnggss To enable scrolling through a completion list, the LLIISSTTPPRROOMMPPTT parameter must be set. Its value will be used as the prompt; if it is the empty string, a default prompt will be used. The value may contain escapesof the form `%%xx'. It supports the escapes `%%BB', `%%bb', `%%SS', `%%ss',
`%%UU', `%%uu' and `%%{{......%%}}' used also in shell prompts as well as three
pairs of additional sequences: a `%%ll' or `%%LL' is replaced by the number
of the last line shown and the total number of lines in the form `num-
ber//total'; a `%%mm' or `%%MM' is replaced with the number of the last
match shown and the total number of matches; and `%%pp' or `%%PP' is
replaced with `TToopp', `BBoottttoomm' or the position of the first line shown in percent of the total number of lines, respectively. In each of these cases the form with the uppercase letter will be replaced with astring of fixed width, padded to the right with spaces, while the low-
ercase form will not be padded. If the parameter LLIISSTTPPRROOMMPPTT is set, the completion code will not ask if the list should be shown. Instead it immediately starts displaying the list, stopping after the first screenful, showing the prompt at the bottom, waiting for a keypress after temporarily switching to the lliissttssccrroollll keymap. Some of the zle functions have a special meaning while scrolling lists:sseenndd-bbrreeaakk
stops listing discarding the key pressedaacccceepptt-lliinnee, ddoowwnn-hhiissttoorryy, ddoowwnn-lliinnee-oorr-hhiissttoorryy
ddoowwnn-lliinnee-oorr-sseeaarrcchh, vvii-ddoowwnn-lliinnee-oorr-hhiissttoorryy
scrolls forward one lineccoommpplleettee-wwoorrdd, mmeennuu-ccoommpplleettee, eexxppaanndd-oorr-ccoommpplleettee
eexxppaanndd-oorr-ccoommpplleettee-pprreeffiixx, mmeennuu-ccoommpplleettee-oorr-eexxppaanndd
scrolls forward one screenful Every other character stops listing and immediately processes the key as usual. Any key that is not bound in the lliissttssccrroollll keymap or thatis bound to uunnddeeffiinneedd-kkeeyy is looked up in the keymap currently
selected. As for the ZZLLSSCCOOLLOORRSS and ZZLLSSCCOOLLOOUURRSS parameters, LLIISSTTPPRROOMMPPTT should not be set directly when using the shell function based completion system.Instead, the lliisstt-pprroommpptt style should be used.
MMeennuu sseelleeccttiioonn The zzsshh//ccoommpplliisstt module also offers an alternative style of selecting matches from a list, called menu selection, which can be used if the shell is set up to return to the last prompt after showing a completion list (see the AALLWWAAYYSSLLAASSTTPPRROOMMPPTT option in zshoptions(1)). It can beinvoked directly by the widget mmeennuu-sseelleecctt defined by the module.
Alternatively, the parameter MMEENNUUSSEELLEECCTT can be set to an integer, which gives the minimum number of matches that must be present before menu selection is automatically turned on. This second method requires that menu completion be started, either directly from a widget such asmmeennuu-ccoommpplleettee, or due to one of the options MMEENNUUCCOOMMPPLLEETTEE or AAUUTTOOMMEENNUU
being set. If MMEENNUUSSEELLEECCTT is set, but is 0, 1 or empty, menu selection will always be started during an ambiguous menu completion.When using the completion system based on shell functions, the MMEENNUUSSEE-
LLEECCTT parameter should not be used (like the ZZLLSSCCOOLLOORRSS and ZZLLSSCCOOLLOOUURRSS parameters described above). Instead, the mmeennuu style should be used with the sseelleecctt==... keyword. After menu selection is started, the matches will be listed. If there are more matches than fit on the screen, only the first screenful is shown. The matches to insert into the command line can be selected from this list. In the list one match is highlighted using the value for mmaa from the ZZLLSSCCOOLLOORRSS or ZZLLSSCCOOLLOOUURRSS parameter. The default value for this is `77' which forces the selected match to be highlighted usingstandout mode on a vt100-compatible terminal. If neither ZZLLSSCCOOLLOORRSS
nor ZZLLSSCCOOLLOOUURRSS is set, the same terminal control sequence as for the`%%SS' escape in prompts is used.
If there are more matches than fit on the screen and the parameterMMEENNUUPPRROOMMPPTT is set, its value will be shown below the matches. It sup-
ports the same escape sequences as LLIISSTTPPRROOMMPPTT, but the number of the match or line shown will be that of the one where the mark is placed. If its value is the empty string, a default prompt will be used. The MMEENNUUSSCCRROOLLLL parameter can be used to specify how the list is scrolled. If the parameter is unset, this is done line by line, if it is set to `00' (zero), the list will scroll half the number of lines of the screen. If the value is positive, it gives the number of lines to scroll and if it is negative, the list will be scrolled the number of lines of the screen minus the (absolute) value. As for the ZZLLSSCCOOLLOORRSS, ZZLLSSCCOOLLOOUURRSS and LLIISSTTPPRROOMMPPTT parameters, neither MMEENNUUPPRROOMMPPTT nor MMEENNUUSSCCRROOLLLL should be set directly when using the shellfunction based completion system. Instead, the sseelleecctt-pprroommpptt and
sseelleecctt-ssccrroollll styles should be used.
The completion code sometimes decides not to show all of the matches inthe list. These hidden matches are either matches for which the com-
pletion function which added them explicitly requested that they notappear in the list (using the -nn option of the ccoommppaadddd builtin command)
or they are matches which duplicate a string already in the list (because they differ only in things like prefixes or suffixes that are not displayed). In the list used for menu selection, however, even these matches are shown so that it is possible to select them. To highlight such matches the hhii and dduu capabilities in the ZZLLSSCCOOLLOORRSS and ZZLLSSCCOOLLOOUURRSS parameters are supported for hidden matches of the first and second kind, respectively.Selecting matches is done by moving the mark around using the zle move-
ment functions. When not all matches can be shown on the screen at the same time, the list will scroll up and down when crossing the top or bottom line. The following zle functions have special meaning during menu selection:aacccceepptt-lliinnee
accepts the current match and leaves menu selectionsseenndd-bbrreeaakk
leaves menu selection and restores the previous contents of the command linerreeddiissppllaayy, cclleeaarr-ssccrreeeenn
execute their normal function without leaving menu selectionaacccceepptt-aanndd-hhoolldd, aacccceepptt-aanndd-mmeennuu-ccoommpplleettee
accept the currently inserted match and continue selection allowing to select the next match to insert into the lineaacccceepptt-aanndd-iinnffeerr-nneexxtt-hhiissttoorryy
accepts the current match and then tries completion with menu selection again; in the case of files this allows one to select a directory and immediately attempt to complete files in it; if there are no matches, a message is shown and one can use uunnddoo to go back to completion on the previous level, every other key leaves menu selection (including the other zle functions which are otherwise special during menu selection) uunnddoo removes matches inserted during the menu selection by one of the three functions beforeddoowwnn-hhiissttoorryy, ddoowwnn-lliinnee-oorr-hhiissttoorryy
vvii-ddoowwnn-lliinnee-oorr-hhiissttoorryy, ddoowwnn-lliinnee-oorr-sseeaarrcchh
moves the mark one line downuupp-hhiissttoorryy, uupp-lliinnee-oorr-hhiissttoorryy
vvii-uupp-lliinnee-oorr-hhiissttoorryy, uupp-lliinnee-oorr-sseeaarrcchh
moves the mark one line upffoorrwwaarrdd-cchhaarr, vvii-ffoorrwwaarrdd-cchhaarr
moves the mark one column rightbbaacckkwwaarrdd-cchhaarr, vvii-bbaacckkwwaarrdd-cchhaarr
moves the mark one column leftffoorrwwaarrdd-wwoorrdd, vvii-ffoorrwwaarrdd-wwoorrdd
vvii-ffoorrwwaarrdd-wwoorrdd-eenndd, eemmaaccss-ffoorrwwaarrdd-wwoorrdd
moves the mark one screenful downbbaacckkwwaarrdd-wwoorrdd, vvii-bbaacckkwwaarrdd-wwoorrdd, eemmaaccss-bbaacckkwwaarrdd-wwoorrdd
moves the mark one screenful upvvii-ffoorrwwaarrdd-bbllaannkk-wwoorrdd, vvii-ffoorrwwaarrdd-bbllaannkk-wwoorrdd-eenndd
moves the mark to the first line of the next group of matchesvvii-bbaacckkwwaarrdd-bbllaannkk-wwoorrdd
moves the mark to the last line of the previous group of matchesbbeeggiinnnniinngg-ooff-hhiissttoorryy
moves the mark to the first lineeenndd-ooff-hhiissttoorryy
moves the mark to the last linebbeeggiinnnniinngg-ooff-bbuuffffeerr-oorr-hhiissttoorryy, bbeeggiinnnniinngg-ooff-lliinnee
bbeeggiinnnniinngg-ooff-lliinnee-hhiisstt, vvii-bbeeggiinnnniinngg-ooff-lliinnee
moves the mark to the leftmost columneenndd-ooff-bbuuffffeerr-oorr-hhiissttoorryy, eenndd-ooff-lliinnee
eenndd-ooff-lliinnee-hhiisstt, vvii-eenndd-ooff-lliinnee
moves the mark to the rightmost columnccoommpplleettee-wwoorrdd, mmeennuu-ccoommpplleettee, eexxppaanndd-oorr-ccoommpplleettee
eexxppaanndd-oorr-ccoommpplleettee-pprreeffiixx, mmeennuu-eexxppaanndd-oorr-ccoommpplleettee
moves the mark to the next matchrreevveerrssee-mmeennuu-ccoommpplleettee
moves the mark to the previous matchvvii-iinnsseerrtt
this toggles between normal and interactive mode; in interactivemode the keys bound to sseellff-iinnsseerrtt and sseellff-iinnsseerrtt-uunnmmeettaa insert
into the command line as in normal editing mode but without leaving menu selection; after each character completion is tried again and the list changes to contain only the new matches; the completion widgets make the longest unambiguous string beinserted in the command line and uunnddoo and bbaacckkwwaarrdd-ddeelleettee-cchhaarr
go back to the previous set of matcheshhiissttoorryy-iinnccrreemmeennttaall-sseeaarrcchh-ffoorrwwaarrdd,
hhiissttoorryy-iinnccrreemmeennttaall-sseeaarrcchh-bbaacckkwwaarrdd this starts incremental
searches in the list of completions displayed; in this mode,aacccceepptt-lliinnee only leaves incremental search, going back to the
normal menu selection mode All movement functions wrap around at the edges; any other zle function not listed leaves menu selection and executes that function. It is possible to make widgets in the above list do the same by using the form of the widget with a `..' in front. For example, the widget`..aacccceepptt-lliinnee' has the effect of leaving menu selection and accepting
the entire command line. During this selection the widget uses the keymap mmeennuusseelleecctt. Any keythat is not defined in this keymap or that is bound to uunnddeeffiinneedd-kkeeyy is
looked up in the keymap currently selected. This is used to ensure that the most important keys used during selection (namely the cursor keys, return, and TAB) have sensible defaults. However, keys in the mmeennuusseelleecctt keymap can be modified directly using the bbiinnddkkeeyy builtincommand (see zshmodules(1)). For example, to make the return key leave
menu selection without accepting the match currently selected one could callbbiinnddkkeeyy -MM mmeennuusseelleecctt ''^^MM'' sseenndd-bbrreeaakk
after loading the zzsshh//ccoommpplliisstt module. TTHHEE ZZSSHH//CCOOMMPPUUTTIILL MMOODDUULLEE The zzsshh//ccoommppuuttiill module adds several builtin commands that are used by some of the completion functions in the completion system based on shell functions (see zshcompsys(1) ). Except for ccoommppqquuoottee these builtin commands are very specialised and thus not very interesting when writing your own completion functions. In summary, these builtin commands are: ccoommppaarrgguummeennttss This is used by the aarrgguummeennttss function to do the argument andcommand line parsing. Like ccoommppddeessccrriibbee it has an option -ii to
do the parsing and initialize some internal state and various options to access the state information to decide what should be completed. ccoommppddeessccrriibbee This is used by the ddeessccrriibbee function to build the displays for the matches and to get the strings to add as matches with theiroptions. On the first call one of the options -ii or -II should
be supplied as the first argument. In the first case, displaystrings without the descriptions will be generated, in the sec-
ond case, the string used to separate the matches from their descriptions must be given as the second argument and the descriptions (if any) will be shown. All other arguments are like the definition arguments to ddeessccrriibbee itself.Once ccoommppddeessccrriibbee has been called with either the -ii or the -II
option, it can be repeatedly called with the -gg option and the
names of five arrays as its arguments. This will step through the different sets of matches and store the options in the first array, the strings with descriptions in the second, the matches for these in the third, the strings without descriptions in the fourth, and the matches for them in the fifth array. These are then directly given to ccoommppaadddd to register the matches with the completion code. ccoommppffiilleess Used by the ppaatthhffiilleess function to optimize complex recursive filename generation (globbing). It does three things. With the-pp and -PP options it builds the glob patterns to use, including
the paths already handled and trying to optimize the patterns with respect to the prefix and suffix from the line and thematch specification currently used. The -ii option does the
directory tests for the iiggnnoorree-ppaarreennttss style and the -rr option
tests if a component for some of the matches are equal to the string on the line and removes all other matches if that is true. ccoommppggrroouuppss Used by the ttaaggss function to implement the internals of theggrroouupp-oorrddeerr style. This only takes its arguments as names of
completion groups and creates the groups for it (all six types: sorted and unsorted, both without removing duplicates, withremoving all duplicates and with removing consecutive dupli-
cates).ccoommppqquuoottee [ -pp ] names ...
There may be reasons to write completion functions that have toadd the matches using the -QQ option to ccoommppaadddd and perform quot-
ing themselves. Instead of interpreting the first character of the aallllqquuootteess key of the ccoommppssttaattee special association and using the qq flag for parameter expansions, one can use this builtin command. The arguments are the names of scalar or array parameters and the values of these parameters are quoted asneeded for the innermost quoting level. If the -pp option is
given, quoting is done as if there is some prefix before the values of the parameters, so that a leading equal sign will not be quoted.The return value is non-zero in case of an error and zero other-
wise. ccoommppttaaggss ccoommppttrryy These implement the internals of the tags mechanism. ccoommppvvaalluueess Like ccoommppaarrgguummeennttss, but for the vvaalluueess function. TTHHEE ZZSSHH//DDAATTEETTIIMMEE MMOODDUULLEE The zzsshh//ddaatteettiimmee module makes available one builtin command:ssttrrffttiimmee [ -ss scalar ] format epochtime
Output the date denoted by epochtime in the format specified.If -ss scalar is given, assign the date to scalar instead of
printing it. The zzsshh//ddaatteettiimmee module makes available one parameter: EEPPOOCCHHSSEECCOONNDDSS An integer value representing the number of seconds since the epoch. TTHHEE ZZSSHH//DDEELLTTOOCCHHAARR MMOODDUULLEE The zzsshh//ddeellttoocchhaarr module makes available two ZLE functions:ddeelleettee-ttoo-cchhaarr
Read a character from the keyboard, and delete from the cursor position up to and including the next (or, with repeat count n, the nth) instance of that character. Negative repeat counts mean delete backwards.zzaapp-ttoo-cchhaarr
This behaves like ddeelleettee-ttoo-cchhaarr, except that the final occur-
rence of the character itself is not deleted. TTHHEE ZZSSHH//EEXXAAMMPPLLEE MMOODDUULLEE The zzsshh//eexxaammppllee module makes available one builtin command:eexxaammppllee [ -ffllaaggss ] [ args ... ]
Displays the flags and arguments it is invoked with. The purpose of the module is to serve as an example of how to write a module. THE ZSH/FILES MODULE The zzsshh//ffiilleess module makes some standard commands available as builtins:cchhggrrpp [ -RRss ] group filename ...
Changes group of files specified. This is equivalent to cchhoowwnnwith a user-spec argument of `::group'.
cchhoowwnn [ -RRss ] user-spec filename ...
Changes ownership and group of files specified.The user-spec can be in four forms:
user change owner to user; do not change group user:::: change owner to user; do not change group user:: change owner to user; change group to user's primary group user::group change owner to user; change group to group ::group do not change owner; change group to group In each case, the `::' may instead be a `..'. The rule is that if there is a `::' then the separator is `::', otherwise if there isa `..' then the separator is `..', otherwise there is no separa-
tor. Each of user and group may be either a username (or group name, as appropriate) or a decimal user ID (group ID). Interpretationas a name takes precedence, if there is an all-numeric username
(or group name).The -RR option causes cchhoowwnn to recursively descend into directo-
ries, changing the ownership of all files in the directory after changing the ownership of the directory itself.The -ss option is a zsh extension to cchhoowwnn functionality. It
enables paranoid behaviour, intended to avoid security problems involving a cchhoowwnn being tricked into affecting files other than the ones intended. It will refuse to follow symbolic links, sothat (for example) ``cchhoowwnn lluusseerr //ttmmpp//ffoooo//ppaasssswwdd'' can't acci-
dentally chown //eettcc//ppaasssswwdd if //ttmmpp//ffoooo happens to be a link to //eettcc. It will also check where it is after leaving directories, so that a recursive chown of a deep directory tree can't end up recursively chowning //uussrr as a result of directories being moved up the tree.llnn [ -ddffiiss ] filename dest
llnn [ -ddffiiss ] filename ... dir
Creates hard (or, with -ss, symbolic) links. In the first form,
the specified destination is created, as a link to the specified filename. In the second form, each of the filenames is taken in turn, and linked to a pathname in the specified directory that has the same last pathname component.Normally, llnn will not attempt to create hard links to directo-
ries. This check can be overridden using the -dd option. Typi-
cally only the super-user can actually succeed in creating hard
links to directories. This does not apply to symbolic links in any case.By default, existing files cannot be replaced by links. The -ii
option causes the user to be queried about replacing existingfiles. The -ff option causes existing files to be silently
deleted, without querying. -ff takes precedence.
mmkkddiirr [ -pp ] [ -mm mode ] dir ...
Creates directories. With the -pp option, non-existing parent
directories are first created if necessary, and there will be nocomplaint if the directory already exists. The -mm option can be
used to specify (in octal) a set of file permissions for the created directories, otherwise mode 777 modified by the current uummaasskk (see umask(2)) is used.mmvv [ -ffii ] filename dest
mmvv [ -ffii ] filename ... dir
Moves files. In the first form, the specified filename is moved to the specified destination. In the second form, each of thefilenames is taken in turn, and moved to a pathname in the spec-
ified directory that has the same last pathname component. By default, the user will be queried before replacing any file that the user cannot write to, but writable files will besilently removed. The -ii option causes the user to be queried
about replacing any existing files. The -ff option causes any
existing files to be silently deleted, without querying. -ff
takes precedence.Note that this mmvv will not move files across devices. Histori-
cal versions of mmvv, when actual renaming is impossible, fall back on copying and removing files; if this behaviour is desired, use ccpp and rrmm manually. This may change in a future version.rrmm [ -ddffiirrss ] filename ...
Removes files and directories specified.Normally, rrmm will not remove directories (except with the -rr
option). The -dd option causes rrmm to try removing directories
with uunnlliinnkk (see unlink(2)), the same method used for files.Typically only the super-user can actually succeed in unlinking
directories in this way. -dd takes precedence over -rr.
By default, the user will be queried before removing any file that the user cannot write to, but writable files will besilently removed. The -ii option causes the user to be queried
about removing any files. The -ff option causes files to be
silently deleted, without querying, and suppresses all errorindications. -ff takes precedence.
The -rr option causes rrmm to recursively descend into directories,
deleting all files in the directory before removing the direc-
tory with the rrmmddiirr system call (see rmdir(2)).The -ss option is a zsh extension to rrmm functionality. It
enables paranoid behaviour, intended to avoid common securityproblems involving a root-run rrmm being tricked into removing
files other than the ones intended. It will refuse to follow symbolic links, so that (for example) ``rrmm //ttmmpp//ffoooo//ppaasssswwdd'' can't accidentally remove //eettcc//ppaasssswwdd if //ttmmpp//ffoooo happens to be a link to //eettcc. It will also check where it is after leaving directories, so that a recursive removal of a deep directory tree can't end up recursively removing //uussrr as a result of directories being moved up the tree. rrmmddiirr dir ... Removes empty directories specified. ssyynncc Calls the system call of the same name (see sync(2)), which flushes dirty buffers to disk. It might return before the I/O has actually been completed. TTHHEE ZZSSHH//MMAAPPFFIILLEE MMOODDUULLEE The zzsshh//mmaappffiillee module provides one special associative array parameter of the same name. mmaappffiillee This associative array takes as keys the names of files; the resulting value is the content of the file. The value is treated identically to any other text coming from a parameter. The value may also be assigned to, in which case the file in question is written (whether or not it originally existed); or an element may be unset, which will delete the file in question. For example, `vvaarreedd mmaappffiillee[[mmyyffiillee]]' works as expected, editing the file `mmyyffiillee'. When the array is accessed as a whole, the keys are the names of files in the current directory, and the values are empty (tosave a huge overhead in memory). Thus $${{((kk))mmaappffiillee}} has the
same affect as the glob operator **((DD)), since files beginning with a dot are not special. Care must be taken with expressionssuch as rrmm $${{((kk))mmaappffiillee}}, which will delete every file in the
current directory without the usual `rrmm **' test.The parameter mmaappffiillee may be made read-only; in that case, files
referenced may not be written or deleted. LLiimmiittaattiioonnss Although reading and writing of the file in question is efficiently handled, zsh's internal memory management may be arbitrarily baroque.Thus it should not automatically be assumed that use of mmaappffiillee repre-
sents a gain in efficiency over use of other mechanisms. Note in par-
ticular that the whole contents of the file will always reside physi-
cally in memory when accessed (possibly multiple times, due to standard parameter substitution operations). In particular, this means handling of sufficiently long files (greater than the machine's swap space, or than the range of the pointer type) will be incorrect.No errors are printed or flagged for non-existent, unreadable, or
unwritable files, as the parameter mechanism is too low in the shell execution hierarchy to make this convenient. It is unfortunate that the mechanism for loading modules does not yet allow the user to specify the name of the shell parameter to be given the special behaviour. TTHHEE ZZSSHH//MMAATTHHFFUUNNCC MMOODDUULLEE The zzsshh//mmaatthhffuunncc module provides standard mathematical functions foruse when evaluating mathematical formulae. The syntax agrees with nor-
mal C and FORTRAN conventions, for example, (((( ff == ssiinn((00..33)) )))) assigns the sine of 0.3 to the parameter f. Most functions take floating point arguments and return a floating point value. However, any necessary conversions from or to integer type will be performed automatically by the shell. Apart from aattaannwith a second argument and the aabbss, iinntt and ffllooaatt functions, all func-
tions behave as noted in the manual page for the corresponding C func-
tion, except that any arguments out of range for the function in ques-
tion will be detected by the shell and an error reported. The following functions take a single floating point argument: aaccooss, aaccoosshh, aassiinn, aassiinnhh, aattaann, aattaannhh, ccbbrrtt, cceeiill, ccooss, ccoosshh, eerrff, eerrffcc, eexxpp, eexxppmm11, ffaabbss, fflloooorr, ggaammmmaa, jj00, jj11, llggaammmmaa, lloogg, lloogg1100, lloogg11pp, llooggbb, ssiinn, ssiinnhh, ssqqrrtt, ttaann, ttaannhh, yy00, yy11. The aattaann function can optionally take a second argument, in which case it behaves like the C function aattaann22. The iillooggbb function takes a single floating point argument, but returns an integer. The function ssiiggnnggaamm takes no arguments, and returns an integer, which is the C variable of the same name, as described in gamma(3). Note that it is therefore only useful immediately after a call to ggaammmmaa orllggaammmmaa. Note also that `ssiiggnnggaamm(())' and `ssiiggnnggaamm' are distinct expres-
sions. The following functions take two floating point arguments: ccooppyyssiiggnn, ffmmoodd, hhyyppoott, nneexxttaafftteerr.The following take an integer first argument and a floating point sec-
ond argument: jjnn, yynn.The following take a floating point first argument and an integer sec-
ond argument: llddeexxpp, ssccaallbb. The function aabbss does not convert the type of its single argument; it returns the absolute value of either a floating point number or an integer. The functions ffllooaatt and iinntt convert their arguments into a floating point or integer value (by truncation) respectively. Note that the C ppooww function is available in ordinary math evaluation as the `****' operator and is not provided here. The function rraanndd4488 is available if your system's mathematical libraryhas the function eerraanndd4488((33)). It returns a pseudo-random floating point
number between 0 and 1. It takes a single string optional argument. If the argument is not present, the random number seed is initialisedby three calls to the rraanndd((33)) function -- this produces the same ran-
dom numbers as the next three values of $$RRAANNDDOOMM.
If the argument is present, it gives the name of a scalar parameter where the current random number seed will be stored. On the first call, the value must contain at least twelve hexadecimal digits (the remainder of the string is ignored), or the seed will be initialised in the same manner as for a call to rraanndd4488 with no argument. Subsequent calls to rraanndd4488(param) will then maintain the seed in the parameter param as a string of twelve hexadecimal digits, with no base signifier. The random number sequences for different parameters are completely independent, and are also independent from that used by calls to rraanndd4488 with no argument. For example, considerpprriinntt $$(((( rraanndd4488((sseeeedd)) ))))
pprriinntt $$(((( rraanndd4488(()) ))))
pprriinntt $$(((( rraanndd4488((sseeeedd)) ))))
Assuming $$sseeeedd does not exist, it will be initialised by the first
call. In the second call, the default seed is initialised; note, how-
ever, that because of the properties of rraanndd(()) there is a correlation between the seeds used for the two initialisations, so for more secureuses, you should generate your own 12-byte seed. The third call
returns to the same sequence of random numbers used in the first call, unaffected by the intervening rraanndd4488(()). TTHHEE ZZSSHH//PPAARRAAMMEETTEERR MMOODDUULLEE The zzsshh//ppaarraammeetteerr module gives access to some of the internal hash tables used by the shell by defining some special parameters. ooppttiioonnss The keys for this associative array are the names of the options that can be set and unset using the sseettoopptt and uunnsseettoopptt builtins. The value of each key is either the string oonn if the option is currently set, or the string ooffff if the option is unset. Setting a key to one of these strings is like setting or unsetting the option, respectively. Unsetting a key in this array is like setting it to the value ooffff. ccoommmmaannddss This array gives access to the command hash table. The keys are the names of external commands, the values are the pathnames of the files that would be executed when the command would be invoked. Setting a key in this array defines a new entry in this table in the same way as with the hhaasshh builtin. Unsetting a key as in `uunnsseett ""ccoommmmaannddss[[ffoooo]]""' removes the entry for the given key from the command hash table. ffuunnccttiioonnss This associative array maps names of enabled functions to their definitions. Setting a key in it is like defining a function with the name given by the key and the body given by the value. Unsetting a key removes the definition for the function named by the key. ddiissffuunnccttiioonnss Like ffuunnccttiioonnss but for disabled functions. bbuuiillttiinnssThis associative array gives information about the builtin com-
mands currently enabled. The keys are the names of the builtincommands and the values are either `uunnddeeffiinneedd' for builtin com-
mands that will automatically be loaded from a module if invoked or `ddeeffiinneedd' for builtin commands that are already loaded. ddiissbbuuiillttiinnss Like bbuuiillttiinnss but for disabled builtin commands. rreesswwoorrddss This array contains the enabled reserved words. ddiissrreesswwoorrddss Like rreesswwoorrddss but for disabled reserved words. aalliiaasseess This maps the names of the regular aliases currently enabled to their expansions. ddiissaalliiaasseess Like aalliiaasseess but for disabled regular aliases. ggaalliiaasseess Like aalliiaasseess, but for global aliases. ddiissggaalliiaasseess Like ggaalliiaasseess but for disabled global aliases. ssaalliiaasseess Like rraalliiaasseess, but for suffix aliases. ddiissssaalliiaasseess Like ssaalliiaasseess but for disabled suffix aliases. ppaarraammeetteerrssThe keys in this associative array are the names of the parame-
ters currently defined. The values are strings describing thetype of the parameter, in the same format used by the tt parame-
ter flag, see zshexpn(1) . Setting or unsetting keys in this array is not possible. mmoodduulleess An associative array giving information about modules. The keys are the names of the modules loaded, registered to be autoloaded, or aliased. The value says which state the named module is in and is one of the strings `llooaaddeedd', `aauuttoollooaaddeedd', or `aalliiaass::name', where name is the name the module is aliased to. Setting or unsetting keys in this array is not possible. ddiirrssttaacckk A normal array holding the elements of the directory stack. Note that the output of the ddiirrss builtin command includes one more directory, the current working directory. hhiissttoorryy This associative array maps history event numbers to the full history lines. hhiissttoorryywwoorrddss A special array containing the words stored in the history. jjoobbddiirrss This associative array maps job numbers to the directories fromwhich the job was started (which may not be the current direc-
tory of the job). jjoobbtteexxttssThis associative array maps job numbers to the texts of the com-
mand lines that were used to start the jobs. jjoobbssttaatteess This associative array gives information about the states of thejobs currently known. The keys are the job numbers and the val-
ues are strings of the form `job-state:mark:pid==state......'. The
job-state gives the state the whole job is currently in, one of
`rruunnnniinngg', `ssuussppeennddeedd', or `ddoonnee'. The mark is `++' for the cur-
rent job, `-' for the previous job and empty otherwise. This is
followed by one `pid==state' for every process in the job. The pids are, of course, the process IDs and the state describes the state of that process. nnaammeeddddiirrss This associative array maps the names of named directories to the pathnames they stand for. uusseerrddiirrss This associative array maps user names to the pathnames of their home directories. ffuunnccssttaacckk This array contains the names of the functions currently being executed. The first element is the name of the function using the parameter. TTHHEE ZZSSHH//PPCCRREE MMOODDUULLEE The zzsshh//ppccrree module makes some commands available as builtins:ppccrreeccoommppiillee [ -aaiimmxx ] PCRE
Compiles a perl-compatible regular expression.
Option -aa will force the pattern to be anchored. Option -ii will
compile a case-insensitive pattern. Option -mm will compile a
multi-line pattern; that is, ^^ and $$ will match newlines within
the pattern. Option -xx will compile an extended pattern,
wherein whitespace and ## comments are ignored.
ppccrreessttuuddyyStudies the previously-compiled PCRE which may result in faster
matching.ppccrreemmaattcchh [ -aa arr ] string
Returns successfully if ssttrriinngg matches the previously-compiled
PCRE. If the expression captures substrings within parentheses,ppccrreemmaattcchh will set the array $match to those substrings, unless
the -aa option is given, in which case it will set the array arr.
The zzsshh//ppccrree module makes available the following test condition:expr -ppccrree-mmaattcchh pcre
Matches a string against a perl-compatible regular expression.
For example,[[ "$text" -pcre-match ^d+$ ]] && print text variable contains
only "d's". TTHHEE ZZSSHH//SSCCHHEEDD MMOODDUULLEE The zzsshh//sscchheedd module makes available one builtin command: sscchheedd [++]hh::mm command ...sscchheedd [ -item ]
Make an entry in the scheduled list of commands to execute. The time may be specified in either absolute or relative time. With no arguments, prints the list of scheduled commands. With theargument `-item', removes the given item from the list.
TTHHEE ZZSSHH//NNEETT//SSOOCCKKEETT MMOODDUULLEE The zzsshh//nneett//ssoocckkeett module makes available one builtin command:zzssoocckkeett [ -aallttvv ] [ -dd fd ] [ args ]
zzssoocckkeett is implemented as a builtin to allow full use of shell command line editing, file I/O, and job control mechanisms. OOuuttbboouunndd CCoonnnneeccttiioonnsszzssoocckkeett [ -vv ] [ -dd fd ] filename
Open a new Unix domain connection to filename. The shell param-
eter RREEPPLLYY will be set to the file descriptor associated withthat connection. Currently, only stream connections are sup-
ported.If -dd is specified, its argument will be taken as the target
file descriptor for the connection.In order to elicit more verbose output, use -vv.
IInnbboouunndd CCoonnnneeccttiioonnsszzssoocckkeett -ll [ -vv ] [ -dd fd ] filename
zzssoocckkeett -ll will open a socket listening on filename. The shell
parameter RREEPPLLYY will be set to the file descriptor associated with that listener.If -dd is specified, its argument will be taken as the target
file descriptor for the connection.In order to elicit more verbose output, use -vv.
zzssoocckkeett -aa [ -ttvv ] [ -dd targetfd ] listenfd
zzssoocckkeett -aa will accept an incoming connection to the socket
associated with listenfd. The shell parameter RREEPPLLYY will be set to the file descriptor associated with the inbound connection.If -dd is specified, its argument will be taken as the target
file descriptor for the connection.If -tt is specified, zzssoocckkeett will return if no incoming connec-
tion is pending. Otherwise it will wait for one.In order to elicit more verbose output, use -vv.
TTHHEE ZZSSHH//SSTTAATT MMOODDUULLEE The zzsshh//ssttaatt module makes available one builtin command:ssttaatt [ -ggnnNNoollLLttTTrrss ] [ -ff fd ] [ -HH hash ] [ -AA array ] [ -FF fmt ] [
++element ] [ file ... ] The command acts as a front end to the ssttaatt system call (see stat(2)). If the ssttaatt call fails, the appropriate system error message printed and status 1 is returned. The fields of ssttrruucctt ssttaatt give information about the files provided as arguments to the command. In addition to those available from the ssttaatt call, an extra element `lliinnkk' is provided. These elements are: ddeevviiccee The number of the device on which the file resides. iinnooddee The unique number of the file on this device (`inode' number). mmooddee The mode of the file; that is, the file's type and accesspermissions. With the -ss option, this will be returned
as a string corresponding to the first column in the dis-
play of the llss -ll command.
nnlliinnkk The number of hard links to the file.uuiidd The user ID of the owner of the file. With the -ss
option, this is displayed as a user name.ggiidd The group ID of the file. With the -ss option, this is
displayed as a group name. rrddeevv The raw device number. This is only useful for special devices. ssiizzee The size of the file in bytes. aattiimmee mmttiimmee ccttiimmee The last access, modification and inode change times of the file, respectively, as the number of seconds sincemidnight GMT on 1st January, 1970. With the -ss option,
these are printed as strings for the local time zone; theformat can be altered with the -FF option, and with the -gg
option the times are in GMT. bbllkkssiizzee The number of bytes in one allocation block on the device on which the file resides. bblloocckk The number of disk blocks used by the file.lliinnkk If the file is a link and the -LL option is in effect,
this contains the name of the file linked to, otherwise it is empty. Note that if this element is selected(``ssttaatt ++lliinnkk'') then the -LL option is automatically
used.A particular element may be selected by including its name pre-
ceded by a `++' in the option list; only one element is allowed.The element may be shortened to any unique set of leading char-
acters. Otherwise, all elements will be shown for all files. Options:-AA array
Instead of displaying the results on standard output, assign them to an array, one ssttrruucctt ssttaatt element perarray element for each file in order. In this case nei-
ther the name of the element nor the name of the filesappears in array unless the -tt or -nn options were given,
respectively. If -tt is given, the element name appears
as a prefix to the appropriate array element; if -nn is
given, the file name appears as a separate array element preceding all the others. Other formatting options are respected.-HH hash
Similar to -AA, but instead assign the values to hash.
The keys are the elements listed above. If the -nn option
is provided then the name of the file is included in the hash with key nnaammee.-ff fd Use the file on file descriptor fd instead of named
files; no list of file names is allowed in this case.-FF fmt Supplies a ssttrrffttiimmee (see strftime(3)) string for the for-
matting of the time elements. The -ss option is implied.
-gg Show the time elements in the GMT time zone. The -ss
option is implied.-ll List the names of the type elements (to standard output
or an array as appropriate) and return immediately;options other than -AA and arguments are ignored.
-LL Perform an llssttaatt (see lstat(2)) rather than a ssttaatt system
call. In this case, if the file is a link, information about the link itself rather than the target file isreturned. This option is required to make the lliinnkk ele-
ment useful.-nn Always show the names of files. Usually these are only
shown when output is to standard output and there is more than one file in the list.-NN Never show the names of files.
-oo If a raw file mode is printed, show it in octal, which is
more useful for human consumption than the default of decimal. A leading zero will be printed in this case. Note that this does not affect whether a raw or formattedfile mode is shown, which is controlled by the -rr and -ss
options, nor whether a mode is shown at all.-rr Print raw data (the default format) alongside string data
(the -ss format); the string data appears in parentheses
after the raw data.-ss Print mmooddee, uuiidd, ggiidd and the three time elements as
strings instead of numbers. In each case the format islike that of llss -ll.
-tt Always show the type names for the elements of ssttrruucctt
ssttaatt. Usually these are only shown when output is to standard output and no individual element has been selected.-TT Never show the type names of the ssttrruucctt ssttaatt elements.
TTHHEE ZZSSHH//SSYYSSTTEEMM MMOODDUULLEE The zzsshh//ssyysstteemm module makes available three builtin commands and a parameter. BBUUIILLTTIINNSSssyysseerrrroorr [[ -ee errvar ]] [[ -pp prefix ]] [[ errno || errname ]]
This command prints out the error message associated with errno, a system error number, followed by a newline to standard error. Instead of the error number, a name errname, for example EENNOOEENNTT, may be used. The set of names is the same as the contents of the array eerrrrnnooss, see below. If the string prefix is given, it is printed in front of the error message, with no intervening space. If errvar is supplied, the entire message, without a newline, is assigned to the parameter names errvar and nothing is output. A return value of 0 indicates the message was successfully printed (although it may not be useful if the error number was out of the system's range), a return value of 1 indicates an error in the parameters, and a return value of 2 indicates the error name was not recognised (no message is printed for this).ssyyssrreeaadd [[ -cc countvar ]] [[ -ii infd ]] [[ -oo outfd ]]
[[ -ss bufsize ]] [[ -tt timeout ]] [[ param ]]
Perform a single system read from file descriptor infd, or zero if that is not given. The result of the read is stored in param or REPLY if that is not given. If countvar is given, the number of bytes read is assigned to the parameter named by countvar. The maximum number of bytes read is bufsize or 8192 if that is not given, however the command returns as soon as any number of bytes was successfully read. If timeout is given, it specifies a timeout in seconds, which may be zero to poll the file descriptor. This is handled by the ppoollll system call if available, otherwise the sseelleecctt system call if available. If outfd is given, an attempt is made to write all the bytes just read to the file descriptor outfd. If this fails, because of a system error other than EEIINNTTRR or because of an internal zsh error during an interrupt, the bytes read but not written are stored in the parameter named by param if supplied (no default is used in this case), and the number of bytes read but not written is stored in the parameter named by countvar if that issupplied. If it was successful, countvar contains the full num-
ber of bytes transferred, as usual, and param is not set. The error EEIINNTTRR (interrupted system call) is handled internally so that shell interrupts are transparent to the caller. Any other error causes a return. The possible return values are 0 At least one byte of data was successfully read and, if appropriate, written. 1 There was an error in the parameters to the command. This is the only error for which a message is printed to standard error. 2 There was an error on the read, or on polling the input file descriptor for a timeout. The parameter EERRRRNNOO gives the error.3 Data were successfully read, but there was an error writ-
ing them to outfd. The parameter EERRRRNNOO gives the error. 4 The attempt to read timed out. Note this does not set EERRRRNNOO as this is not a system error. 5 No system error occurred, but zero bytes were read. This usually indicates end of file. The parameters are set according to the usual rules; no write to outfd is attempted.ssyysswwrriittee [[ -cc countvar ]] [[ -oo outfd ]] data
The data (a single string of bytes) are written to the file descriptor outfd, or 1 if that is not given, using the wwrriittee system call. Multiple write operations may be used if the first does not write all the data. If countvar is given, the number of byte written is stored in the parameter named by countvar; this may not be the full length of data if an error occurred. The error EEIINNTTRR (interrupted system call) is handled internally by retrying; otherwise an error causes the command to return.For example, if the file descriptor is set to non-blocking out-
put, an error EEAAGGAAIINN (on some systems, EEWWOOUULLDDBBLLOOCCKK) may result in the command returning early. The return status may be 0 for success, 1 for an error in the parameters to the command, or 2 for an error on the write; no error message is printed in the last case, but the parameter EERRRRNNOO will reflect the error that occurred. PPAARRAAMMEETTEERRSS eerrrrnnooss A readonly array of the names of errors defined on the system. These are typically macros defined in C by including the system header file eerrrrnnoo..hh. The index of each name (assuming the option KKSSHHAARRRRAAYYSS is unset) corresponds to the error number. Error numbers num before the last known error which have no name are given the name EEnum in the array. Note that aliases for errors are not handled; only the canonical name is used. TTHHEE ZZSSHH//NNEETT//TTCCPP MMOODDUULLEE The zzsshh//nneett//ttccpp module makes available one builtin command:zzttccpp [ -aaccffllLLttvv ] [ -dd fd ] [ args ]
zzttccpp is implemented as a builtin to allow full use of shell com-
mand line editing, file I/O, and job control mechanisms. If zzttccpp is run with no options, it will output the contents of its session table.If it is run with only the option -LL, it will output the con-
tents of the session table in a format suitable for automatic parsing. The option is ignored if given with a command to open or close a session. The output consists of a set of lines, one per session, each containing the following elements separated by spaces: File descriptorThe file descriptor in use for the connection. For nor-
mal inbound (II) and outbound (OO) connections this may be read and written by the usual shell mechanisms. However,it should only be close with `zzttccpp -cc'.
Connection type A letter indicating how the session was created: ZZ A session created with the zzffttpp command.LL A connection opened for listening with `zzttccpp -ll'.
II An inbound connection accepted with `zzttccpp -aa'.
OO An outbound connection created with `zzttccpp host ...'. The local hostThis is usually set to an all-zero IP address as the
address of the localhost is irrelevant. The local port This is likely to be zero unless the connection is for listening. The remote host This is the fully qualified domain name of the peer, ifavailable, else an IP address. It is an all-zero IP
address for a session opened for listening. The remote port This is zero for a connection opened for listening. OOuuttbboouunndd CCoonnnneeccttiioonnsszzttccpp [ -vv ] [ -dd fd ] host [ port ]
Open a new TCP connection to host. If the port is omitted, it will default to port 23. The connection will be added to the session table and the shell parameter RREEPPLLYY will be set to the file descriptor associated with that connection.If -dd is specified, its argument will be taken as the target
file descriptor for the connection.In order to elicit more verbose output, use -vv.
IInnbboouunndd CCoonnnneeccttiioonnsszzttccpp -ll [ -vv ] [ -dd fd ] port
zzttccpp -ll will open a socket listening on TCP port. The socket
will be added to the session table and the shell parameter RREEPPLLYYwill be set to the file descriptor associated with that lis-
tener.If -dd is specified, its argument will be taken as the target
file descriptor for the connection.In order to elicit more verbose output, use -vv.
zzttccpp -aa [ -ttvv ] [ -dd targetfd ] listenfd
zzttccpp -aa will accept an incoming connection to the port associ-
ated with listenfd. The connection will be added to the session table and the shell parameter RREEPPLLYY will be set to the file descriptor associated with the inbound connection.If -dd is specified, its argument will be taken as the target
file descriptor for the connection.If -tt is specified, zzttccpp will return if no incoming connection
is pending. Otherwise it will wait for one.In order to elicit more verbose output, use -vv.
CClloossiinngg CCoonnnneeccttiioonnsszzttccpp -ccff [ -vv ] [ fd ]
zzttccpp -cc [ -vv ] [ fd ]
zzttccpp -cc will close the socket associated with fd. The socket
will be removed from the session table. If fd is not specified, zzttccpp will close everything in the session table.Normally, sockets registered by zftp (see zshmodules(1) ) cannot
be closed this way. In order to force such a socket closed, use-ff.
In order to elicit more verbose output, use -vv.
EExxaammppllee Here is how to create a TCP connection between two instances of zsh. We need to pick an unassigned port; here we use the randomly chosen 5123. On hhoosstt11, zzmmooddllooaadd zzsshh//nneett//ttccppzzttccpp -ll 55112233
lliisstteennffdd==$$RREEPPLLYY
zzttccpp -aa $$lliisstteennffdd
ffdd==$$RREEPPLLYY
The second from last command blocks until there is an incoming connec-
tion. Now create a connection from hhoosstt22 (which may, of course, be the same machine): zzmmooddllooaadd zzsshh//nneett//ttccpp zzttccpp hhoosstt11 55112233ffdd==$$RREEPPLLYY
Now on each host, $$ffdd contains a file descriptor for talking to the
other. For example, on hhoosstt11:pprriinntt TThhiiss iiss aa mmeessssaaggee >>&&$$ffdd
and on hhoosstt22:rreeaadd -rr lliinnee <<&&$$ffdd;; pprriinntt -rr - $$lliinnee
prints `TThhiiss iiss aa mmeessssaaggee'. To tidy up, on hhoosstt11:zzttccpp -cc $$lliisstteennffdd
zzttccpp -cc $$ffdd
and on hhoosstt22zzttccpp -cc $$ffdd
TTHHEE ZZSSHH//TTEERRMMCCAAPP MMOODDUULLEE The zzsshh//tteerrmmccaapp module makes available one builtin command: eecchhoottcc cap [ arg ... ] Output the termcap value corresponding to the capability cap, with optional arguments. The zzsshh//tteerrmmccaapp module makes available one parameter: tteerrmmccaapp An associative array that maps termcap capability codes to their values. TTHHEE ZZSSHH//TTEERRMMIINNFFOO MMOODDUULLEE The zzsshh//tteerrmmiinnffoo module makes available one builtin command: eecchhoottii cap [ arg ] Output the terminfo value corresponding to the capability cap, instantiated with arg if applicable. The zzsshh//tteerrmmiinnffoo module makes available one parameter: tteerrmmiinnffoo An associative array that maps terminfo capability names to their values. TTHHEE ZZSSHH//ZZFFTTPP MMOODDUULLEE The zzsshh//zzffttpp module makes available one builtin command: zzffttpp subcommand [ args ]The zzsshh//zzffttpp module is a client for FTP (file transfer proto-
col). It is implemented as a builtin to allow full use of shell command line editing, file I/O, and job control mechanisms. Often, users will access it via shell functions providing a more powerful interface; a set is provided with the zzsshh distribution and is described in zshzftpsys(1). However, the zzffttpp command is entirely usable in its own right. All commands consist of the command name zzffttpp followed by thename of a subcommand. These are listed below. The return sta-
tus of each subcommand is supposed to reflect the success orfailure of the remote operation. See a description of the vari-
able ZZFFTTPPVVEERRBBOOSSEE for more information on how responses from the server may be printed. SSuubbccoommmmaannddss ooppeenn host[::port] [ user [ password [ account ] ] ] Open a new FTP session to host, which may be the name of aTCP/IP connected host or an IP number in the standard dot nota-
tion. If the argument is in the form host::port, open a connec-
tion to TCP port port instead of the standard FTP port 21. Thismay be the name of a TCP service or a number: see the descrip-
tion of ZZFFTTPPPPOORRTT below for more information. If IPv6 addresses in colon format are used, the host should be surrounded by quoted square brackets to distinguish it from the port, for example ''[[ffee8800::::220033::bbaaffff::ffee0022::88bb5566]]''. For consistency this is allowed with all forms of host. Remaining arguments are passed to the llooggiinn subcommand. Note that if no arguments beyond host are supplied, ooppeenn will not automatically call llooggiinn. If no arguments at all are supplied, ooppeenn will use the parameters set by the ppaarraammss subcommand. After a successful open, the shell variables ZZFFTTPPHHOOSSTT,ZZFFTTPPPPOORRTT, ZZFFTTPPIIPP and ZZFFTTPPSSYYSSTTEEMM are available; see `Vari-
ables' below. llooggiinn [ name [ password [ account ] ] ] uusseerr [ name [ password [ account ] ] ] Login the user name with parameters password and account. Any of the parameters can be omitted, and will be read from standard input if needed (name is always needed). If standard input is a terminal, a prompt for each one will be printed on standard error and password will not be echoed. If any of the parameters are not used, a warning message is printed. After a successful login, the shell variables ZZFFTTPPUUSSEERR, ZZFFTTPPAACCCCOOUUNNTT and ZZFFTTPPPPWWDD are available; see `Variables' below.This command may be re-issued when a user is already logged in,
and the server will first be reinitialized for a new user. ppaarraammss [ host [ user [ password [ account ] ] ] ]ppaarraammss -
Store the given parameters for a later ooppeenn command with noarguments. Only those given on the command line will be remem-
bered. If no arguments are given, the parameters currently set are printed, although the password will appear as a line of stars; the return value is one if no parameters were set, zero otherwise. Any of the parameters may be specified as a `??', which may need to be quoted to protect it from shell expansion. In this case, the appropriate parameter will be read from stdin as with the llooggiinn subcommand, including special handling of password. If the `??' is followed by a string, that is used as the prompt forreading the parameter instead of the default message (any neces-
sary punctuation and whitespace should be included at the end of the prompt). The first letter of the parameter (only) may bequoted with a `\\'; hence an argument ""\\\\$$wwoorrdd"" guarantees that
the string from the shell parameter $$wwoorrdd will be treated liter-
ally, whether or not it begins with a `??'.If instead a single `-' is given, the existing parameters, if
any, are deleted. In that case, calling ooppeenn with no arguments will cause an error. The list of parameters is not deleted after a cclloossee, however it will be deleted if the zzsshh//zzffttpp module is unloaded. For example, zzffttpp ppaarraammss ffttpp..eellsseewwhheerree..xxxx jjuusseerr ''??PPaasssswwoorrdd ffoorr jjuusseerr:: '' will store the host ffttpp..eellsseewwhheerree..xxxx and the user jjuusseerr and then prompt the user for the corresponding password with the given prompt. tteesstt Test the connection; if the server has reported that it has closed the connection (maybe due to a timeout), return status 2; if no connection was open anyway, return status 1; else return status 0. The tteesstt subcommand is silent, apart from messagesprinted by the $$ZZFFTTPPVVEERRBBOOSSEE mechanism, or error messages if the
connection closes. There is no network overhead for this test. The test is only supported on systems with either the sseelleecctt((22)) or ppoollll((22)) system calls; otherwise the message `nnoott ssuuppppoorrtteedd oonn tthhiiss ssyysstteemm' is printed instead. The tteesstt subcommand will automatically be called at the start of any other subcommand for the current session when a connection is open. ccdd directory Change the remote directory to directory. Also alters the shell variable ZZFFTTPPPPWWDD. ccdduupp Change the remote directory to the one higher in the directorytree. Note that ccdd .... will also work correctly on non-UNIX sys-
tems. ddiirr [ args... ] Give a (verbose) listing of the remote directory. The args arepassed directly to the server. The command's behaviour is imple-
mentation dependent, but a UNIX server will typically interpret args as arguments to the llss command and with no arguments returnthe result of `llss -ll'. The directory is listed to standard out-
put. llss [ args ] Give a (short) listing of the remote directory. With no args, produces a raw list of the files in the directory, one per line. Otherwise, up to vagaries of the server implementation, behaves similar to ddiirr. ttyyppee [ type ] Change the type for the transfer to type, or print the current type if type is absent. The allowed values are `AA' (ASCII), `II' (Image, i.e. binary), or `BB' (a synonym for `II'). The FTP default for a transfer is ASCII. However, if zzffttpp findsthat the remote host is a UNIX machine with 8-bit byes, it will
automatically switch to using binary for file transfers upon ooppeenn. This can subsequently be overridden. The transfer type is only passed to the remote host when a data connection is established; this command involves no network overhead. aasscciiii The same as ttyyppee AA. bbiinnaarryy The same as ttyyppee II. mmooddee [ SS | BB ] Set the mode type to stream (SS) or block (BB). Stream mode is the default; block mode is not widely supported. rreemmoottee files... llooccaall [ files... ] Print the size and last modification time of the remote or local files. If there is more than one item on the list, the name of the file is printed first. The first number is the file size,the second is the last modification time of the file in the for-
mat CCCCYYYYMMMMDDDDhhhhmmmmSSSS consisting of year, month, date, hour, min-
utes and seconds in GMT. Note that this format, including thelength, is guaranteed, so that time strings can be directly com-
pared via the [[[[ builtin's << and >> operators, even if they are too long to be represented as integers.Not all servers support the commands for retrieving this infor-
mation. In that case, the rreemmoottee command will print nothing and return status 2, compared with status 1 for a file not found.The llooccaall command (but not rreemmoottee) may be used with no argu-
ments, in which case the information comes from examining file descriptor zero. This is the same file as seen by a ppuutt command with no further redirection. ggeett file [...]Retrieve all files from the server, concatenating them and send-
ing them to standard output. ppuutt file [...] For each file, read a file from standard input and send that to the remote host with the given name. aappppeenndd file [...] As ppuutt, but if the remote file already exists, data is appended to it instead of overwriting it. ggeettaatt file point ppuuttaatt file point aappppeennddaatt file point Versions of ggeett, ppuutt and aappppeenndd which will start the transfer atthe given point in the remote file. This is useful for append-
ing to an incomplete local file. However, note that this abil-
ity is not universally supported by servers (and is not quite the behaviour specified by the standard). ddeelleettee file [...] Delete the list of files on the server. mmkkddiirr directory Create a new directory directory on the server. rrmmddiirr directory Delete the directory directory on the server.rreennaammee old-name new-name
Rename file old-name to new-name on the server.
ssiittee args...Send a host-specific command to the server. You will probably
only need this if instructed by the server to use it. qquuoottee args... Send the raw FTP command sequence to the server. You should be familiar with the FTP command set as defined in RFC959 before doing this. Useful commands may include SSTTAATT and HHEELLPP. Note also the mechanism for returning messages as described for the variable ZZFFTTPPVVEERRBBOOSSEE below, in particular that all messages from the control connection are sent to standard error. cclloosseeqquuiitt Close the current data connection. This unsets the shell param-
eters ZZFFTTPPHHOOSSTT, ZZFFTTPPPPOORRTT, ZZFFTTPPIIPP, ZZFFTTPPSSYYSSTTEEMM, ZZFFTTPPUUSSEERR, ZZFFTTPPAACCCCOOUUNNTT, ZZFFTTPPPPWWDD, ZZFFTTPPTTYYPPEE and ZZFFTTPPMMOODDEE. sseessssiioonn [ sessname ] Allows multiple FTP sessions to be used at once. The name of the session is an arbitrary string of characters; the default session is called `ddeeffaauulltt'. If this command is called without an argument, it will list all the current sessions; with an argument, it will either switch to the existing session called sessname, or create a new session of that name. Each session remembers the status of the connection, the set ofconnection-specific shell parameters (the same set as are unset
when a connection closes, as given in the description of cclloossee), and any user parameters specified with the ppaarraammss subcommand. Changing to a previous session restores those values; changing to a new session initialises them in the same way as if zzffttpp had just been loaded. The name of the current session is given by the parameter ZZFFTTPPSSEESSSSIIOONN. rrmmsseessssiioonn [ sessname ] Delete a session; if a name is not given, the current session isdeleted. If the current session is deleted, the earliest exist-
ing session becomes the new current session, otherwise the cur-
rent session is not changed. If the session being deleted is the only one, a new session called `ddeeffaauulltt' is created and becomes the current session; note that this is a new session even if the session being deleted is also called `ddeeffaauulltt'. It is recommended that sessions not be deleted while background commands which use zzffttpp are still active. PPaarraammeetteerrss The following shell parameters are used by zzffttpp. Currently none of them are special. ZZFFTTPPTTMMOOUUTT Integer. The time in seconds to wait for a network operation to complete before returning an error. If this is not set when the module is loaded, it will be given the default value 60. A value of zero turns off timeouts. If a timeout occurs on the control connection it will be closed. Use a larger value if this occurs too frequently. ZZFFTTPPIIPPReadonly. The IP address of the current connection in dot nota-
tion. ZZFFTTPPHHOOSSTT Readonly. The hostname of the current remote server. If the host was opened as an IP number, ZZFFTTPPHHOOSSTT contains thatinstead; this saves the overhead for a name lookup, as IP num-
bers are most commonly used when a nameserver is unavailable. ZZFFTTPPPPOORRTTReadonly. The number of the remote TCP port to which the con-
nection is open (even if the port was originally specified as a named service). Usually this is the standard FTP port, 21.In the unlikely event that your system does not have the appro-
priate conversion functions, this appears in network byte order.If your system is little-endian, the port then consists of two
swapped bytes and the standard port will be reported as 5376. In that case, numeric ports passed to zzffttpp ooppeenn will also need to be in this format. ZZFFTTPPSSYYSSTTEEMM Readonly. The system type string returned by the server in response to an FTP SSYYSSTT request. The most interesting case is astring beginning ""UUNNIIXX TTyyppee:: LL88"", which ensures maximum compati-
bility with a local UNIX host. ZZFFTTPPTTYYPPEE Readonly. The type to be used for data transfers , either `AA' or `II'. Use the ttyyppee subcommand to change this. ZZFFTTPPUUSSEERR Readonly. The username currently logged in, if any. ZZFFTTPPAACCCCOOUUNNTT Readonly. The account name of the current user, if any. Most servers do not require an account name. ZZFFTTPPPPWWDD Readonly. The current directory on the server. ZZFFTTPPCCOODDEE Readonly. The three digit code of the last FTP reply from the server as a string. This can still be read after the connection is closed, and is not changed when the current session changes. ZZFFTTPPRREEPPLLYY Readonly. The last line of the last reply sent by the server. This can still be read after the connection is closed, and is not changed when the current session changes. ZZFFTTPPSSEESSSSIIOONNReadonly. The name of the current FTP session; see the descrip-
tion of the sseessssiioonn subcommand. ZZFFTTPPPPRREEFFSSA string of preferences for altering aspects of zzffttpp's behav-
iour. Each preference is a single character. The following are defined: PP Passive: attempt to make the remote server initiate data transfers. This is slightly more efficient than sendport mode. If the letter SS occurs later in the string, zzffttpp will use sendport mode if passive mode is not available. SS Sendport: initiate transfers by the FTP PPOORRTT command. If this occurs before any PP in the string, passive mode will never be attempted. DD Dumb: use only the bare minimum of FTP commands. This prevents the variables ZZFFTTPPSSYYSSTTEEMM and ZZFFTTPPPPWWDD from being set, and will mean all connections default to ASCII type. It may prevent ZZFFTTPPSSIIZZEE from being set during a transfer if the server does not send it anyway (many servers do). If ZZFFTTPPPPRREEFFSS is not set when zzffttpp is loaded, it will be set to a default of `PPSS', i.e. use passive mode if available, otherwise fall back to sendport mode. ZZFFTTPPVVEERRBBOOSSEE A string of digits between 0 and 5 inclusive, specifying which responses from the server should be printed. All responses go to standard error. If any of the numbers 1 to 5 appear in the string, raw responses from the server with reply codes beginning with that digit will be printed to standard error. The firstdigit of the three digit reply code is defined by RFC959 to cor-
respond to: 1. A positive preliminary reply. 2. A positive completion reply. 3. A positive intermediate reply. 4. A transient negative completion reply. 5. A permanent negative completion reply. It should be noted that, for unknown reasons, the reply `Service not available', which forces termination of a connection, is classified as 421, i.e. `transient negative', an interesting interpretation of the word `transient'. The code 0 is special: it indicates that all but the last line of multiline replies read from the server will be printed to standard error in a processed format. By convention, servers use this mechanism for sending information for the user to read. The appropriate reply code, if it matches the same response, takes priority. If ZZFFTTPPVVEERRBBOOSSEE is not set when zzffttpp is loaded, it will be set to the default value 445500, i.e., messages destined for the user and all errors will be printed. A null string is valid and specifies that no messages should be printed. FFuunnccttiioonnss zzffttppcchhppwwdd If this function is set by the user, it is called every time the directory changes on the server, including when a user is loggedin, or when a connection is closed. In the last case, $$ZZFFTTPPPPWWDD
will be unset; otherwise it will reflect the new directory. zzffttpppprrooggrreessss If this function is set by the user, it will be called during a ggeett, ppuutt or aappppeenndd operation each time sufficient data has beenreceived from the host. During a ggeett, the data is sent to stan-
dard output, so it is vital that this function should write tostandard error or directly to the terminal, not to standard out-
put. When it is called with a transfer in progress, the following additional shell parameters are set: ZZFFTTPPFFIILLEE The name of the remote file being transferred from or to. ZZFFTTPPTTRRAANNSSFFEERR A GG for a ggeett operation and a PP for a ppuutt operation. ZZFFTTPPSSIIZZEE The total size of the complete file being transferred: the same as the first value provided by the rreemmoottee and llooccaall subcommands for a particular file. If the server cannot supply this value for a remote file being retrieved, it will not be set. If input is from a pipe the value may be incorrect and correspond simply to a full pipe buffer. ZZFFTTPPCCOOUUNNTT The amount of data so far transferred; a number betweenzero and $$ZZFFTTPPSSIIZZEE, if that is set. This number is
always available.The function is initially called with ZZFFTTPPTTRRAANNSSFFEERR set appro-
priately and ZZFFTTPPCCOOUUNNTT set to zero. After the transfer is fin-
ished, the function will be called one more time with ZZFFTTPPTTRRAANNSSFFEERR set to GGFF or PPFF, in case it wishes to tidy up. It is otherwise never called twice with the same value of ZZFFTTPPCCOOUUNNTT. Sometimes the progress meter may cause disruption. It is up to the user to decide whether the function should be defined and to use uunnffuunnccttiioonn when necessary. PPrroobblleemmss A connection may not be opened in the left hand side of a pipe as this occurs in a subshell and the file information is not updated in themain shell. In the case of type or mode changes or closing the connec-
tion in a subshell, the information is returned but variables are not updated until the next call to zzffttpp. Other status changes in subshellswill not be reflected by changes to the variables (but should be other-
wise harmless). Deleting sessions while a zzffttpp command is active in the background can have unexpected effects, even if it does not use the session being deleted. This is because all shell subprocesses share information onthe state of all connections, and deleting a session changes the order-
ing of that information. On some operating systems, the control connection is not valid after a fork(), so that operations in subshells, on the left hand side of a pipeline, or in the background are not possible, as they should be. This is presumably a bug in the operating system. TTHHEE ZZSSHH//ZZLLEE MMOODDUULLEE The zzsshh//zzllee module contains the Zsh Line Editor. See zshzle(1). TTHHEE ZZSSHH//ZZLLEEPPAARRAAMMEETTEERR MMOODDUULLEE The zzsshh//zzlleeppaarraammeetteerr module defines two special parameters that can beused to access internal information of the Zsh Line Editor (see zsh-
zle(1)). kkeeyymmaappss This array contains the names of the keymaps currently defined. wwiiddggeettss This associative array contains one entry per widget defined.The name of the widget is the key and the value gives informa-
tion about the widget. It is either the string `bbuuiillttiinn' for builtin widgets, a string of the form `uusseerr::name' foruser-defined widgets, where name is the name of the shell func-
tion implementing the widget, or it is a string of the form `ccoommpplleettiioonn::type::name', for completion widgets. In the last case type is the name of the builtin widgets the completion widgetimitates in its behavior and name is the name of the shell func-
tion implementing the completion widget. TTHHEE ZZSSHH//ZZPPRROOFF MMOODDUULLEE When loaded, the zzsshh//zzpprrooff causes shell functions to be profiled. The profiling results can be obtained with the zzpprrooff builtin command made available by this module. There is no way to turn profiling off other than unloading the module.zzpprrooff [ -cc ]
Without the -cc option, zzpprrooff lists profiling results to standard
output. The format is comparable to that of commands like ggpprrooff. At the top there is a summary listing all functions that were called at least once. This summary is sorted in decreasing order of the amount of time spent in each. The lines contain the number of the function in order, which is used in other parts of the list in suffixes of the form `[[num]]'.RE, then the number of calls made to the function. The next three columns list the time in milliseconds spent in the function and itsdescendents, the average time in milliseconds spent in the func-
tion and its descendents per call and the percentage of time spent in all shell functions used in this function and itsdescendents. The following three columns give the same informa-
tion, but counting only the time spent in the function itself. The final column shows the name of the function. After the summary, detailed information about every function that was invoked is listed, sorted in decreasing order of the amount of time spent in each function and its descendents. Each of these entries consists of descriptions for the functions that called the function described, the function itself, and the functions that were called from it. The description for the function itself has the same format as in the summary (and shows the same information). The other lines don't show the number of the function at the beginning and have their function named indented to make it easier to distinguish the line showing the function described in the section from the surrounding lines. The information shown in this case is almost the same as in the summary, but only refers to the call hierarchy being displayed. For example, for a calling function the column showing the total running time lists the time spent in the described function and its descendents only for the times when it was called from that particular calling function. Likewise, for a called function, this columns lists the total time spent in the called function and its descendents only for the times when it was called from the function described. Also in this case, the column showing the number of calls to afunction also shows a slash and then the total number of invoca-
tions made to the called function. As long as the zzsshh//zzpprrooff module is loaded, profiling will be done and multiple invocations of the zzpprrooff builtin command will show the times and numbers of calls since the module was loaded.With the -cc option, the zzpprrooff builtin command will reset its
internal counters and will not show the listing. ) TTHHEE ZZSSHH//ZZPPTTYY MMOODDUULLEE The zzsshh//zzppttyy module offers one builtin:zzppttyy [ -ee ] [ -bb ] name [ arg ... ]
The arguments following name are concatenated with spaces between, then executed as a command, as if passed to the eevvaallbuiltin. The command runs under a newly assigned pseudo-termi-
nal; this is useful for running commands non-interactively which
expect an interactive environment. The name is not part of the command, but is used to refer to this command in later calls to zzppttyy.With the -ee option, the pseudo-terminal is set up so that input
characters are echoed.With the -bb option, input to and output from the pseudo-terminal
are made non-blocking.
zzppttyy -dd [ names ... ]
The second form, with the -dd option, is used to delete commands
previously started, by supplying a list of their names. If no names are given, all commands are deleted. Deleting a command causes the HUP signal to be sent to the corresponding process.zzppttyy -ww [ -nn ] name [ strings ... ]
The -ww option can be used to send the to command name the given
strings as input (separated by spaces). If the -nn option is not
given, a newline is added at the end. If no strings are provided, the standard input is copied to thepseudo-terminal; this may stop before copying the full input if
the pseudo-terminal is non-blocking.
Note that the command under the pseudo-terminal sees this input
as if it were typed, so beware when sending special tty drivercharacters such as word-erase, line-kill, and end-of-file.
zzppttyy -rr [ -tt ] name [ param [ pattern ] ]
The -rr option can be used to read the output of the command
name. With only a name argument, the output read is copied tothe standard output. Unless the pseudo-terminal is non-block-
ing, copying continues until the command under the pseudo-termi-
nal exits; when non-blocking, only as much output as is immedi-
ately available is copied. The return value is zero if any out-
put is copied. When also given a param argument, at most one line is read and stored in the parameter named param. Less than a full line maybe read if the pseudo-terminal is non-blocking. The return
value is zero if at least one character is stored in param. If a pattern is given as well, output is read until the wholestring read matches the pattern, even in the non-blocking case.
The return value is zero if the string read matches the pattern, or if the command has exited but at least one character could still be read. As of this writing, a maximum of one megabyte of output can be consumed this way; if a full megabyte is readwithout matching the pattern, the return value is non-zero.
In all cases, the return value is non-zero if nothing could be
read, and is 22 if this is because the command has finished.If the -rr option is combined with the -tt option, zzppttyy tests
whether output is available before trying to read. If no output is available, zzppttyy immediately returns the value 11.zzppttyy -tt name
The -tt option without the -rr option can be used to test whether
the command name is still running. It returns a zero value ifthe command is running and a non-zero value otherwise.
zzppttyy [ -LL ]
The last form, without any arguments, is used to list the com-
mands currently defined. If the -LL option is given, this is
done in the form of calls to the zzppttyy builtin. TTHHEE ZZSSHH//ZZSSEELLEECCTT MMOODDUULLEE The zzsshh//zzsseelleecctt module makes available one builtin command:zzsseelleecctt [ -rrwwee -tt timeout -aa array ] [ fd ... ]
The zzsseelleecctt builtin is a front-end to the `select' system call,
which blocks until a file descriptor is ready for reading or writing, or has an error condition, with an optional timeout. If this is not available on your system, the command prints an error message and returns status 2 (normal errors return status 1). For more information, see your systems documentation for select(3). Note there is no connection with the shell builtin of the same name. Arguments and options may be intermingled in any order.Non-option arguments are file descriptors, which must be decimal
integers. By default, file descriptors are to be tested for reading, i.e. zzsseelleecctt will return when data is available to be read from the file descriptor, or more precisely, when a readoperation from the file descriptor will not block. After a -rr,
-ww and -ee, the given file descriptors are to be tested for read-
ing, writing, or error conditions. These options and an arbi-
trary list of file descriptors may be given in any order. (The presence of an `error condition' is not well defined in the documentation for many implementations of the select system call. According to recent versions of the POSIX specification, it is really an exception condition, of which the only standardexample is out-of-band data received on a socket. So zsh users
are unlikely to find the -ee option useful.)
The option `-tt timeout' specifies a timeout in hundredths of a
second. This may be zero, in which case the file descriptors will simply be polled and zzsseelleecctt will return immediately. It is possible to call zselect with no file descriptors and anon-zero timeout for use as a finer-grained replacement for
`sleep'; not, however, the return status is always 1 for a time-
out.The option `-aa array' indicates that aarrrraayy should be set to
indicate the file descriptor(s) which are ready. If the option is not given, the array rreeppllyy will be used for this purpose. The array will contain a string similar to the arguments for zzsseelleecctt. For example,zzsseelleecctt -tt 00 -rr 00 -ww 11
might return immediately with status 0 and $$rreeppllyy containing `-rr
00 -ww 11' to show that both file descriptors are ready for the
requested operations.The option `-AA assoc' indicates that the associative array aassssoocc
should be set to indicate the file descriptor(s) which areready. This option overrides the option -aa, nor will rreeppllyy be
modified. The keys of aassssoocc are the file descriptors, and the corresponding values are any of the characters `rrwwee' to indicate the condition. The command returns 0 if some file descriptors are ready for reading. If the operation timed out, or a timeout of 0 was given and no file descriptors were ready, or there was an error, it returns status 1 and the array will not be set (nor modified in any way). If there was an error in the select operation the appropriate error message is printed. TTHHEE ZZSSHH//ZZUUTTIILL MMOODDUULLEE The zzsshh//zzuuttiill module only adds some builtins:zzssttyyllee [ -LL ]
zzssttyyllee [ -ee | - | -- ] pattern style strings ...
zzssttyyllee -dd [ pattern [ styles ... ] ]
zzssttyyllee -gg name [ pattern [ style ] ]
zzssttyyllee -aabbss context style name [ sep ]
zzssttyyllee -TTtt context style [ strings ...]
zzssttyyllee -mm context style pattern
This builtin command is used to define and lookup styles. Styles are pairs of names and values, where the values consistof any number of strings. They are stored together with pat-
terns and lookup is done by giving a string, called the `con-
text', which is compared to the patterns. The definition stored for the first matching pattern will be returned. For ordering of comparisons, patterns are searched from mostspecific to least specific, and patterns that are equally spe-
cific keep the order in which they were defined. A pattern is considered to be more specific than another if it contains more components (substrings separated by colons) or if the patterns for the components are more specific, where simple strings areconsidered to be more specific than patterns and complex pat-
terns are considered to be more specific than the pattern `**'. The first form (without arguments) lists the definitions in theorder zzssttyyllee will test them. If the -LL option is given, listing
is done in the form of calls to zzssttyyllee. Forms with arguments:zzssttyyllee [ - | -- | -ee ] pattern style strings ...
Defines the given style for the pattern with the stringsas the value. If the -ee option is given, the strings
will be concatenated (separated by spaces) and the resulting string will be evaluated (in the same way as it is done by the eevvaall builtin command) when the style is looked up. In this case the parameter `rreeppllyy' must beassigned to set the strings returned after the evalua-
tion. Before evaluating the value, rreeppllyy is unset, and if it is still unset after the evaluation, the style is treated as if it were not set.zzssttyyllee -dd [ pattern [ styles ... ] ]
Delete style definitions. Without arguments all defini-
tions are deleted, with a pattern all definitions for that pattern are deleted and if any styles are given, then only those styles are deleted for the pattern.zzssttyyllee -gg name [ pattern [ style ] ]
Retrieve a style definition. The name is used as the name of an array in which the results are stored. Without any further arguments, all patterns defined are returned. With a pattern the styles defined for that pattern are returned and with both a pattern and a style, the value strings of that combination is returned. The other forms can be used to look up or test patterns.zzssttyyllee -ss context style name [ sep ]
The parameter name is set to the value of the style interpreted as a string. If the value contains several strings they are concatenated with spaces (or with the sep string if that is given) between them.zzssttyyllee -bb context style name
The value is stored in name as a boolean, i.e. as the string `yyeess' if the value has only one string and that string is equal to one of `yyeess', `ttrruuee', `oonn', or `11'. If the value is any other string or has more than one string, the parameter is set to `nnoo'.zzssttyyllee -aa context style name
The value is stored in name as an array. If name is declared as an associative array, the first, third, etc. strings are used as the keys and the other strings are used as the values.zzssttyyllee -tt context style [ strings ...]
zzssttyyllee -TT context style [ strings ...]
Test the value of a style, i.e. the -tt option only
returns a status (sets $$??). Without any strings the
return status is zero if the style is defined for at least one matching pattern, has only one string in its value, and that is equal to one of `ttrruuee', `yyeess', `oonn' or `11'. If any strings are given the status is zero if and only if at least one of the strings is equal to at least one of the strings in the value. If the style is not defined, the status is 22.The -TT option tests the values of the style like -tt, but
it returns zero (rather than 22) if the style is not defined for any matching pattern.zzssttyyllee -mm context style pattern
Match a value. Returns status zero if the pattern matches at least one of the strings in the value.zzffoorrmmaatt -ff param format specs ...
zzffoorrmmaatt -aa array sep specs ...
This builtin provides two different forms of formatting. Thefirst form is selected with the -ff option. In this case the for-
mat string will be modified by replacing sequences starting with a percent sign in it with strings from the specs. Each spec should be of the form `char::string' which will cause everyappearance of the sequence `%%char' in format to be replaced by
the string. The `%%' sequence may also contain optional minimum
and maximum field width specifications between the `%%' and the
`char' in the form `%%min..maxcc', i.e. the minimum field width is
given first and if the maximum field width is used, it has to be preceded by a dot. Specifying a minimum field width makes the result be padded with spaces to the right if the string is shorter than the requested width. Padding to the left can be achieved by giving a negative minimum field width. If a maximum field width is specified, the string will be truncated afterthat many characters. After all `%%' sequences for the given
specs have been processed, the resulting string is stored in the parameter param.The %%-escapes also understand ternary expressions in the form
used by prompts. The %% is followed by a `((' and then an ordi-
nary format specifier character as described above. There may be a set of digits either before or after the `(('; these specify a test number, which defaults to zero. Negative numbers arealso allowed. An arbitrary delimiter character follows the for-
mat specifier, which is followed by a piece of `true' text, thedelimiter character again, a piece of `false' text, and a clos-
ing parenthesis. The complete expression (without the digits)thus looks like `%%((X..text1..text2))', except that the `..' charac-
ter is arbitrary. The value given for the format specifier in the char::string expressions is evaluated as a mathematical expression, and compared with the test number. If they are the same, text1 is output, else text2 is output. A parenthesis maybe escaped in text2 as %%)). Either of text1 or text2 may contain
nested %%-escapes.
For example:zformat f REPLY "The answer is '%3(c.yes.no)'." c:3
outputs "The answer is 'yes'." to RREEPPLLYY since the value for the format specifier cc is 3, agreeing with the digit argument to the ternary expression.The second form, using the -aa option, can be used for aligning
strings. Here, the specs are of the form `left::right' where `left' and `right' are arbitrary strings. These strings are modified by replacing the colons by the sep string and padding the left strings with spaces to the right so that the sep strings in the result (and hence the right strings after them) are all aligned if the strings are printed below each other. All strings without a colon are left unchanged and all strings with an empty right string have the trailing colon removed. In both cases the lengths of the strings are not used to determine how the other strings are to be aligned. The resulting strings are stored in the array. zzrreeggeexxppaarrssee This implements some internals of the rreeggeexxaarrgguummeennttss function.zzppaarrsseeooppttss [ -DD ] [ -KK ] [ -EE ] [ -aa array ] [ -AA assoc ] specs
This builtin simplifies the parsing of options in positionalparameters, i.e. the set of arguments given by $$**. Each spec
describes one option and must be of the form `opt[==array]'. If an option described by opt is found in the positional parametersit is copied into the array specified with the -aa option; if the
optional `==array' is given, it is instead copied into that array. Note that it is an error to give any spec without an `==array'unless one of the -aa or -AA options is used.
Unless the -EE option is given, parsing stops at the first string
that isn't described by one of the specs. Even with -EE, parsing
always stops at a positional parameter equal to `-' or `--'.
The opt description must be one of the following. Any of the special characters can appear in the option name provided it is preceded by a backslash. name name++ The name is the name of the option without the leading`-'. To specify a GNU-style long option, one of the
usual two leading `-' must be included in name; for exam-
ple, a `--ffiillee' option is represented by a name of
`-ffiillee'.
If a `++' appears after name, the option is appended to array each time it is found in the positional parameters; without the `++' only the last occurrence of the option is preserved.If one of these forms is used, the option takes no argu-
ment, so parsing stops if the next positional parameterdoes not also begin with `-' (unless the -EE option is
used). name::name::-
name:::: If one or two colons are given, the option takes an argu-
ment; with one colon, the argument is mandatory and with two colons it is optional. The argument is appended to the array after the option itself. An optional argument is put into the same array element as the option name (note that this makes empty strings as arguments indistinguishable). A mandatory argument isadded as a separate element unless the `::-' form is used,
in which case the argument is put into the same element. A `++' as described above may appear between the name and the first colon. The options of zzppaarrsseeooppttss itself are:-aa array
As described above, this names the default array in which to store the recognised options.-AA assoc
If this is given, the options and their values are also put intoan associative array with the option names as keys and the argu-
ments (if any) as the values.-DD If this option is given, all options found are removed from the
positional parameters of the calling shell or shell function, up to but not including any not described by the specs. This is similar to using the sshhiifftt builtin.-KK With this option, the arrays specified with the -aa and -AA
options and with the `==array' forms are kept unchanged when none of the specs for them is used. This allows assignment of default values to them before calling zzppaarrsseeooppttss.-EE This changes the parsing rules to not stop at the first string
that isn't described by one of the specs. It can be used totest for or (if used together with -DD) extract options and their
arguments, ignoring all other options and arguments that may be in the positional parameters. For example,sseett -- -aa -bbxx -cc yy -cczz bbaazz -cceenndd
zzppaarrsseeooppttss aa==ffoooo bb::==bbaarr cc++::==bbaarr will have the effect offfoooo==((-aa))
bbaarr==((-bb xx -cc yy -cc zz))
The arguments from `bbaazz' on will not be used.As an example for the -EE option, consider:
sseett -- -aa xx -bb yy -cc zz aarrgg11 aarrgg22
zzppaarrsseeooppttss -EE -DD bb::==bbaarr
will have the effect ofbbaarr==((-bb yy))
sseett -- -aa xx -cc zz aarrgg11 aarrgg22
I.e., the option -bb and its arguments are taken from the positional
parameters and put into the array bbaarr. zsh 4.2.3 January 13, 2005 ZSHMODULES(1)