Skip to content

Instantly share code, notes, and snippets.

@theendofline
Last active September 22, 2025 22:53
Show Gist options
  • Select an option

  • Save theendofline/2a926613f400bce5966a5a51379c8554 to your computer and use it in GitHub Desktop.

Select an option

Save theendofline/2a926613f400bce5966a5a51379c8554 to your computer and use it in GitHub Desktop.
#!/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