#!/bin/bash set -euo pipefail DOTFILES_REPO="https://gitea.purpleraft.com/ryan/dotfiles" DOTFILES_DIR="$HOME/.dotfiles" echo "Starting dotfiles bootstrap..." # Clone repo (new installs) or update for branch switching if [ -d "$DOTFILES_DIR/.git" ]; then echo "Updating existing dotfiles repo..." cd "$DOTFILES_DIR" # Handle local changes if they exist if ! git diff-index --quiet HEAD --; then echo "Local changes detected:" echo "1) Discard 2) Stash 3) Abort" read -p "Choice (1-3): " choice case $choice in 1) git reset --hard HEAD ;; 2) git stash push -m "Bootstrap $(date +%Y%m%d-%H%M)" ;; *) echo "Aborted. Check 'git status' in $DOTFILES_DIR"; exit 1 ;; esac fi git pull --quiet || { echo "Error: Failed to update repository"; exit 1; } else echo "Cloning dotfiles into $DOTFILES_DIR..." git clone "$DOTFILES_REPO" "$DOTFILES_DIR" cd "$DOTFILES_DIR" fi # Branch selection - allows choosing which version of dotfiles to install # - New installs: git clone defaults to 'main', but you can switch to any branch # - Existing installs: switch from current branch to a different one # - Only runs in interactive terminals (skipped in automated/CI environments) # if [ -t 0 ] && [ -t 1 ] && [ -d ".git" ]; then # current_branch=$(git branch --show-current 2>/dev/null || echo "unknown") # echo "Current branch: $current_branch" # echo # read -p "Switch to a different branch? (y/N): " -n 1 -r # echo # if [[ $REPLY =~ ^[Yy]$ ]]; then # echo "Available branches:" # git branch -a --format="%(refname:short)" | grep -v "HEAD" | sed 's|^origin/||' | sort -u | nl -w2 -s'. ' # branches=($(git branch -a --format="%(refname:short)" | grep -v "HEAD" | sed 's|^origin/||' | sort -u)) # while true; do # read -p "Enter branch number (1-${#branches[@]}): " branch_num # if [[ "$branch_num" =~ ^[0-9]+$ ]] && [ "$branch_num" -ge 1 ] && [ "$branch_num" -le "${#branches[@]}" ]; then # selected_branch="${branches[$((branch_num-1))]}" # echo "Switching to branch: $selected_branch" # if git show-ref --verify --quiet "refs/heads/$selected_branch"; then # git checkout "$selected_branch" # elif git show-ref --verify --quiet "refs/remotes/origin/$selected_branch"; then # git checkout -b "$selected_branch" "origin/$selected_branch" # else # echo "Error: Branch $selected_branch not found" # exit 1 # fi # git pull --quiet || true # echo "Switched to branch: $selected_branch" # break # else # echo "Invalid selection. Please enter a number between 1 and ${#branches[@]}" # fi # done # fi # fi # Hand off to setup if [ -f "setup.sh" ]; then echo "Starting setup..." bash setup.sh else echo "Error: No setup.sh found!" exit 1 fi