22.19 The zsh/newuser Module

The zsh/newuser module is loaded at boot if it is available, the RCS option is set, and the PRIVILEGED option is not set (all three are true by default). This takes place immediately after commands in the global zshenv file (typically /etc/zshenv), if any, have been executed. If the module is not available it is silently ignored by the shell; the module may safely be removed from $MODULE_PATH by the administrator if it is not required.

On loading, the module tests if any of the start-up files .zshenv, .zprofile, .zshrc or .zlogin exist in the directory given by the environment variable ZDOTDIR, or the user’s home directory if that is not set. The test is not performed and the module halts processing if the shell was in an emulation mode (i.e. had been invoked as some other shell than zsh).

If none of the start-up files were found, the module then looks for the file newuser first in a sitewide directory, usually the parent directory of the site-functions directory, and if that is not found the module searches in a version-specific directory, usually the parent of the functions directory containing version-specific functions. (These directories can be configured when zsh is built using the --enable-site-scriptdir=dir and --enable-scriptdir=dir flags to configure, respectively; the defaults are prefix/share/zsh and prefix/share/zsh/$ZSH_VERSION where the default prefix is /usr/local.)

If the file newuser is found, it is then sourced in the same manner as a start-up file. The file is expected to contain code to install start-up files for the user, however any valid shell code will be executed.

The zsh/newuser module is then unconditionally unloaded.

Note that it is possible to achieve exactly the same effect as the zsh/newuser module by adding code to /etc/zshenv. The module exists simply to allow the shell to make arrangements for new users without the need for intervention by package maintainers and system administrators.

The script supplied with the module invokes the shell function zsh-newuser-install. This may be invoked directly by the user even if the zsh/newuser module is disabled. Note, however, that if the module is not installed the function will not be installed either. The function is documented in User Configuration Functions.