#!/usr/bin/env bash # bootstrap.sh — Set up dotfiles on a new machine # Usage: bash bootstrap.sh [--profile personal|work] # # This script stows all dotfile packages, copies shell config files, # and creates untracked .local stub files for per-machine overrides. set -e DOTFILES_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROFILE="${1:-personal}" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo " Dotfiles Bootstrap" echo " Profile : $PROFILE" echo " OS : $(uname -s)" echo " Host : $(hostname)" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" # ── 1. Stow all packages ─────────────────────────────────────────────────────── # shell is excluded from global .stow-local-ignore, handled separately below PACKAGES="zsh bash tmux nvim starship alacritty kitty ghostty wezterm zed btop vim" for pkg in $PACKAGES; do if [[ -d "$DOTFILES_DIR/$pkg" ]]; then echo " stow → $pkg" stow --adopt --dir="$DOTFILES_DIR" --target="$HOME" "$pkg" 2>/dev/null || \ echo " ⚠ stow $pkg skipped (already linked or conflict)" fi done # ── 2. Copy shell config files manually (stow-local-ignore excludes `shell`) ── SHELL_SRC="$DOTFILES_DIR/shell/.config/shell" SHELL_DST="$HOME/.config/shell" mkdir -p "$SHELL_DST" for f in common aliases personal work macos linux; do if [[ -f "$SHELL_SRC/$f" ]]; then echo " copy shell/$f → $SHELL_DST/$f" cp -n "$SHELL_SRC/$f" "$SHELL_DST/$f" 2>/dev/null || true fi done # ── 3. Create untracked .local stub files ───────────────────────────────────── create_stub() { local file="$1" comment="$2" if [[ ! -f "$file" ]]; then echo "# $comment" > "$file" echo " created stub → $file" else echo " exists (skipped) → $file" fi } create_stub "$HOME/.zshrc.local" "Per-machine zsh overrides — never committed" create_stub "$HOME/.bashrc.local" "Per-machine bash overrides — never committed" create_stub "$HOME/.tmux.conf.machine.local" "Per-machine tmux overrides — never committed" create_stub "$HOME/.gitconfig.local" "Per-machine git identity — never committed" # ── 4. Inject profile into .zshrc.local if requested ────────────────────────── if [[ "$PROFILE" == "work" ]]; then if ! grep -q "DOTFILES_PROFILE" "$HOME/.zshrc.local" 2>/dev/null; then echo "" >> "$HOME/.zshrc.local" echo "# Work profile — load work-specific shell config and nvim plugins" >> "$HOME/.zshrc.local" echo "export DOTFILES_PROFILE=work" >> "$HOME/.zshrc.local" echo "source ~/.config/shell/work" >> "$HOME/.zshrc.local" echo " → injected DOTFILES_PROFILE=work into ~/.zshrc.local" fi fi # ── 5. macOS-specific setup ─────────────────────────────────────────────────── if [[ "$(uname -s)" == "Darwin" ]]; then # Install Homebrew if missing if ! command -v brew >/dev/null 2>&1; then echo " Installing Homebrew…" /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" fi fi echo "" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo " Done! Next steps:" echo " 1. Edit ~/.zshrc.local — add secrets / tokens" echo " 2. Edit ~/.gitconfig.local — add your git identity for this machine" echo " 3. Run: exec zsh (or source ~/.bashrc for bash)" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"