Skip to content

Instantly share code, notes, and snippets.

@mrclrchtr
Created February 16, 2026 09:57
Show Gist options
  • Select an option

  • Save mrclrchtr/1c776e83683a2ad0206602142d7982bd to your computer and use it in GitHub Desktop.

Select an option

Save mrclrchtr/1c776e83683a2ad0206602142d7982bd to your computer and use it in GitHub Desktop.
Bootstrap fresh macOS with Xcode CLT, Homebrew, and chezmoi
#!/usr/bin/env bash
set -euo pipefail
if [[ "$(uname -s)" != "Darwin" ]]; then
echo "This bootstrap script is for macOS only." >&2
exit 1
fi
if ! xcode-select -p >/dev/null 2>&1; then
echo "==> Installing Xcode Command Line Tools"
xcode-select --install || true
echo
echo "Complete the Xcode Command Line Tools installation, then rerun this script."
exit 1
else
echo "==> Xcode Command Line Tools already installed"
fi
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)"
else
echo "==> Homebrew already installed"
fi
# Homebrew may not be in PATH yet in the current shell.
if ! command -v brew >/dev/null 2>&1; then
if [[ -x /opt/homebrew/bin/brew ]]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
elif [[ -x /usr/local/bin/brew ]]; then
eval "$(/usr/local/bin/brew shellenv)"
fi
fi
if ! command -v brew >/dev/null 2>&1; then
echo "Homebrew was installed but is still not available in PATH." >&2
echo "Open a new terminal and run this script again." >&2
exit 1
fi
if ! brew list --formula chezmoi >/dev/null 2>&1; then
echo "==> Installing chezmoi"
brew install chezmoi
else
echo "==> chezmoi already installed"
fi
source_dir="$(chezmoi source-path)"
if [[ -d "$source_dir/.git" ]]; then
echo "==> chezmoi already initialized at $source_dir"
echo "==> Running chezmoi apply"
chezmoi apply
else
echo "==> Initializing chezmoi"
chezmoi init --apply mrclrchtr
fi
echo
echo "Bootstrap complete."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment