zsh: consolidate updaters into single update_zshrc function

This commit is contained in:
2026-08-01 02:05:01 -04:00
parent 7e75d00c30
commit 0c510b06d7
2 changed files with 39 additions and 47 deletions
+37 -4
View File
@@ -18,13 +18,46 @@ use_master_branch(){
}
update_zshrc(){
local tmp=/tmp/.zshrc.$$
curl -fsSL --connect-timeout 5 --max-time 10 "$ZSHRC_URL" -o "$tmp" 2>/dev/null || return
if zsh -n "$tmp" 2>/dev/null && ! cmp -s "$tmp" "$HOME/.zshrc" 2>/dev/null; then
local tmp
# zshrc
tmp=/tmp/.zshrc.$$
if curl -fsSL --connect-timeout 3 --max-time 8 "$ZSHRC_URL" -o "$tmp" 2>/dev/null \
&& [[ -f "$tmp" ]] && 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
mv "$tmp" "$HOME/.zshrc" && exec zsh
fi
rm -f "$tmp"
# zsh-init
tmp=/tmp/.zsh-init.$$
if curl -fsSL --connect-timeout 3 --max-time 8 "$ZSHRC_GIT/zsh-init.sh" -o "$tmp" 2>/dev/null \
&& [[ -f "$tmp" ]] && ! cmp -s "$tmp" "$ZSH_CONFIG/zsh-init.sh" 2>/dev/null; then
echo "Updating zsh-init..."
mv "$tmp" "$ZSH_CONFIG/zsh-init.sh"
else
rm -f "$tmp"
fi
# zsh-functions
tmp=/tmp/.zsh-functions.$$
if curl -fsSL --connect-timeout 3 --max-time 8 "$ZSHRC_GIT/zsh-functions.zsh" -o "$tmp" 2>/dev/null \
&& [[ -f "$tmp" ]] && ! cmp -s "$tmp" "$ZSH_CONFIG/zsh-functions.zsh" 2>/dev/null; then
echo "Updating zsh-functions..."
mv "$tmp" "$ZSH_CONFIG/zsh-functions.zsh"
else
rm -f "$tmp"
fi
# starship
if command -v starship >/dev/null; then
tmp=$(mktemp)
if curl -fsSL --connect-timeout 3 --max-time 8 "$ZSHRC_GIT/starship.toml" -o "$tmp" 2>/dev/null \
&& [[ -f "$tmp" ]] && ! cmp -s "$tmp" "$HOME/.config/starship.toml" 2>/dev/null; then
mkdir -p "$HOME/.config"
echo "Updating starship..."
mv "$tmp" "$HOME/.config/starship.toml"
else
rm -f "$tmp"
fi
fi
}
fix_btopbg(){
+2 -43
View File
@@ -34,49 +34,8 @@ alias nbstat=$'netbird status --json | jq -r \'.peers.details[]? | [(.hostname /
alias open-ports="ss -tulpn | grep LISTEN"
alias yeet='yay -Rcs'
# Auto-update zshrc, zsh-functions, and starship config on interactive shell start. Disable with ZSHRC_UPDATE_DISABLED=true.
if [[ -o interactive && "$ZSHRC_UPDATE_DISABLED" != "true" ]]; then
tmp=/tmp/.zshrc.$$
if curl -fsSL --connect-timeout 3 --max-time 8 "$ZSHRC_URL" -o "$tmp" 2>/dev/null \
&& [[ -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
rm -f "$tmp"
# zsh-init
itmp=/tmp/.zsh-init.$$
if curl -fsSL --connect-timeout 3 --max-time 8 "$ZSHRC_GIT/zsh-init.sh" -o "$itmp" 2>/dev/null \
&& [[ -f "$itmp" ]] && ! cmp -s "$itmp" "$ZSH_CONFIG/zsh-init.sh" 2>/dev/null; then
echo "Updating zsh-init..."
mv "$itmp" "$ZSH_CONFIG/zsh-init.sh"
else
rm -f "$itmp"
fi
# zsh-functions
ftmp=/tmp/.zsh-functions.$$
if curl -fsSL --connect-timeout 3 --max-time 8 "$ZSHRC_GIT/zsh-functions.zsh" -o "$ftmp" 2>/dev/null \
&& [[ -f "$ftmp" ]] && ! cmp -s "$ftmp" "$ZSH_CONFIG/zsh-functions.zsh" 2>/dev/null; then
echo "Updating zsh-functions..."
mv "$ftmp" "$ZSH_CONFIG/zsh-functions.zsh"
else
rm -f "$ftmp"
fi
# starship config
if command -v starship >/dev/null; then
stmp=$(mktemp)
if curl -fsSL --connect-timeout 3 --max-time 8 "$ZSHRC_GIT/starship.toml" -o "$stmp" 2>/dev/null \
&& [[ -f "$stmp" ]] && ! cmp -s "$stmp" "$HOME/.config/starship.toml" 2>/dev/null; then
mkdir -p "$HOME/.config"
mv "$stmp" "$HOME/.config/starship.toml"
else
rm -f "$stmp"
fi
fi
fi
# Auto-update on interactive shell start. Disable with ZSHRC_UPDATE_DISABLED=true.
[[ -o interactive && "$ZSHRC_UPDATE_DISABLED" != "true" ]] && update_zshrc
[[ -f $HOME/.zshrc.local ]] || touch $HOME/.zshrc.local
source $HOME/.zshrc.local