Go to the first, previous, next, last section, table of contents.


Zsh 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 available are:

cap
Builtins for manipulating POSIX.1e (POSIX.6) capability (privilege) sets.
clone
A builtin that can clone a running shell onto another terminal.
comp1
Base of the completion system. Used by the compctl and zle modules.
compctl
The compctl builtin for controlling completion.
deltochar
A ZLE function duplicating EMACS' zap-to-char.
example
An example of how to write a module.
files
Some basic file manipulation commands as builtins.
sched
A builtin that provides a timed execution facility within the shell.
stat
A builtin command interface to the stat system call.
zle
The Zsh Line Editor, including the bindkey and vared builtins.

The cap Module

The cap module is used for manipulating POSIX.1e (POSIX.6) capability 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:

cap [ capabilities ]
Change the shell's process capability sets to the specified capabilities, otherwise display the shell's current capabilities.
getcap filename ...
This is a built-in implementation of the POSIX standard utility. It displays the capability sets on each specified filename.
setcap 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.

The clone Module

The clone module makes available one builtin command:

clone tty
Creates a forked instance of the current shell, attached to the specified tty. In the new shell, the PID, PPID and TTY special parameters 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 successful, and non-zero on error.

The comp1 Module

The comp1 module does nothing that is visible to the user. Its purpose is to provide the internal basis of the programmable completion mechanism.

This module must be loaded before any module that provides a means of controlling completion (such as the compctl module), or that uses completions (such as the zle module). This is done automatically for modules distributed with zsh, and for other modules can be effected by the use of zmodload -d.

The compctl Module

The compctl module makes available one builtin command, compctl, which is the standard way to control completions for ZLE. See section Programmable Completion.

The deltochar Module

The deltochar module makes available one ZLE function:

delete-to-char
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.

The example Module

The example module makes available one builtin command:

example [ -flags ] [ 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 files Module

The files module makes some standard commands available as builtins:

ln [ -dfis ] filename dest
ln [ -dfis ] filename ... dir
Creates hard (or, with -s, 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, ln will not attempt to create hard links to directories. This check can be overridden using the -d option. Typically 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 -i option causes the user to be queried about replacing existing files. The -f option causes existing files to be silently deleted, without querying. -f takes precedence.
mkdir [ -p ] [ -m mode ] dir ...
Creates directories. With the -p option, non-existing parent directories are first created if necessary, and there will be no complaint if the directory already exists. The -m option can be used to specify (in octal) a set of file permissions for the created directories, otherwise mode 777 modified by the current umask (see man page umask(2)) is used.
mv [ -fi ] filename dest
mv [ -fi ] filename ... dir
Moves files. In the first form, the specified filename is moved to the specified destination. In the second form, each of the filenames is taken in turn, and moved to a pathname in the specified 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 be silently removed. The -i option causes the user to be queried about replacing any existing files. The -f option causes any existing files to be silently deleted, without querying. -f takes precedence. Note that this mv will not move files across devices. Historical versions of mv, when actual renaming is impossible, fall back on copying and removing files; if this behaviour is desired, use cp and rm manually. This may change in a future version.
rm [ -dfirs ] filename ...
Removes files and directories specified. Normally, rm will not remove directories (except with the -r option). The -d option causes rm to try removing directories with unlink (see man page unlink(2)), the same method used for files. Typically only the super-user can actually succeed in unlinking directories in this way. -d takes precedence over -r. By default, the user will be queried before removing any file that the user cannot write to, but writable files will be silently removed. The -i option causes the user to be queried about removing any files. The -f option causes files to be silently deleted, without querying, and suppresses all error indications. -f takes precedence. The -r option causes rm to recursively descend into directories, deleting all files in the directory before removing the directory with the rmdir system call (see man page rmdir(2)). The -s option is a zsh extension to rm functionality. It enables paranoid behaviour, intended to avoid common security problems involving a root-run rm being tricked into removing files other than the ones intended. It will refuse to follow symbolic links, so that (for example) "rm /tmp/foo/passwd'' can't accidentally remove /etc/passwd if /tmp/foo happens to be a link to /etc. 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 /usr as a result of directories being moved up the tree.
rmdir dir ...
Removes empty directories specified.
sync
Calls the system call of the same name (see man page sync(2)), which flushes dirty buffers to disk. It might return before the I/O has actually been completed.

The sched Module

The sched module makes available one builtin command:

sched [+]hh:mm command ...
sched [ -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 the argument `-item', removes the given item from the list.

The stat Module

The stat module makes available one builtin command:

stat [ -gnNlLtTrs ] [ -f fd ] [ -A array ] [ -F fmt ] [ +element ] [ file ... ]
The command acts as a front end to the stat system call (see man page stat(2)). If the stat call fails, the appropriate system error message printed and status 1 is returned. The fields of struct stat give information about the files provided as arguments to the command. In addition to those available from the stat call, an extra element `link' is provided. These elements are:
device
The number of the device on which the file resides.
inode
The unique number of the file on this device (`inode' number).
mode
The mode of the file; that is, the file's type and access permissions. With the -s option, this will be returned as a string corresponding to the first column in the display of the ls -l command.
nlink
The number of hard links to the file.
uid
The user ID of the owner of the file. With the -s option, this is displayed as a user name.
gid
The group ID of the file. With the -s option, this is displayed as a group name.
rdev
The raw device number. This is only useful for special devices.
size
The size of the file in bytes.
atime
mtime
ctime
The last access, modification and inode change times of the file, respectively, as the number of seconds since midnight GMT on 1st January, 1970. With the -s option, these are printed as strings for the local time zone; the format can be altered with the -F option, and with the -g option the times are in GMT.
blksize
The number of bytes in one allocation block on the device on which the file resides.
block
The number of disk blocks used by the file.
link
If the file is a link and the -L option is in effect, this contains the name of the file linked to, otherwise it is empty. Note that if this element is selected ("stat +link'') then the -L option is automatically used.
A particular element may be selected by including its name preceded by a `+' in the option list; only one element is allowed. The element may be shortened to any unique set of leading characters. Otherwise, all elements will be shown for all files. Options:
-A array
Instead of displaying the results on standard output, assign them to an array, one struct stat element per array element for each file in order. In this case neither the name of the element nor the name of the files is provided unless the -t or -n options are provided, respectively. In the former case the element name appears as a prefix to the appropriate array element and in the latter case the file name appears as a separate array element preceding all the others. Other formatting options are respected.
-f fd
Use the file on file descriptor fd instead of named files; no list of file names is allowed in this case.
-F fmt
Supplies a strftime (see man page strftime(3)) string for the formatting of the time elements. The -s option is implied.
-g
Show the time elements in the GMT time zone. The -s option is implied.
-l
List the names of the type elements (to standard output or an array as appropriate) and return immediately; options other than -A and arguments are ignored.
-L
Perform an lstat (see man page lstat(2)) rather than a stat system call. In this case, if the file is a link, information about the link itself rather than the target file is returned. This option is required to make the link element useful.
-n
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.
-N
Never show the names of files.
-r
Print raw data (the default format) alongside string data (the -s format); the string data appears in parentheses after the raw data.
-s
Print mode, uid, gid and the three time elements as strings instead of numbers. In each case the format is like that of ls -l.
-t
Always show the type names for the elements of struct stat. Usually these are only shown when output is to standard output and no individual element has been selected.
-T
Never show the type names of the struct stat elements.

The zle Module

The zle module contains the Zsh Line Editor. See section Zsh Line Editor. It also contains three related builtin commands:

bindkey [ options ] -l
bindkey [ options ] -d
bindkey [ options ] -D keymap ...
bindkey [ options ] -A old-keymap new-keymap
bindkey [ options ] -N new-keymap [ old-keymap ]
bindkey [ options ] -m
bindkey [ options ] -r in-string ...
bindkey [ options ] -s in-string out-string ...
bindkey [ options ] in-string command ...
bindkey [ options ] [ in-string ]
bindkey's options can be divided into three categories: keymap selection, operation selection, and others. The keymap selection options are:
-e
Selects keymap `emacs', and also links it to `main'.
-v
Selects keymap `viins', and also links it to `main'.
-a
Selects keymap `vicmd'.
-M
The first non-option argument is used as a keymap name, and does not otherwise count as an argument.
Some operations do not permit a keymap to be selected. If a keymap selection is required and none of the options above are used, the `main' keymap is used. These operations do not permit a keymap to be selected:
-l
List all existing keymap names. If the -L option is used, list in the form of bindkey commands to create the keymaps.
-d
Delete all existing keymaps and reset to the default state.
-D keymap ...
Delete the named keymaps.
-A old-keymap new-keymap
Make the new-keymap name an alias for old-keymap, so that both names refer to the same keymap. The names have equal standing; if either is deleted, the other remains. If there is already a keymap with the new-keymap name, it is deleted.
-N new-keymap [ old-keymap ]
Create a new keymap, named new-keymap. If a keymap already has that name, it is deleted. If an old-keymap name is given, the new keymap is initialised to be a duplicate of it, otherwise the new keymap will be empty.
The following operations require a keymap to be selected:
-m
Add the built-in set of meta-key bindings to the selected keymap. Only keys that are unbound or bound to self-insert are affected.
-r in-string ...
Unbind the specified in-strings in the selected keymap. This is exactly equivalent to binding the strings to undefined-key.
-s in-string out-string ...
Bind each in-string to each out-string. When in-string is typed, out-string will be pushed back and treated as input to the line editor.
in-string command ...
Bind each in-string to each command.
[ in-string ]
List key bindings. If an in-string is specified, the binding of that string in the selected keymap is displayed. Otherwise, all key bindings in the selected keymap are displayed. As an exception, if the -e or -v options are used alone, the keymap is not displayed - the implicit linking of keymaps is the only thing that happens.
In the binding operations, if the -R option is used, the in-strings are interpreted as ranges, instead of plain strings. A valid range consists of two characters, with an optional `-' between them. All characters between the two specified, inclusive, are bound as specified. For either in-string or out-string, the following escape sequences are recognised:
\a
bell character
\b
backspace
\e, \E
escape
\f
form feed
\n
linefeed (newline)
\r
carriage return
\t
horizontal tab
\v
vertical tab
\NNN
character code in octal
\xNN
character code in hexadecimal
\M[-]X
character with meta bit set
\C[-]X
control character
^X
control character
In all other cases, `\' escapes the following character. Delete is written as `^?'. Note that `\M^?' and `^\M?' are not the same.
vared [ -ch ] [ -p prompt ] [ -r rprompt ] name
The value of the parameter name is loaded into the edit buffer, and the line editor is invoked. When the editor exits, name is set to the string value returned by the editor. If the -c flag is given, the parameter is created if it doesn't already exist. If the -p flag is given, the following string will be taken as the prompt to display at the left. If the -r flag is given, the following string gives the prompt to display at the right. If the -h flag is specified, the history can be accessed from ZLE.
zle -l [ -L ]
zle -D widget ...
zle -A old-widget new-widget
zle -N widget [ function ]
zle widget
The zle builtin performs a number of different actions concerning ZLE. Which operation it performs depends on its options:
-l [ -L ]
List all existing user-defined widgets. If the -L option is used, list in the form of zle commands to create the widgets. Built-in widgets are not listed.
-D widget ...
Delete the named widgets.
-A old-widget new-widget
Make the new-widget name an alias for old-widget, so that both names refer to the same widget. The names have equal standing; if either is deleted, the other remains. If there is already a widget with the new-widget name, it is deleted.
-N widget [ function ]
Create a user-defined widget. If there is already a widget with the specified name, it is overwritten. When the new widget is invoked from within the editor, the specified shell function is called. If no function name is specified, it defaults to the same name as the widget.
widget
Invoke the specified widget. This can only be done when ZLE is active; normally this will be within a user-defined widget.


Go to the first, previous, next, last section, table of contents.