diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 7cf54f5..1a8ccc5 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -62,6 +62,18 @@ this file is the curated, human-readable summary. cases (non-root privilege refusals + root-safe Brave/unknown refusals). Gates: `cargo fmt --check`, `clippy --workspace --all-targets -- -D 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 fast-defaults commit and content-verified (`fastdefaults.iso`, 1.6 GiB, `ad9cddb2…`, build `20260926T145700Z` from `e747baf`; embedded diff --git a/docs/HANDOFF.md b/docs/HANDOFF.md index 0c1cd83..ec9557b 100644 --- a/docs/HANDOFF.md +++ b/docs/HANDOFF.md @@ -3,6 +3,16 @@ 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. +- **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):** audited the `e747baf` fast-defaults tree against the prompt (all lanes covered, no code changes needed), re-ran gates green (fmt, clippy -D, diff --git a/installer-rs/crates/phoebus-core/src/system.rs b/installer-rs/crates/phoebus-core/src/system.rs index 2a85a61..e6992a9 100644 --- a/installer-rs/crates/phoebus-core/src/system.rs +++ b/installer-rs/crates/phoebus-core/src/system.rs @@ -337,29 +337,110 @@ pub fn cupsd_local_conf() -> String { /// history search and a readable prompt. Existing users' files are never /// overwritten (seeded only when absent). 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 zle -N up-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 '^[OA' up-line-or-beginning-search bindkey '^[[B' down-line-or-beginning-search +bindkey '^[OB' down-line-or-beginning-search bindkey '^R' history-incremental-search-backward -HISTSIZE=10000 -SAVEHIST=10000 +# Home/End/Delete/word jumps. +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 -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 zstyle ':completion:*' menu select -zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}' -[ -r /usr/share/zsh/site-functions ] || true +zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}' 'r:|[._-]=* r:|=*' +[[ -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 source /usr/share/zsh-autosuggestions/zsh-autosuggestions.zsh fi if [ -r /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh ]; then source /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh 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`; @@ -2720,9 +2801,26 @@ mod tests { assert_eq!(USER_LOGIN_SHELL, "/bin/zsh"); assert_eq!(ROOT_LOGIN_SHELL, "/bin/bash"); 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-syntax-highlighting")); assert!(ZSH_SKEL_RC.contains("up-line-or-beginning-search")); + // No `%F{name}`: 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] diff --git a/installer-rs/crates/phoebus-executor/src/users.rs b/installer-rs/crates/phoebus-executor/src/users.rs index 4f37355..9c4f2df 100644 --- a/installer-rs/crates/phoebus-executor/src/users.rs +++ b/installer-rs/crates/phoebus-executor/src/users.rs @@ -167,10 +167,7 @@ fn ensure_root_shell_bash(exec: &Exec, root: &Path) -> Result<()> { /// `~/.zshrc` from the maintained default, preserving existing custom files. fn seed_default_zsh(exec: &Exec, config: &InstallConfig) -> Result<()> { let target = exec.target(); - target.write( - "etc/zsh/zprofile", - "# Phoebus Zsh login defaults (generated).\n", - )?; + target.write("etc/zsh/zprofile", phoebus_core::system::ZSH_ZPROFILE)?; // Skeleton for future users; never overwrite customization. if !target.exists("etc/skel/.zshrc") { target.write("etc/skel/.zshrc", phoebus_core::system::ZSH_SKEL_RC)?; @@ -312,6 +309,9 @@ mod tests { assert!(skel.contains("zsh-autosuggestions")); let user_rc = std::fs::read_to_string(exec.root.join("home/ada/.zshrc")).unwrap(); 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]