Last active
February 11, 2026 13:48
-
-
Save martinadamsdev/ff645269c4bc6f5501f1fc1c3966d4fc to your computer and use it in GitHub Desktop.
Mac zsh setup
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
| #!/bin/bash | |
| # ============================================================ | |
| # Mac Oh My Zsh + Starship One-Click Setup Script | |
| # Compatible with macOS default bash (3.x) | |
| # ============================================================ | |
| set -e | |
| # Colors | |
| GREEN='\033[0;32m' | |
| YELLOW='\033[1;33m' | |
| CYAN='\033[0;36m' | |
| RED='\033[0;31m' | |
| NC='\033[0m' | |
| info() { echo -e "${CYAN}[INFO]${NC} $1"; } | |
| done_() { echo -e "${GREEN}[DONE]${NC} $1"; } | |
| warn() { echo -e "${YELLOW}[WARN]${NC} $1"; } | |
| err() { echo -e "${RED}[ERROR]${NC} $1"; } | |
| echo "" | |
| echo -e "${GREEN}╔══════════════════════════════════════════════╗${NC}" | |
| echo -e "${GREEN}║ Mac Oh My Zsh + Starship One-Click Setup ║${NC}" | |
| echo -e "${GREEN}╚══════════════════════════════════════════════╝${NC}" | |
| echo "" | |
| # ============================================================ | |
| # 1. Homebrew | |
| # ============================================================ | |
| if command -v brew &>/dev/null; then | |
| done_ "Homebrew already installed: $(brew --version | head -1)" | |
| else | |
| info "Installing Homebrew..." | |
| /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" | |
| # Auto-detect Homebrew path (Apple Silicon vs Intel) | |
| if [[ -f /opt/homebrew/bin/brew ]]; then | |
| BREW_PATH="/opt/homebrew/bin/brew" | |
| elif [[ -f /usr/local/bin/brew ]]; then | |
| BREW_PATH="/usr/local/bin/brew" | |
| else | |
| err "Homebrew installation failed, please install manually" | |
| exit 1 | |
| fi | |
| # Add Homebrew to PATH (auto-detect user home directory) | |
| echo >> "$HOME/.zprofile" | |
| echo "eval \"\$(${BREW_PATH} shellenv zsh)\"" >> "$HOME/.zprofile" | |
| eval "$(${BREW_PATH} shellenv zsh)" | |
| done_ "Homebrew installed" | |
| fi | |
| # ============================================================ | |
| # 2. Oh My Zsh | |
| # ============================================================ | |
| if [[ -d "$HOME/.oh-my-zsh" ]]; then | |
| done_ "Oh My Zsh already installed" | |
| else | |
| info "Installing Oh My Zsh..." | |
| sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended | |
| done_ "Oh My Zsh installed" | |
| fi | |
| # ============================================================ | |
| # 3. Starship | |
| # ============================================================ | |
| if command -v starship &>/dev/null; then | |
| done_ "Starship already installed: $(starship --version)" | |
| else | |
| info "Installing Starship..." | |
| brew install starship | |
| done_ "Starship installed" | |
| fi | |
| # ============================================================ | |
| # 4. Fira Code Font | |
| # ============================================================ | |
| if brew list --cask font-fira-code &>/dev/null 2>&1; then | |
| done_ "Fira Code already installed" | |
| else | |
| info "Installing Fira Code..." | |
| brew install --cask font-fira-code | |
| done_ "Fira Code installed" | |
| fi | |
| # ============================================================ | |
| # 5. Plugins | |
| # ============================================================ | |
| ZSH_CUSTOM="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}" | |
| # bash 3.x compatible - no associative arrays | |
| PLUGIN_NAMES="zsh-autosuggestions zsh-syntax-highlighting autoupdate" | |
| PLUGIN_URLS="https://github.com/zsh-users/zsh-autosuggestions https://github.com/zsh-users/zsh-syntax-highlighting.git https://github.com/TamCore/autoupdate-oh-my-zsh-plugins" | |
| set -- $PLUGIN_URLS | |
| for plugin in $PLUGIN_NAMES; do | |
| url="$1"; shift | |
| if [[ -d "$ZSH_CUSTOM/plugins/$plugin" ]]; then | |
| done_ "Plugin $plugin already installed" | |
| else | |
| info "Installing plugin $plugin..." | |
| git clone --depth=1 "$url" "$ZSH_CUSTOM/plugins/$plugin" | |
| done_ "Plugin $plugin installed" | |
| fi | |
| done | |
| # ============================================================ | |
| # 6. Write ~/.zshrc | |
| # ============================================================ | |
| info "Configuring ~/.zshrc..." | |
| # Backup existing config | |
| if [[ -f "$HOME/.zshrc" ]]; then | |
| cp "$HOME/.zshrc" "$HOME/.zshrc.backup.$(date +%Y%m%d%H%M%S)" | |
| warn "Existing .zshrc backed up" | |
| fi | |
| cat > "$HOME/.zshrc" << 'ZSHRC' | |
| # ============================================================ | |
| # Performance optimization | |
| # ============================================================ | |
| DISABLE_MAGIC_FUNCTIONS="true" | |
| DISABLE_COMPFIX="true" | |
| # Cache compinit (reload once per day) | |
| autoload -Uz compinit | |
| if [ "$(date +'%j')" != "$(stat -f '%Sm' -t '%j' ~/.zcompdump 2>/dev/null)" ]; then | |
| compinit | |
| else | |
| compinit -C | |
| fi | |
| # ============================================================ | |
| # Oh My Zsh settings | |
| # ============================================================ | |
| export ZSH="$HOME/.oh-my-zsh" | |
| # Disable Oh My Zsh theme, use Starship instead | |
| ZSH_THEME="" | |
| # ============================================================ | |
| # Plugins (syntax-highlighting must be last) | |
| # ============================================================ | |
| plugins=( | |
| git | |
| macos | |
| brew | |
| z | |
| extract | |
| sudo | |
| autoupdate | |
| zsh-autosuggestions | |
| zsh-syntax-highlighting | |
| ) | |
| source $ZSH/oh-my-zsh.sh | |
| # ============================================================ | |
| # Autosuggestions settings | |
| # ============================================================ | |
| ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#999999" | |
| ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE="20" | |
| ZSH_AUTOSUGGEST_USE_ASYNC=1 | |
| # ============================================================ | |
| # Aliases | |
| # ============================================================ | |
| alias cls="clear" | |
| alias ll="ls -la" | |
| alias la="ls -A" | |
| alias ..="cd .." | |
| alias ...="cd ../.." | |
| alias ....="cd ../../.." | |
| # Git shortcuts | |
| alias gs="git status" | |
| alias gp="git push" | |
| alias gl="git pull" | |
| alias gco="git checkout" | |
| alias gcm="git commit -m" | |
| alias gd="git diff" | |
| alias gb="git branch" | |
| alias glog="git log --oneline --graph --decorate" | |
| # Homebrew maintenance | |
| alias brewup='brew update && brew upgrade --greedy && brew autoremove && brew cleanup --prune=all -s && brew doctor' | |
| # ============================================================ | |
| # Environment variables | |
| # ============================================================ | |
| export EDITOR="vim" | |
| export LANG="en_US.UTF-8" | |
| # ============================================================ | |
| # Starship prompt (must be at the end) | |
| # ============================================================ | |
| eval "$(starship init zsh)" | |
| ZSHRC | |
| done_ "~/.zshrc configured" | |
| # ============================================================ | |
| # 7. Starship config | |
| # ============================================================ | |
| info "Configuring Starship..." | |
| mkdir -p "$HOME/.config" | |
| cat > "$HOME/.config/starship.toml" << 'STARSHIP' | |
| format = """ | |
| $directory\ | |
| $git_branch\ | |
| $git_status\ | |
| $python\ | |
| $nodejs\ | |
| $rust\ | |
| $golang\ | |
| $docker_context\ | |
| $line_break\ | |
| $character""" | |
| right_format = """$cmd_duration""" | |
| add_newline = true | |
| [character] | |
| success_symbol = "[❯](bold green)" | |
| error_symbol = "[❯](bold red)" | |
| [directory] | |
| truncation_length = 3 | |
| truncation_symbol = "…/" | |
| style = "bold cyan" | |
| [git_branch] | |
| format = " [$symbol$branch]($style)" | |
| symbol = " " | |
| style = "bold purple" | |
| [git_status] | |
| format = "[$all_status$ahead_behind]($style) " | |
| style = "bold red" | |
| [cmd_duration] | |
| min_time = 3_000 | |
| format = "[$duration]($style)" | |
| style = "bold yellow" | |
| [python] | |
| format = " [${symbol}${version}]($style)" | |
| symbol = " " | |
| style = "bold yellow" | |
| [nodejs] | |
| format = " [${symbol}${version}]($style)" | |
| symbol = " " | |
| style = "bold green" | |
| [rust] | |
| format = " [${symbol}${version}]($style)" | |
| symbol = " " | |
| style = "bold red" | |
| [golang] | |
| format = " [${symbol}${version}]($style)" | |
| symbol = " " | |
| style = "bold cyan" | |
| [docker_context] | |
| format = " [${symbol}${context}]($style)" | |
| symbol = " " | |
| style = "bold blue" | |
| STARSHIP | |
| done_ "Starship configured" | |
| # ============================================================ | |
| # Done | |
| # ============================================================ | |
| echo "" | |
| echo -e "${GREEN}╔══════════════════════════════════════════════╗${NC}" | |
| echo -e "${GREEN}║ ✅ Setup complete! ║${NC}" | |
| echo -e "${GREEN}╚══════════════════════════════════════════════╝${NC}" | |
| echo "" | |
| echo -e " 📁 Config: ${CYAN}~/.zshrc${NC}" | |
| echo -e " ⭐ Starship: ${CYAN}~/.config/starship.toml${NC}" | |
| echo -e " 🔤 Font: ${CYAN}Fira Code${NC}" | |
| echo "" | |
| echo -e " ${YELLOW}⚠️ Please set your terminal font to Fira Code${NC}" | |
| echo -e " ${YELLOW}⚠️ Then run: source ~/.zshrc or restart your terminal${NC}" | |
| echo "" |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
bash <(curl -fsSL https://gist.githubusercontent.com/martinadamsdev/ff645269c4bc6f5501f1fc1c3966d4fc/raw/mac-setup-zsh.sh)