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:
+1
-1
@@ -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.
|
||||
|
||||
@@ -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