#!/usr/bin/env bash set -euo pipefail # Fresh Mac setup. Safe to run via: curl -fsSL | bash # Installs iTerm2, Oh My Zsh, Node.js, and Fira Code if they are missing. # Homebrew is installed first when needed. if [[ "$(uname -s)" != "Darwin" ]]; then echo "new-setup.sh is meant for macOS." >&2 exit 1 fi log() { printf '%s\n' "$*" } already() { log "Already installed: $1" } ensure_brew() { if command -v brew >/dev/null 2>&1; then return fi if [[ -x /opt/homebrew/bin/brew ]]; then eval "$(/opt/homebrew/bin/brew shellenv)" return fi if [[ -x /usr/local/bin/brew ]]; then eval "$(/usr/local/bin/brew shellenv)" return fi log "Installing Homebrew..." NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" 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 if ! command -v brew >/dev/null 2>&1; then echo "Homebrew installed, but brew is not on PATH. Open a new terminal and re-run." >&2 exit 1 fi } has_iterm() { [[ -d /Applications/iTerm.app ]] || [[ -d "${HOME}/Applications/iTerm.app" ]] } has_ohmyzsh() { [[ -d "${ZSH:-${HOME}/.oh-my-zsh}" ]] } has_node() { command -v node >/dev/null 2>&1 } has_fira_code() { local found found="$(find "${HOME}/Library/Fonts" /Library/Fonts /opt/homebrew/share/fonts \ -iname '*Fira*Code*' 2>/dev/null | head -n 1 || true)" [[ -n "$found" ]] } install_iterm() { if has_iterm; then already "iTerm2" return fi log "Installing iTerm2..." brew install --cask iterm2 } install_ohmyzsh() { if has_ohmyzsh; then already "Oh My Zsh" return fi if ! command -v zsh >/dev/null 2>&1; then log "Installing zsh..." brew install zsh fi log "Installing Oh My Zsh..." RUNZSH=no CHSH=no KEEP_ZSHRC=yes \ sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" } install_node() { if has_node; then already "Node.js ($(node -v))" return fi log "Installing Node.js..." brew install node } install_fira_code() { if has_fira_code; then already "Fira Code" return fi log "Installing Fira Code..." brew install --cask font-fira-code } log "Checking prerequisites..." ensure_brew brew update install_iterm install_ohmyzsh install_node install_fira_code log "Done. New software is on this Mac if it was missing."