Last active
September 22, 2025 22:53
-
-
Save theendofline/2a926613f400bce5966a5a51379c8554 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # install-zsh-stack-macos.sh β Homebrew + zsh + Oh My Zsh + plugins (macOS) | |
| set -euo pipefail | |
| THEME="${THEME:-bira}" | |
| echo "# β Theme to install: $THEME" | |
| # 1) Homebrew | |
| 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)" | |
| 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 | |
| echo "πΊ Updating Homebrew..." | |
| brew update | |
| brew upgrade | |
| echo "πΊ Installing git, zsh, curl..." | |
| brew install git zsh curl | |
| # 2) Oh My Zsh (unattended) | |
| export RUNZSH=no CHSH=no KEEP_ZSHRC=yes | |
| echo "π‘ Installing Oh My Zsh..." | |
| curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh | sh -s -- --unattended | |
| # 3) Plugins (no declare -A; no read -d) | |
| ZSH_DIR="$HOME/.oh-my-zsh" | |
| CUSTOM_DIR="${ZSH_CUSTOM:-$ZSH_DIR/custom}" | |
| mkdir -p "$CUSTOM_DIR/plugins" | |
| echo "π Cloning plugins into $CUSTOM_DIR/plugins ..." | |
| while read -r name url; do | |
| [[ -z "${name:-}" || -z "${url:-}" ]] && continue | |
| [[ -d "$CUSTOM_DIR/plugins/$name" ]] && continue | |
| git clone --depth=1 "$url" "$CUSTOM_DIR/plugins/$name" | |
| done <<'EOF' | |
| zsh-autosuggestions https://github.com/zsh-users/zsh-autosuggestions | |
| zsh-syntax-highlighting https://github.com/zsh-users/zsh-syntax-highlighting | |
| fast-syntax-highlighting https://github.com/zdharma-continuum/fast-syntax-highlighting | |
| zsh-autocomplete https://github.com/marlonrichert/zsh-autocomplete | |
| EOF | |
| # 4) Theme (BSD sed uses -i '') | |
| echo "π¨ Setting theme \"$THEME\" ..." | |
| touch "$HOME/.zshrc" | |
| if grep -q '^ZSH_THEME=' "$HOME/.zshrc"; then | |
| sed -i '' "s/^ZSH_THEME=.*/ZSH_THEME=\"$THEME\"/" "$HOME/.zshrc" | |
| else | |
| sed -i '' "1i\\ | |
| ZSH_THEME=\"$THEME\" | |
| " "$HOME/.zshrc" | |
| fi | |
| # 5) Plugins line (recommended order) | |
| ORDERED_PLUGINS=(git zsh-autosuggestions zsh-syntax-highlighting fast-syntax-highlighting zsh-autocomplete) | |
| echo "π§© Writing plugins line ..." | |
| if grep -q '^plugins=' "$HOME/.zshrc"; then | |
| sed -i '' "s/^plugins=.*/plugins=(${ORDERED_PLUGINS[*]})/" "$HOME/.zshrc" | |
| else | |
| printf '\nplugins=(%s)\n' "${ORDERED_PLUGINS[*]}" >> "$HOME/.zshrc" | |
| fi | |
| # 6) Make Homebrew zsh default shell | |
| BREW_PREFIX="$(brew --prefix)" | |
| ZSH_PATH="$BREW_PREFIX/bin/zsh" | |
| echo "π Ensuring $ZSH_PATH is in /etc/shells ..." | |
| grep -qxF "$ZSH_PATH" /etc/shells || echo "$ZSH_PATH" | sudo tee -a /etc/shells >/dev/null | |
| if [[ "${SHELL:-}" != "$ZSH_PATH" ]]; then | |
| echo "π Changing login shell to $ZSH_PATH ..." | |
| chsh -s "$ZSH_PATH" | |
| fi | |
| echo -e "\nβ Done. Open a new Terminal/iTerm window to use zsh with your theme and plugins." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment