mirror of
https://github.com/openai/codex.git
synced 2026-10-21 17:48:44 +00:00
Expose `shell_startup_script` from `codex-shell-command` and use it for interactive shell snapshot capture, preserving the existing startup scripts. The helper returns an empty script for other shell types; callers remain responsible for login startup flags and shell lifecycle. GitOrigin-RevId: 8cb64c02c08140d2676e67b9db06c9a77649b3eb
31 lines
987 B
Rust
31 lines
987 B
Rust
//! Profile seeding shared by shell snapshot capture and other initialized shells.
|
|
//! Preserve the existing scripts; callers own the shell's launch flags and lifecycle.
|
|
|
|
use crate::shell_detect::ShellType;
|
|
|
|
/// Load the interactive configuration used by snapshot capture in a login shell.
|
|
/// The caller must already launch the shell with its usual login startup flags.
|
|
/// Only Bash and Zsh are supported here; POSIX sh's ENV handling remains in capture.
|
|
pub fn shell_startup_script(shell_type: ShellType) -> &'static str {
|
|
match shell_type {
|
|
ShellType::Zsh => {
|
|
r#"if [[ -n "${ZDOTDIR-}" ]]; then
|
|
rc="$ZDOTDIR/.zshrc"
|
|
elif [[ -n "${HOME-}" ]]; then
|
|
rc="$HOME/.zshrc"
|
|
else
|
|
rc=
|
|
fi
|
|
[[ -r "$rc" ]] && . "$rc"
|
|
"#
|
|
}
|
|
ShellType::Bash => {
|
|
r#"if [ -z "${BASH_ENV-}" ] && [ -n "${HOME-}" ] && [ -r "$HOME/.bashrc" ]; then
|
|
. "$HOME/.bashrc"
|
|
fi
|
|
"#
|
|
}
|
|
ShellType::Sh | ShellType::PowerShell | ShellType::Cmd => "",
|
|
}
|
|
}
|