Skip to content

Instantly share code, notes, and snippets.

@Neugierdsnase
Created May 11, 2023 13:20
Show Gist options
  • Save Neugierdsnase/f59c3c5c1a1eb66aec7fde36c5a034b6 to your computer and use it in GitHub Desktop.
Save Neugierdsnase/f59c3c5c1a1eb66aec7fde36c5a034b6 to your computer and use it in GitHub Desktop.
#!/usr/bin/env zsh
# ANSI color codes
GREEN="\033[32m"
YELLOW="\033[33m"
RESET="\033[0m"
BACKUP_DIR="$HOME/Documents/dotfiles_backup"
# Create the backup directory if it doesn't exist
# and initialized git repo
if [ ! -d "$BACKUP_DIR" ]; then
mkdir -p "$BACKUP_DIR"
cd "$BACKUP_DIR"
git init
else
cd "$BACKUP_DIR"
if [ ! -d ".git" ]; then
git init
fi
fi
# List of dotfiles/directories to back up
DOTFILES=(
"$HOME/.config/alacritty"
"$HOME/.zshrc"
"$HOME/.tmux.conf"
"$HOME/.tmux"
"$HOME/.config/tmuxinator"
"$HOME/.config/nvim"
"$HOME/.config/starship.toml"
)
# Backup the dotfiles
for dotfile in "${DOTFILES[@]}"; do
if [ -e "$dotfile" ]; then
echo "\n${YELLOW}Backing up $dotfile...${RESET}"
# avoiding nested git repositories
rsync -av --exclude='.git' "$dotfile" "$BACKUP_DIR"
git add -A
echo "${GREEN}Backed up $dotfile to $BACKUP_DIR${RESET}"
echo "\n------------------------------------\n\n\n"
else
echo "${YELLOW}Skipped $dotfile (not found)${RESET}"
echo "\n------------------------------------\n\n\n"
fi
done
# Commit the changes
git commit -m "Updated dotfiles backup via script."
echo "${GREEN}Dotfile backup completed.${RESET}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment