#!/usr/bin/env bash # Respalda al cerrar sesión/apagar todo lo que chezmoi ya tiene rastreado. # Solo re-sincroniza rutas YA gestionadas (chezmoi re-add), nunca añade # rutas nuevas por su cuenta -- eso evita que algo sensible se cuele solo. set -uo pipefail LOG="$HOME/.local/share/chezmoi-sync.log" mkdir -p "$(dirname "$LOG")" exec >>"$LOG" 2>&1 echo "=== shutdown-sync $(date -Iseconds) ===" SRC="$HOME/.local/share/chezmoi" cd "$SRC" || exit 0 chezmoi re-add git add -A if git diff --cached --quiet; then echo "sin cambios que respaldar" exit 0 fi git commit -m "Auto-backup $(date '+%Y-%m-%d %H:%M')" if timeout 20 git push origin main; then echo "push OK" else echo "push falló (¿sin red?), el commit queda en local para el próximo intento" fi