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.
This commit is contained in:
2026-07-13 00:18:38 -04:00
parent 9d4c2d392c
commit e0598477da
2 changed files with 3 additions and 3 deletions
+2 -2
View File
@@ -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