#!/bin/sh # curl -fsSL https://setup.jimbos.computer | sh # # stdin is this script when piped, so anything interactive reads from /dev/tty. # Everything runs from main on the last line, so a truncated download does nothing. set -eu DOTFILES_REPOSITORY="JimJoyce/dotfiles" DOTFILES_DIRECTORY="$HOME/dotfiles" HOMEBREW_PREFIX="/opt/homebrew" HOMEBREW_INSTALL_URL="https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh" announce_step() { printf '\n\033[1;35m==> %s\033[0m\n' "$1" } install_homebrew() { announce_step "Installing Homebrew and the Xcode command line tools" [ -x "$HOMEBREW_PREFIX/bin/brew" ] && return 0 /bin/bash -c "$(curl -fsSL "$HOMEBREW_INSTALL_URL")" < /dev/tty } sign_in_to_github() { announce_step "Signing in to GitHub (creates and uploads an SSH key)" brew install gh gh auth status > /dev/null 2>&1 && return 0 gh auth login --hostname github.com --git-protocol ssh --web < /dev/tty gh auth setup-git } clone_or_update_dotfiles() { announce_step "Fetching $DOTFILES_REPOSITORY into $DOTFILES_DIRECTORY" if [ -d "$DOTFILES_DIRECTORY/.git" ]; then git -C "$DOTFILES_DIRECTORY" pull --ff-only else gh repo clone "$DOTFILES_REPOSITORY" "$DOTFILES_DIRECTORY" fi } main() { install_homebrew eval "$("$HOMEBREW_PREFIX/bin/brew" shellenv)" sign_in_to_github clone_or_update_dotfiles "$DOTFILES_DIRECTORY/install.sh" all < /dev/tty announce_step "Done. Open a new terminal. Recreate ~/.gitconfig.user if you need the extra credentials." } main