feat(shell): modernize default Zsh seed and login environment
Some checks are pending
ci / test (push) Waiting to run

Fixes the %F{ yellow } color bug (Phoebus Gold 214), drops the no-op
site-functions probe, puts fpath before a cached compinit (full audit at
most once per 24h), adds Kitty/application-mode keybindings, replaces
cross-tab SHARE_HISTORY with INC_APPEND_HISTORY, and adds a builtin
vcs_info git branch plus an exit-status prompt arrow. New ZSH_ZPROFILE
bridges /etc/profile (env-update paths, Nix/Flatpak profile.d) into Zsh
login sessions and adds ~/.local/bin to PATH. Seeding stays once-only;
root stays on Bash; /bin/sh untouched.

Verified: cargo fmt --check, clippy --workspace --all-targets -- -D
warnings, cargo test --workspace 757/757, zsh -n on both files plus an
interactive startup smoke test on host zsh 5.9. Installed-session
behavior awaits the disposable VM.
This commit is contained in:
Phoebus 2026-09-26 15:31:10 -07:00
parent 962e125208
commit 5369a89b4b
4 changed files with 132 additions and 12 deletions

View file

@ -62,6 +62,18 @@ this file is the curated, human-readable summary.
cases (non-root privilege refusals + root-safe Brave/unknown refusals). cases (non-root privilege refusals + root-safe Brave/unknown refusals).
Gates: `cargo fmt --check`, `clippy --workspace --all-targets -- -D Gates: `cargo fmt --check`, `clippy --workspace --all-targets -- -D
warnings`, release build, `test_vmsafety.py` 18/18, shellcheck clean. warnings`, release build, `test_vmsafety.py` 18/18, shellcheck clean.
- **Zsh defaults modernization (seeded once, user-owned afterwards).**
`ZSH_SKEL_RC` fixes the `%F{ yellow }` color bug (now Phoebus Gold 214),
drops the no-op site-functions probe, puts `fpath` before a cached
`compinit` (full audit at most once per 24h via `.zcompdump`), adds
Kitty/application-mode keybindings (Up/Down prefix search, Home/End/
Delete, word jumps), replaces cross-tab `SHARE_HISTORY` with
`INC_APPEND_HISTORY`, and adds a builtin `vcs_info` git branch plus an
exit-status prompt arrow. New `ZSH_ZPROFILE` bridges `/etc/profile`
(Gentoo `env-update` paths, Nix/Flatpak `profile.d`) into Zsh login
sessions and adds `~/.local/bin` to `PATH`. Verified: `zsh -n` clean on
both files, interactive startup smoke test, 757 workspace tests green;
installed-session behavior awaits the disposable VM.
- **Not VM-verified this session.** A fresh ISO was built from the - **Not VM-verified this session.** A fresh ISO was built from the
fast-defaults commit and content-verified (`fastdefaults.iso`, 1.6 GiB, fast-defaults commit and content-verified (`fastdefaults.iso`, 1.6 GiB,
`ad9cddb2…`, build `20260926T145700Z` from `e747baf`; embedded `ad9cddb2…`, build `20260926T145700Z` from `e747baf`; embedded

View file

@ -3,6 +3,16 @@
Rolling note between work sessions. **Update this file before you finish**, then Rolling note between work sessions. **Update this file before you finish**, then
commit it. It should be short and current; use `git log` for detail. commit it. It should be short and current; use `git log` for detail.
- **Zsh modernization (2026-09-26, IMPLEMENTED + UNIT-TESTED, VM NOT RUN):**
rewrote `ZSH_SKEL_RC` (color fix, cached compinit, Kitty keybindings,
`INC_APPEND_HISTORY`, vcs_info git branch, exit-status prompt) and added
`ZSH_ZPROFILE` (`/etc/profile` bridge + `~/.local/bin`); `seed_default_zsh`
uses the new const. Gates: fmt, clippy `--workspace --all-targets -- -D
warnings`, 757/757 tests, `zsh -n` + interactive startup smoke on host zsh
5.9. Seeding is once-only (existing `~/.zshrc` preserved). Installed-session
behavior (login env, Nix paths, prompt/git/keys in Kitty) awaits the
disposable VM. Uncommitted; `docs/DUAL-BOOT.md` from the prior session also
still uncommitted.
- **Fast-defaults follow-up (2026-09-26, ISO BUILT + CONTENT-VERIFIED, VM NOT RUN):** - **Fast-defaults follow-up (2026-09-26, ISO BUILT + CONTENT-VERIFIED, VM NOT RUN):**
audited the `e747baf` fast-defaults tree against the prompt (all lanes audited the `e747baf` fast-defaults tree against the prompt (all lanes
covered, no code changes needed), re-ran gates green (fmt, clippy -D, covered, no code changes needed), re-ran gates green (fmt, clippy -D,

View file

@ -337,29 +337,110 @@ pub fn cupsd_local_conf() -> String {
/// history search and a readable prompt. Existing users' files are never /// history search and a readable prompt. Existing users' files are never
/// overwritten (seeded only when absent). /// overwritten (seeded only when absent).
pub const ZSH_SKEL_RC: &str = r#"# Phoebus default Zsh configuration (seeded once; user-owned afterwards). pub const ZSH_SKEL_RC: &str = r#"# Phoebus default Zsh configuration (seeded once; user-owned afterwards).
autoload -Uz compinit && compinit
# --- 1. Completion paths (must precede compinit) ---------------------------
# Plain assignments (no duplicates handling needed here): entries that do not
# exist are ignored by compinit.
fpath=(
/usr/share/zsh/site-functions
$HOME/.local/share/zsh/site-functions
$fpath
)
# Fast cached completion init: full fpath audit at most once per 24h, cache
# (`-C`, no audit) otherwise. The audit is a security check (world-writable
# fpath entries), so it is deferred, never disabled.
autoload -Uz compinit
_zcompdump="${ZDOTDIR:-$HOME}/.zcompdump"
if [[ ! -f "$_zcompdump" ]] \
|| ! command -v find >/dev/null 2>&1 \
|| [[ -n $(find "${_zcompdump%/*}" -maxdepth 1 -name "${_zcompdump##*/}" -mtime +0 2>/dev/null) ]]; then
compinit -d "$_zcompdump"
else
compinit -C -d "$_zcompdump"
fi
unset _zcompdump
# --- 2. Keybindings (Emacs baseline + Kitty/application-mode compat) --------
bindkey -e
autoload -Uz up-line-or-beginning-search down-line-or-beginning-search autoload -Uz up-line-or-beginning-search down-line-or-beginning-search
zle -N up-line-or-beginning-search zle -N up-line-or-beginning-search
zle -N down-line-or-beginning-search zle -N down-line-or-beginning-search
# Up/Down: history prefix search (both normal `^[[A` and application `^[OA`
# sequences; Kitty switches between them with smkx/rmkx).
bindkey '^[[A' up-line-or-beginning-search bindkey '^[[A' up-line-or-beginning-search
bindkey '^[OA' up-line-or-beginning-search
bindkey '^[[B' down-line-or-beginning-search bindkey '^[[B' down-line-or-beginning-search
bindkey '^[OB' down-line-or-beginning-search
bindkey '^R' history-incremental-search-backward bindkey '^R' history-incremental-search-backward
HISTSIZE=10000 # Home/End/Delete/word jumps.
SAVEHIST=10000 bindkey '^[[H' beginning-of-line
bindkey '^[OH' beginning-of-line
bindkey '^[[F' end-of-line
bindkey '^[OF' end-of-line
bindkey '^[[3~' delete-char
bindkey '^[[1;5C' forward-word
bindkey '^[[1;5D' backward-word
# --- 3. History (immediate write, no cross-session navigation) --------------
HISTFILE=~/.zsh_history HISTFILE=~/.zsh_history
setopt APPEND_HISTORY SHARE_HISTORY HIST_IGNORE_DUPS HIST_IGNORE_SPACE HISTSIZE=50000
SAVEHIST=50000
# INC_APPEND_HISTORY (not SHARE_HISTORY): each command hits the file at once
# so nothing is lost on crash, but Up/Down stays local to the session instead
# of pulling in commands from other tabs.
setopt EXTENDED_HISTORY INC_APPEND_HISTORY
setopt HIST_EXPIRE_DUPS_FIRST HIST_IGNORE_DUPS HIST_FIND_NO_DUPS
setopt HIST_IGNORE_SPACE HIST_REDUCE_BLANKS
# --- 4. Ergonomics ----------------------------------------------------------
setopt AUTO_CD AUTO_PUSHD PUSHD_IGNORE_DUPS CORRECT setopt AUTO_CD AUTO_PUSHD PUSHD_IGNORE_DUPS CORRECT
zstyle ':completion:*' menu select zstyle ':completion:*' menu select
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}' zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}' 'r:|[._-]=* r:|=*'
[ -r /usr/share/zsh/site-functions ] || true [[ -n ${LS_COLORS:-} ]] && zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
# Git branch via the vcs_info builtin (no external dependency); limited to
# git so prompt rendering stays fast. Appended to precmd_functions so a user
# precmd of their own keeps working.
autoload -Uz vcs_info
zstyle ':vcs_info:*' enable git
zstyle ':vcs_info:git:*' formats ' %F{242}(%F{214}%b%F{242})%f'
phoebus_vcs_precmd() { vcs_info; }
precmd_functions+=(phoebus_vcs_precmd)
# --- 5. Prompt (Phoebus Gold 214; arrow shows last exit status) --------------
setopt PROMPT_SUBST
PROMPT='%F{214}%n@%m%f %F{39}%~%f${vcs_info_msg_0_} %(?.%F{118}❯%f.%F{196}❯%f) '
RPROMPT='%F{242}%*%f'
# --- 6. Safe color aliases ---------------------------------------------------
alias ls='ls --color=auto'
alias ll='ls -la --color=auto'
alias grep='grep --color=auto'
alias diff='diff --color=auto'
# --- 7. Packaged plugins (highlighting last: it wraps prior widgets) --------
if [ -r /usr/share/zsh-autosuggestions/zsh-autosuggestions.zsh ]; then if [ -r /usr/share/zsh-autosuggestions/zsh-autosuggestions.zsh ]; then
source /usr/share/zsh-autosuggestions/zsh-autosuggestions.zsh source /usr/share/zsh-autosuggestions/zsh-autosuggestions.zsh
fi fi
if [ -r /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh ]; then if [ -r /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh ]; then
source /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh source /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
fi fi
PROMPT='%F{ yellow }%n@%m%f %F{ blue }%~%f %# ' "#;
RPROMPT='%F{240}%*%f'
/// Zsh login environment (`/etc/zsh/zprofile`, generated).
/// Zsh login shells read this file and NOT `/etc/profile`, so without the
/// bridge below Gentoo's `env-update` paths and `/etc/profile.d/*.sh`
/// (Nix, Flatpak) would be missing from Zsh login sessions.
pub const ZSH_ZPROFILE: &str = r#"# /etc/zsh/zprofile - Phoebus Zsh login environment (generated).
# Bridge Gentoo's standard profile (profile.env, profile.d: Nix, Flatpak).
if [ -r /etc/profile ]; then
emulate sh -c 'source /etc/profile'
fi
# User-local binaries on PATH.
if [ -d "$HOME/.local/bin" ] && [[ ":$PATH:" != *":$HOME/.local/bin:"* ]]; then
export PATH="$HOME/.local/bin:$PATH"
fi
"#; "#;
/// Login shell for newly created users. Root keeps `/bin/bash`; /// Login shell for newly created users. Root keeps `/bin/bash`;
@ -2720,9 +2801,26 @@ mod tests {
assert_eq!(USER_LOGIN_SHELL, "/bin/zsh"); assert_eq!(USER_LOGIN_SHELL, "/bin/zsh");
assert_eq!(ROOT_LOGIN_SHELL, "/bin/bash"); assert_eq!(ROOT_LOGIN_SHELL, "/bin/bash");
assert!(ZSH_SKEL_RC.contains("compinit")); assert!(ZSH_SKEL_RC.contains("compinit"));
assert!(ZSH_SKEL_RC.contains("compinit -C"));
assert!(ZSH_SKEL_RC.contains("zsh-autosuggestions")); assert!(ZSH_SKEL_RC.contains("zsh-autosuggestions"));
assert!(ZSH_SKEL_RC.contains("zsh-syntax-highlighting")); assert!(ZSH_SKEL_RC.contains("zsh-syntax-highlighting"));
assert!(ZSH_SKEL_RC.contains("up-line-or-beginning-search")); assert!(ZSH_SKEL_RC.contains("up-line-or-beginning-search"));
// No `%F{<space>name<space>}`: zsh color names take no spaces.
assert!(!ZSH_SKEL_RC.contains("%F{ "));
assert!(!ZSH_SKEL_RC.contains(" }%"));
// Completion paths precede compinit; the old no-op probe is gone.
assert!(
ZSH_SKEL_RC.find("fpath=(").unwrap()
< ZSH_SKEL_RC.find("autoload -Uz compinit").unwrap()
);
assert!(!ZSH_SKEL_RC.contains("[ -r /usr/share/zsh/site-functions ] || true"));
// History is session-local (immediate write, no cross-tab pull).
assert!(ZSH_SKEL_RC.contains("setopt EXTENDED_HISTORY INC_APPEND_HISTORY"));
assert!(!ZSH_SKEL_RC.contains("APPEND_HISTORY SHARE_HISTORY"));
// Kitty/application-mode keybindings and the login-env bridge.
assert!(ZSH_SKEL_RC.contains("'^[OA'"));
assert!(ZSH_ZPROFILE.contains("emulate sh -c 'source /etc/profile'"));
assert!(ZSH_ZPROFILE.contains("$HOME/.local/bin"));
} }
#[test] #[test]

View file

@ -167,10 +167,7 @@ fn ensure_root_shell_bash(exec: &Exec, root: &Path) -> Result<()> {
/// `~/.zshrc` from the maintained default, preserving existing custom files. /// `~/.zshrc` from the maintained default, preserving existing custom files.
fn seed_default_zsh(exec: &Exec, config: &InstallConfig) -> Result<()> { fn seed_default_zsh(exec: &Exec, config: &InstallConfig) -> Result<()> {
let target = exec.target(); let target = exec.target();
target.write( target.write("etc/zsh/zprofile", phoebus_core::system::ZSH_ZPROFILE)?;
"etc/zsh/zprofile",
"# Phoebus Zsh login defaults (generated).\n",
)?;
// Skeleton for future users; never overwrite customization. // Skeleton for future users; never overwrite customization.
if !target.exists("etc/skel/.zshrc") { if !target.exists("etc/skel/.zshrc") {
target.write("etc/skel/.zshrc", phoebus_core::system::ZSH_SKEL_RC)?; target.write("etc/skel/.zshrc", phoebus_core::system::ZSH_SKEL_RC)?;
@ -312,6 +309,9 @@ mod tests {
assert!(skel.contains("zsh-autosuggestions")); assert!(skel.contains("zsh-autosuggestions"));
let user_rc = std::fs::read_to_string(exec.root.join("home/ada/.zshrc")).unwrap(); let user_rc = std::fs::read_to_string(exec.root.join("home/ada/.zshrc")).unwrap();
assert!(user_rc.contains("up-line-or-beginning-search")); assert!(user_rc.contains("up-line-or-beginning-search"));
// Login shells bridge Gentoo's /etc/profile (env-update, Nix).
let zprofile = std::fs::read_to_string(exec.root.join("etc/zsh/zprofile")).unwrap();
assert!(zprofile.contains("source /etc/profile"));
} }
#[test] #[test]