#!/bin/sh # Shattershard terminal setup — https://shattershard.com/terminal # # curl -fsSL https://shattershard.com/setup.sh | sh # # Does the 5 steps from the page: Homebrew, zsh plugins, SF Mono Nerd Font, # the Brogrammer Terminal.app theme and ~/.zshrc (your old one is backed up). # Safe to run again. Preview without changing anything: # # curl -fsSL https://shattershard.com/setup.sh | DRY_RUN=1 sh # Everything lives in main(), called on the last line: when piped from curl, # the whole script is downloaded before anything runs. SITE="https://shattershard.com" bold() { printf '\033[1m%s\033[0m\n' "$1"; } step() { printf '\n\033[1;31m▸\033[0m \033[1m%s\033[0m\n' "$1"; } info() { printf ' %s\n' "$1"; } fail() { printf '\n\033[1;31m✗ %s\033[0m\n' "$1" >&2; exit 1; } run() { if [ -n "$DRY_RUN" ]; then printf ' \033[2m[dry run] %s\033[0m\n' "$*" else "$@" fi } ask() { # stdin is the script itself when piped, so read the answer from the terminal if [ -n "$YES" ] || [ -n "$DRY_RUN" ]; then return 0; fi if [ ! -r /dev/tty ]; then fail "No terminal to ask for confirmation. Re-run with YES=1."; fi printf '%s [y/N] ' "$1" read -r answer < /dev/tty case "$answer" in y|Y|yes|YES) return 0 ;; *) return 1 ;; esac } main() { [ "$(uname -s)" = "Darwin" ] || fail "This setup is for macOS (Terminal.app)." bold "Shattershard terminal setup" info "This will:" info " 1. install Homebrew (if missing)" info " 2. brew install zsh-autosuggestions zsh-syntax-highlighting" info " 3. brew install --cask font-sf-mono-nerd-font-ligaturized" info " 4. import the Brogrammer theme into Terminal.app and make it the default" info " 5. replace ~/.zshrc (the current one is backed up first)" [ -n "$DRY_RUN" ] && info "Dry run: nothing will be changed." echo ask "Continue?" || { info "Cancelled."; exit 0; } # 1. Homebrew step "Homebrew" if command -v brew >/dev/null 2>&1; then info "already installed: $(brew --version | head -1)" else info "installing Homebrew (it may ask for your password)" # Give the installer the real terminal, not our piped script run /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" < /dev/tty \ || fail "Homebrew installation failed." fi # Make brew usable in this shell and in future ones for prefix in /opt/homebrew /usr/local; do if [ -x "$prefix/bin/brew" ]; then eval "$("$prefix/bin/brew" shellenv)" if ! grep -qs "brew shellenv" "$HOME/.zprofile"; then info "adding brew to ~/.zprofile" if [ -z "$DRY_RUN" ]; then printf '\neval "$(%s/bin/brew shellenv)"\n' "$prefix" >> "$HOME/.zprofile" fi fi break fi done command -v brew >/dev/null 2>&1 || [ -n "$DRY_RUN" ] || fail "brew is not on PATH. Open a new terminal and run the script again." # 2. zsh plugins step "zsh plugins" for formula in zsh-autosuggestions zsh-syntax-highlighting; do if brew list --formula "$formula" >/dev/null 2>&1; then info "$formula: already installed" else run brew install "$formula" || fail "Could not install $formula." fi done # 3. Font step "SF Mono Nerd Font" if brew list --cask font-sf-mono-nerd-font-ligaturized >/dev/null 2>&1; then info "already installed" else run brew install --cask font-sf-mono-nerd-font-ligaturized || fail "Could not install the font." fi # 4. Terminal theme step "Brogrammer theme" theme="$HOME/Downloads/Brogrammer.terminal" run curl -fsSL "$SITE/assets/files/Brogrammer.terminal" -o "$theme" || fail "Could not download the theme." if defaults read com.apple.Terminal "Window Settings" 2>/dev/null | grep -q '"Brogrammer"\|Brogrammer ='; then info "already imported into Terminal.app" else info "opening it imports the profile into Terminal.app (a new window will open)" run open "$theme" [ -z "$DRY_RUN" ] && sleep 2 fi run defaults write com.apple.Terminal "Default Window Settings" -string "Brogrammer" run defaults write com.apple.Terminal "Startup Window Settings" -string "Brogrammer" info "set as the default profile for new windows" # 5. .zshrc step "~/.zshrc" backup="" if [ -f "$HOME/.zshrc" ]; then backup="$HOME/.zshrc.bak.$(date +%Y%m%d-%H%M%S)" run cp "$HOME/.zshrc" "$backup" info "backed up your current file to $backup" info "tip: move API keys and tokens from it into ~/.zsh_secrets — the new .zshrc loads that file" fi run curl -fsSL "$SITE/assets/files/zshrc.txt" -o "$HOME/.zshrc" || fail "Could not download .zshrc." echo bold "✓ Done. Open a new Terminal window to see it." [ -n "$backup" ] && info "Changed your mind? cp \"$backup\" ~/.zshrc" return 0 } main "$@"