#!/usr/bin/env bash # --------------------------------------------------------------------------- # Put back the configs that install.sh moved aside. # scripts/restore-backup.sh # restore the most recent backup # scripts/restore-backup.sh # restore a specific backup # scripts/restore-backup.sh --list # show available backups # --------------------------------------------------------------------------- source "$(dirname "${BASH_SOURCE[0]}")/lib.sh" mapfile -t BACKUPS < <(find "$HOME" -maxdepth 1 -type d -name '.config-backup-*' | sort -r) if [[ "${1:-}" == "--list" ]]; then if [[ ${#BACKUPS[@]} -eq 0 ]]; then echo "no backups found in $HOME" else printf '%s\n' "${BACKUPS[@]}" fi exit 0 fi SRC="${1:-${BACKUPS[0]:-}}" [[ -n "$SRC" ]] || die "no backup directories found (looked for ~/.config-backup-*)" [[ -d "$SRC" ]] || die "not a directory: $SRC" log "Restoring from ${SRC/#$HOME/\~}" step "the following files will be copied back over your current configs:" (cd "$SRC" && find . -type f | sed 's|^\./| ~/|') confirm "Restore these files?" || die "aborted" # -a preserves modes; the trailing /. copies the contents, not the directory. run cp -a "$SRC/." "$HOME/" ok "restored — restart i3 (Super+Shift+R) or log out and back in"