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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user