From e0598477daaac7bb88649b65d3069f85d0f9184f Mon Sep 17 00:00:00 2001 From: Jeremy McClure Date: Mon, 13 Jul 2026 00:18:38 -0400 Subject: [PATCH] validate downloaded zshrc with zsh -n before replacing Adds syntax validation via zsh -n to both update_zshrc() and the auto-update on shell start. Prevents error pages or corrupted content from overwriting ~/.zshrc and breaking the shell. --- zsh/README.md | 2 +- zsh/zshrc | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/zsh/README.md b/zsh/README.md index bf5aa17..83753c1 100644 --- a/zsh/README.md +++ b/zsh/README.md @@ -3,7 +3,7 @@ ## Files ### `zshrc` -Main Zsh configuration file. Sets up Oh My Zsh, plugins (git, sudo, eza, fzf, starship, etc.), history options, aliases, and auto-updates itself from a remote source. Also bootstraps tmux config and runs a fastfetch system info display on interactive shells. +Main Zsh configuration file. Sets up Oh My Zsh, plugins (git, sudo, eza, fzf, starship, etc.), history options, aliases, and auto-updates itself from a remote source. Before replacing `~/.zshrc`, the downloaded file is validated with `zsh -n` to ensure it's syntactically valid — this prevents error pages or corrupted content from breaking the shell. Also bootstraps tmux config and runs a fastfetch system info display on interactive shells. ### `zshrc-bootstrap.zsh` One-shot setup script executed by `zshrc`. Installs missing dependencies (starship, lazydocker, fastfetch, eza, fzf, etc.) via the system package manager (brew, apt, dnf, pacman) or cargo, clones Oh My Zsh and custom plugins (zsh-autosuggestions, fast-syntax-highlighting, fzf-tab). Runs only when the bootstrap version changes. diff --git a/zsh/zshrc b/zsh/zshrc index cbae3e8..c160368 100644 --- a/zsh/zshrc +++ b/zsh/zshrc @@ -17,7 +17,7 @@ export ZSHRC_BOOTSTRAP="$ZSH_CONFIG/.bootstrapped" update_zshrc(){ local tmp=/tmp/.zshrc.$$ curl -sSL --connect-timeout 5 "$ZSHRC_URL" -o "$tmp" 2>/dev/null || return - if ! cmp -s "$tmp" "$HOME/.zshrc" 2>/dev/null; then + if zsh -n "$tmp" 2>/dev/null && ! cmp -s "$tmp" "$HOME/.zshrc" 2>/dev/null; then echo "Updating zshrc..." mv "$tmp" "$HOME/.zshrc" && echo "Updated. Reloading..." && exec zsh fi @@ -127,7 +127,7 @@ alias yeet='yay -Rcs' if [[ -o interactive ]]; then tmp=/tmp/.zshrc.$$ curl -sSL --connect-timeout 3 "$ZSHRC_URL" -o "$tmp" 2>/dev/null - if [[ -f "$tmp" ]] && ! cmp -s "$tmp" "$HOME/.zshrc" 2>/dev/null; then + if [[ -f "$tmp" ]] && zsh -n "$tmp" 2>/dev/null && ! cmp -s "$tmp" "$HOME/.zshrc" 2>/dev/null; then echo "Updating zshrc..." mv "$tmp" "$HOME/.zshrc" && exec zsh fi