Last active
January 19, 2026 12:45
-
-
Save brei0x/42e9a1b65ecec83b0432331616baf4ee to your computer and use it in GitHub Desktop.
Install Zsh + Oh My Zsh + Powerlevel10k theme (macOS & Linux)
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 | |
| # Install Zsh + Oh My Zsh + Powerlevel10k theme (macOS & Linux) | |
| # This script is idempotent! | |
| # To run this script: | |
| # 1. Execute: sh -c "$(curl -fsSL "$(curl -s "https://api.github.com/gists/42e9a1b65ecec83b0432331616baf4ee" | grep -o '"raw_url": *"[^"]*"' | cut -d'"' -f4)")" | |
| # This script installs and configures the following: | |
| # 1. Zsh and Git | |
| # 2. Oh My Zsh | |
| # 3. Powerlevel10k theme for Zsh | |
| # 4. Custom aliases and configurations in .zshrc | |
| # 5. Sets Zsh as the default shell | |
| # Colors | |
| GREEN='\033[0;32m' | |
| YELLOW='\033[1;33m' | |
| RED='\033[0;31m' | |
| CYAN='\033[0;36m' | |
| NC='\033[0m' | |
| # Logging functions | |
| log_info() { echo -e "${GREEN}[INFO]${NC} $1"; } | |
| log_warning() { echo -e "${YELLOW}[WARNING]${NC} $1"; } | |
| log_error() { echo -e "${RED}[ERROR]${NC} $1"; } | |
| # Function to check if a command exists | |
| command_exists() { | |
| command -v "$1" > /dev/null 2>&1 | |
| } | |
| # Function to add line to a file if it does not already exist | |
| add_line() { | |
| local line="$1" | |
| local file="$2" | |
| if ! grep -Fxq "$line" "$file"; then | |
| echo "$line" >> "$file" | |
| fi | |
| } | |
| # Function to display the p10k preset menu | |
| select_p10k_preset() { | |
| echo "" | |
| echo -e "${CYAN}Select a Powerlevel10k configuration:${NC}" | |
| echo "" | |
| echo " 1) brei0x - Custom configuration (brei0x)" | |
| echo " 2) Classic - Classic style with icons" | |
| echo " 3) Lean - Minimalist and clean" | |
| echo " 4) Lean 8colors - Lean with 8 colors only" | |
| echo " 5) Pure - Ultra-minimalist (Pure style)" | |
| echo " 6) Rainbow - Colorful with rainbow segments" | |
| echo " 7) Robbyrussell - oh-my-zsh default style" | |
| echo "" | |
| read -rp "Enter your choice [1-7] (default: 1): " choice | |
| case "${choice:-1}" in | |
| 1) | |
| P10K_PRESET="brei0x" | |
| P10K_URL="$(curl -s "https://api.github.com/gists/18828f196299e886b32a36a9c738baf2" | grep -o '"raw_url": *"[^"]*"' | cut -d'"' -f4)" | |
| ;; | |
| 2) | |
| P10K_PRESET="classic" | |
| P10K_URL="https://raw.githubusercontent.com/romkatv/powerlevel10k/master/config/p10k-classic.zsh" | |
| ;; | |
| 3) | |
| P10K_PRESET="lean" | |
| P10K_URL="https://raw.githubusercontent.com/romkatv/powerlevel10k/master/config/p10k-lean.zsh" | |
| ;; | |
| 4) | |
| P10K_PRESET="lean-8colors" | |
| P10K_URL="https://raw.githubusercontent.com/romkatv/powerlevel10k/master/config/p10k-lean-8colors.zsh" | |
| ;; | |
| 5) | |
| P10K_PRESET="pure" | |
| P10K_URL="https://raw.githubusercontent.com/romkatv/powerlevel10k/master/config/p10k-pure.zsh" | |
| ;; | |
| 6) | |
| P10K_PRESET="rainbow" | |
| P10K_URL="https://raw.githubusercontent.com/romkatv/powerlevel10k/master/config/p10k-rainbow.zsh" | |
| ;; | |
| 7) | |
| P10K_PRESET="robbyrussell" | |
| P10K_URL="https://raw.githubusercontent.com/romkatv/powerlevel10k/master/config/p10k-robbyrussell.zsh" | |
| ;; | |
| *) | |
| log_warning "Invalid choice. Using brei0x preset." | |
| P10K_PRESET="brei0x" | |
| P10K_URL="$(curl -s "https://api.github.com/gists/18828f196299e886b32a36a9c738baf2" | grep -o '"raw_url": *"[^"]*"' | cut -d'"' -f4)" | |
| ;; | |
| esac | |
| } | |
| # Check OS compatibility | |
| OS="$(uname -s)" | |
| if [ "$OS" != "Darwin" ] && [ "$OS" != "Linux" ]; then | |
| log_error "This script is designed to run on macOS or Linux. Exiting." | |
| exit 1 | |
| fi | |
| # Install Zsh and Git | |
| if [ "$OS" = "Darwin" ]; then | |
| if ! command_exists zsh; then | |
| log_info "Installing Zsh..." | |
| brew install zsh | |
| else | |
| log_info "Zsh is already installed." | |
| fi | |
| if ! command_exists git; then | |
| log_info "Installing Git..." | |
| brew install git | |
| else | |
| log_info "Git is already installed." | |
| fi | |
| else | |
| if ! command_exists zsh; then | |
| log_info "Installing Zsh..." | |
| sudo apt install -y zsh | |
| else | |
| log_info "Zsh is already installed." | |
| fi | |
| if ! command_exists git; then | |
| log_info "Installing Git..." | |
| sudo apt install -y git | |
| else | |
| log_info "Git is already installed." | |
| fi | |
| fi | |
| # Install Oh My Zsh | |
| if [ -d "$HOME/.oh-my-zsh" ]; then | |
| log_info "Oh My Zsh is already installed." | |
| else | |
| log_info "Installing Oh My Zsh..." | |
| sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended | |
| fi | |
| # Add aliases to .zshrc | |
| log_info "Configuring aliases in .zshrc..." | |
| add_line 'alias az-clean-history-and-exit="history -c && exit"' ~/.zshrc | |
| if [ "$OS" = "Darwin" ]; then | |
| add_line 'alias az-maintenance-packages="~/.local/bin/maintenance-packages"' ~/.zshrc | |
| fi | |
| # Install Powerlevel10k theme | |
| P10K_DIR="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k" | |
| if [ -d "$P10K_DIR" ]; then | |
| log_info "Powerlevel10k is already installed. Updating..." | |
| git -C "$P10K_DIR" pull --quiet | |
| else | |
| log_info "Installing Powerlevel10k theme..." | |
| git clone --depth=1 https://github.com/romkatv/powerlevel10k.git "$P10K_DIR" | |
| fi | |
| # Configure Powerlevel10k theme in .zshrc | |
| log_info "Setting Powerlevel10k as the Zsh theme..." | |
| if [ "$OS" = "Darwin" ]; then | |
| sed -i "" 's/ZSH_THEME=".*"/ZSH_THEME="powerlevel10k\/powerlevel10k"/g' ~/.zshrc | |
| else | |
| sed -i 's/ZSH_THEME=".*"/ZSH_THEME="powerlevel10k\/powerlevel10k"/g' ~/.zshrc | |
| fi | |
| # Add Powerlevel10k instant prompt configuration to .zshrc | |
| INSTANT_PROMPT_MARKER="p10k-instant-prompt" | |
| INSTANT_PROMPT_BLOCK=' | |
| # Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc. | |
| # Initialization code that may require console input (password prompts, [y/n] | |
| # confirmations, etc.) must go above this block; everything else may go below. | |
| if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then | |
| source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" | |
| fi | |
| ' | |
| if ! grep -Fq "$INSTANT_PROMPT_MARKER" ~/.zshrc; then | |
| log_info "Adding Powerlevel10k instant prompt configuration..." | |
| echo "$INSTANT_PROMPT_BLOCK" >> ~/.zshrc | |
| else | |
| log_info "Powerlevel10k instant prompt is already configured." | |
| fi | |
| # Add Powerlevel10k source configuration to .zshrc | |
| P10K_SOURCE_MARKER="source ~/.p10k.zsh" | |
| P10K_SOURCE_BLOCK=' | |
| # To customize prompt, run `p10k configure` or edit ~/.p10k.zsh. | |
| [[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh | |
| ' | |
| if ! grep -Fq "$P10K_SOURCE_MARKER" ~/.zshrc; then | |
| log_info "Adding Powerlevel10k source configuration..." | |
| echo "$P10K_SOURCE_BLOCK" >> ~/.zshrc | |
| else | |
| log_info "Powerlevel10k source is already configured." | |
| fi | |
| # Select and download Powerlevel10k configuration | |
| select_p10k_preset | |
| log_info "Downloading Powerlevel10k configuration (${P10K_PRESET})..." | |
| if [ -f "$HOME/.p10k.zsh" ]; then | |
| rm -f ~/.p10k.zsh | |
| fi | |
| curl -fsSL -H "Cache-Control: no-cache" "$P10K_URL" -o ~/.p10k.zsh | |
| # Set Zsh as the default shell | |
| CURRENT_SHELL="$(basename "$SHELL")" | |
| if [ "$CURRENT_SHELL" = "zsh" ]; then | |
| log_info "Zsh is already the default shell." | |
| else | |
| log_info "Setting Zsh as the default shell..." | |
| if [ "$OS" = "Darwin" ]; then | |
| chsh -s /bin/zsh | |
| else | |
| sudo usermod -s /bin/zsh "$(whoami)" | |
| fi | |
| fi | |
| echo "" | |
| log_info "Installation complete! (p10k preset: ${P10K_PRESET})" | |
| log_warning "To download fonts for Powerlevel10k, visit: https://github.com/romkatv/powerlevel10k?tab=readme-ov-file#manual-font-installation" | |
| log_info "To start Zsh and replace the current shell session, run: ${YELLOW}exec zsh${NC}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment