Skip to main content

Module emulation_startup

Module emulation_startup 

Source
Expand description

emulation_startup submodule — per-drop-in startup/logout files (Rust-only). Startup- and shutdown-file model for every zshrs emulation drop-in.

zshrs-only — no zsh C counterpart. Src/init.c::run_init_scripts knows exactly two startup-file sets: zsh’s (zshenv/zprofile/zshrc/zlogin) and a single lumped Bourne one (/etc/profile + ~/.profile + $ENV). That is enough for upstream, which only ever emulates sh/ksh loosely. zshrs ships drop-ins for eight shells and each has its own set, so the whole table lives here.

Every row below was read off the shell’s own manual AND verified by running the reference binary with a scratch $HOME in which each candidate file echoes its own name:

personalitylogin shellinteractive non-loginnon-interactive
--bash/etc/profile, first of ~/.bash_profile / ~/.bash_login / ~/.profile/etc/bash.bashrc†, ~/.bashrc$BASH_ENV
--ksh/etc/profile, ~/.profile, then the interactive file/etc/ksh.kshrc†, $ENV (default ~/.kshrc)
--mksh/etc/profile, ~/.profile, then the interactive file$ENV, or ~/.mkshrc when $ENV is unset
--pdksh/etc/profile, ~/.profile, then the interactive file$ENV (no default)
--sh / --posix / --dash / --ash/etc/profile, ~/.profile, then the interactive file$ENV (no default)
--cshthe non-login files, then /etc/csh.login, ~/.login/etc/csh.cshrc, ~/.tcshrc or ~/.cshrc

† existence-gated: see [sys_file].

Reference runs (printf 'true\n' | env -i HOME=… <shell> <flags>):

  • bash 5.3.15: -l -c true.bash_profile; with it removed → .bash_login; with both removed → .profile; -i -c true.bashrc; -i -l -c true.bash_profile and NOT .bashrc; script.sh$BASH_ENV; -l script.sh.bash_profile then $BASH_ENV; -i -c true with $BASH_ENV set → .bashrc only; --norc -i / --noprofile -l → nothing; --rcfile F -i and --init-file F -iF; -l -c exit.bash_profile, .bash_logout.
  • ksh93 (/bin/ksh, macOS): -i.kshrc; -i with $ENV set → that file; -l.profile; -i -l.profile then .kshrc.
  • mksh 59c: -i.mkshrc; -i with $ENV → that file; -l.profile; -i -l.profile then .mkshrc.
  • dash: -i → nothing without $ENV; -i with $ENV → that file; -l.profile; -i -l with $ENV.profile then $ENV.
  • tcsh (macOS /bin/csh): -i.tcshrc, or .cshrc when .tcshrc is absent; -l.tcshrc then .login.

pdksh itself is not installed here; its $ENV-with-no-default rule is taken from ksh(1) on OpenBSD, which tells the user to set it by hand (“export ENV=$HOME/.kshrc”) — the sentence mksh(1) replaces with its own ~/.mkshrc fallback.

Two deliberate divergences, both marked at their call site:

  • The system-wide rc files bash and ksh93 compile in (SYS_BASHRC, /etc/ksh.kshrc) are sourced when they EXIST. zshrs ships one binary to every platform and cannot bake in a packager’s -DSYS_BASHRC; Debian/Ubuntu/Arch define it and ship the file, macOS defines neither — so “exists” reproduces both. Same reasoning as crate::extensions::global_rc.
  • bash’s rshd/sshd network-stdin case (a non-interactive shell whose stdin is a socket reads ~/.bashrc) is not modeled.

Enums§

Personality
Which shell zshrs is standing in for. Selected once by the binary’s CLI mode application (--bash, --ksh, an argv[0] symlink, …) and read wherever behavior forks per drop-in.

Functions§

apply_personality_option_deltas
Re-apply the selected drop-in’s option deltas on top of the emulate preset it shares with another shell.
default_aliases
The aliases this personality starts with, or None to leave zsh’s own defaults (run-help, which-command) in place.
emits_bracketed_paste
Whether this drop-in writes the bracketed-paste enable/disable pair (\e[?2004h / \e[?2004l) around its line editing.
emits_integration_prompt
Whether this drop-in writes the OSC 133 shell-integration marker before each prompt. It is a zsh feature — bash does not send one, and neither does zsh 5.9 with its default .term.extensions — so only native zshrs keeps it.
emulating
True when this process is standing in for another shell — any --MODE flag or argv[0] inference, --zsh included.
explicit_login
True when -l / --login was given explicitly. See [EXPLICIT_LOGIN].
install_default_aliases
Replace the alias table’s contents with this personality’s defaults. Called once during CLI mode selection, before any startup file runs, so a user’s own alias still wins.
logout_files
The ordered files read when a LOGIN shell exits, given whether the shell is interactive.
noprofile
True when --noprofile was given.
norc
True when --norc was given.
overrides_zsh_startup
True when this drop-in owns its own startup files, i.e. the faithful run_init_scripts port must NOT run for it.
personality
The selected drop-in, defaulting to Personality::Zsh.
rcfile
The --rcfile override, if one was given.
run_init_scripts
Source the selected drop-in’s startup files. Library-side entry point, called from the run_init_scripts hook.
run_logout_scripts
Source the selected drop-in’s logout files on the way out of a login shell. Called from zexit, where zsh reads .zlogout.
selected_emulate_name
The emulate name to install, or None when no drop-in was selected and the faithful argv[0] derivation should stand.
set_emulating
Record that a parity / drop-in mode was selected. Called once from the binary’s CLI mode application, for every --MODE and every argv[0] inference.
set_explicit_login
Record that login-ness came from an explicit -l / --login.
set_noprofile
Set/clear --noprofile.
set_norc
Set/clear --norc.
set_personality
Record the drop-in the user asked for. Called once from the binary’s CLI mode application, before any user code runs.
set_rcfile
Record --rcfile FILE / --init-file FILE.
single_quote
Single-quote a value the way bash’s alias / declare -p listings do: wrap in '…' and render an embedded quote as '\''.
startup_files
The ordered startup files the selected drop-in reads. Returned rather than sourced so the library’s run_init_scripts hook and the binary’s -c / script-file dispatch drive the SAME list through their own sourcing machinery.