Skip to content

Harden bash and zsh prompt rendering#10

Draft
jdloft wants to merge 1 commit into
masterfrom
codex/fix-terminal-corruption-issues-in-bash-and-zsh
Draft

Harden bash and zsh prompt rendering#10
jdloft wants to merge 1 commit into
masterfrom
codex/fix-terminal-corruption-issues-in-bash-and-zsh

Conversation

@jdloft
Copy link
Copy Markdown
Owner

@jdloft jdloft commented Feb 20, 2026

Motivation

  • Narrow terminal windows and history/search navigation revealed prompt redraw/cursor-position corruption caused by unmarked non-printing ANSI sequences and zsh % expansions in dynamic fields.
  • The prompt host color used the literal prompt escape token instead of the actual hostname which made special-case coloring (e.g. toolbox) unreliable.

Description

  • Added a Bash helper _dotfiles-bash-np to wrap ANSI color sequences with explicit readline non-printing delimiters (\001/\002) and applied it to the main prompt, exit-code, git, virtualenv, k8s and chroot segments in source/bash/20_prompt.bash.
  • Reworked Bash prompt-building to concatenate safe non-printing markers via _dotfiles-bash-np and updated _dotfiles-exit_code, _dotfiles-git-prompt, _dotfiles-virtualenv-prompt, and _dotfiles-k8s-prompt to use the helper.
  • Fixed host detection in both Bash and Zsh to use a real hostname variable (host_name from DOTFILES_HOST/HOSTNAME) instead of comparing the literal prompt escape token, and made the chroot prompt resilient to being read once.
  • Hardened Zsh prompt in source/zsh/20_prompt.zsh by switching to %~ for the cwd and escaping % characters in dynamic fields (chroot, git branch, virtualenv, k8s context) to avoid percent-expansion and width miscalculation.

Testing

  • bash -n source/bash/20_prompt.bash completed successfully with no syntax errors.
  • zsh -n source/zsh/20_prompt.zsh could not be run in this environment because zsh is not installed, so Zsh syntax validation was not performed automatically.

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant