Skip to content

Instantly share code, notes, and snippets.

@kenilt
Created July 30, 2025 14:34
Show Gist options
  • Save kenilt/a08cffdd0ae4d03117eee6ac7e997a04 to your computer and use it in GitHub Desktop.
Save kenilt/a08cffdd0ae4d03117eee6ac7e997a04 to your computer and use it in GitHub Desktop.
Restore key dotfiles (.zshrc, .gitconfig, .vimrc, etc.), the ~/.config/ directory, and ~/.zsh and ~/.ssh folders
#!/bin/bash
# Set backup directory
BACKUP_DIR="$(pwd)/Backup"
SSH_BACKUP_DIR="$BACKUP_DIR/ssh"
CONFIG_BACKUP_DIR="$BACKUP_DIR/config"
ZSH_BACKUP_DIR="$BACKUP_DIR/zsh"
echo "πŸ”„ Starting restore..."
# Restore dotfiles
for file in "$BACKUP_DIR"/.*rc "$BACKUP_DIR"/.git*; do
if [ -f "$file" ]; then
cp "$file" ~/
echo "βœ… Restored $(basename "$file")"
fi
done
# Restore ~/.config
if [ -d "$CONFIG_BACKUP_DIR" ]; then
mkdir -p ~/.config
cp -r "$CONFIG_BACKUP_DIR"/* ~/.config/
echo "βœ… Restored ~/.config/"
fi
# Restore ~/.zsh
if [ -d "$ZSH_BACKUP_DIR" ]; then
mkdir -p ~/.zsh
cp -r "$ZSH_BACKUP_DIR"/* ~/.zsh/
echo "βœ… Restored ~/.zsh/"
fi
# Restore SSH config
if [ -d "$SSH_BACKUP_DIR" ]; then
mkdir -p ~/.ssh
cp -r "$SSH_BACKUP_DIR"/* ~/.ssh/
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_* 2>/dev/null
chmod 644 ~/.ssh/config 2>/dev/null
echo "βœ… Restored ~/.ssh/"
else
echo "⚠️ No SSH backup directory found."
fi
echo "βœ… Restore complete."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment