Oh My Zsh: The Ultimate Guide

Okay, here’s a comprehensive article on Oh My Zsh, aiming for approximately 5000 words. I’ve broken it down into logical sections and subsections to make it easier to navigate and read.

Oh My Zsh: The Ultimate Guide

Table of Contents

  1. Introduction: What is Oh My Zsh (and Why Should You Care?)

    • 1.1. Beyond the Basic Shell
    • 1.2. The Power of Customization
    • 1.3. The Community Factor
    • 1.4. Who is This Guide For?
    • 1.5 What is a Shell?
    • 1.6 What is Zsh?
    • 1.7 Key Benefits of using Oh My Zsh
  2. Installation and Setup

    • 2.1. Prerequisites: Zsh and curl or wget
    • 2.2. Installation Methods
      • 2.2.1. Via curl
      • 2.2.2. Via wget
      • 2.2.3. Manual Installation (Advanced)
      • 2.2.4. Using Package Managers (e.g., apt, brew, pacman)
    • 2.3. Setting Zsh as Your Default Shell
    • 2.4. Initial Configuration: The .zshrc File
    • 2.5. Troubleshooting Installation Issues
      • 2.5.1 Permission Issues
      • 2.5.2 Network Connectivity Problems
      • 2.5.3 Zsh Not Found Errors
  3. Understanding the .zshrc File

    • 3.1. The Heart of Oh My Zsh Configuration
    • 3.2. Key Sections and Settings
      • 3.2.1. ZSH (Oh My Zsh Installation Path)
      • 3.2.2. plugins
      • 3.2.3. theme
      • 3.2.4. export PATH (and other environment variables)
      • 3.2.5. Aliases
      • 3.2.6. Functions
      • 3.2.7. Custom Code Blocks
    • 3.3. Best Practices for Editing .zshrc
      • 3.3.1. Backups!
      • 3.3.2. Comments
      • 3.3.3. Version Control (Git)
      • 3.3.4. Modularity (Sourcing other files)
    • 3.4. Reloading .zshrc (source ~/.zshrc)
  4. Themes: Giving Your Terminal a Makeover

    • 4.1. Built-in Themes
      • 4.1.1. robbyrussell (The Default)
      • 4.1.2. agnoster (Powerline-inspired)
      • 4.1.3. bira (Simple and Clean)
      • 4.1.4. spaceship (Highly Configurable)
      • 4.1.5 And many others
    • 4.2. External Themes
      • 4.2.1. Powerlevel10k (Highly Recommended)
        • 4.2.1.1 Installation
        • 4.2.1.2 Configuration Wizard (p10k configure)
        • 4.2.1.3 Customization Options
      • 4.2.2. Other Popular External Themes
    • 4.3. Creating Your Own Theme
      • 4.3.1. Theme Structure
      • 4.3.2. Prompt Variables (e.g., %n, %m, %d, %~)
      • 4.3.3. Colors and Styling
      • 4.3.4. Conditional Segments
    • 4.4. Managing Themes (Switching, Updating)
    • 4.5 Fonts and Icons
      • 4.5.1 Nerd Fonts
      • 4.5.2 Powerline Fonts
  5. Plugins: Supercharging Your Shell Functionality

    • 5.1. Built-in Plugins
      • 5.1.1. git (Essential Git Enhancements)
      • 5.1.2. zsh-autosuggestions (Fish-like Autocompletion)
      • 5.1.3. zsh-syntax-highlighting (Real-time Syntax Highlighting)
      • 5.1.4. docker (Docker Command Completion)
      • 5.1.5. kubectl (Kubernetes Command Completion)
      • 5.1.6. python (Python Environment Management)
      • 5.1.7. node (Node.js and npm Helpers)
      • 5.1.8. sudo (Easily Prefix Commands with sudo)
      • 5.1.9. history (Enhanced History Management)
      • 5.1.10. colored-man-pages (Colorized Man Pages)
      • 5.1.11. extract (Universal archive extraction)
      • 5.1.12 And many more…
    • 5.2. External Plugins
      • 5.2.1. Finding External Plugins (Awesome Zsh, GitHub, etc.)
      • 5.2.2. Installing External Plugins (Manual and Plugin Managers)
    • 5.3. Plugin Managers
      • 5.3.1. Antigen (Popular and Versatile)
      • 5.3.2. Zplugin (Fast and Flexible)
      • 5.3.3. zinit (Turbo-charged plugin loader)
      • 5.3.4. Comparison of Plugin Managers
    • 5.4. Creating Your Own Plugin
      • 5.4.1. Plugin Structure
      • 5.4.2. Adding Functions and Aliases
      • 5.4.3. Completion Functions
    • 5.5 Managing Plugins.
    • 5.6 Plugin Loading Order.
  6. Aliases: Shortcuts for Your Frequent Commands

    • 6.1. The Basics of Aliases
    • 6.2. Common and Useful Aliases
      • 6.2.1. Git Aliases (ga, gc, gp, etc.)
      • 6.2.2. Navigation Aliases (.., ..., cd -)
      • 6.2.3. System Aliases (la, ll, grep)
      • 6.2.4. Custom Aliases for Your Workflow
    • 6.3. Global Aliases
    • 6.4. Suffix Aliases
    • 6.5. Managing Aliases (Listing, Removing)
  7. Functions: Adding More Complex Logic

    • 7.1. When to Use Functions Instead of Aliases
    • 7.2. Basic Function Syntax
    • 7.3. Passing Arguments to Functions
    • 7.4. Return Values
    • 7.5. Local Variables
    • 7.6. Example Functions
      • 7.6.1. Creating Directories and Navigating
      • 7.6.2. Custom Git Workflows
      • 7.6.3. System Information Display
    • 7.7 Advanced Function Techniques
    • 7.7.1 Function Autoloading
    • 7.7.2 Using Functions in Completions
  8. Customizing Your Prompt

    • 8.1. Understanding Prompt Variables (PROMPT, RPROMPT, etc.)
    • 8.2. Adding Dynamic Information (Git Branch, Time, User, Host)
    • 8.3. Using Colors and Special Characters
    • 8.4. Conditional Prompt Segments (e.g., only show Git info in a Git repo)
    • 8.5. Multi-line Prompts
    • 8.6. Transient Prompts
  9. Advanced Oh My Zsh Techniques

    • 9.1. Zsh Completion System (compinit, compdef)
      • 9.1.1. Understanding Completion Functions
      • 9.1.2. Writing Custom Completion Functions
    • 9.2. Zsh Hooks (e.g., precmd, preexec, chpwd)
      • 9.2.1. Running Commands Before/After Other Commands
      • 9.2.2. Customizing Shell Behavior on Directory Change
    • 9.3. Zsh Options (e.g., setopt, unsetopt)
      • 9.3.1. Controlling Shell Behavior
      • 9.3.2. Useful Options for Productivity
    • 9.4. Zsh Modules (e.g., zsh/zprof, zsh/datetime)
    • 9.5. Using zsh for Scripting
    • 9.6. Zsh Line Editor (zle)
    • 9.7. Zsh Builtins
  10. Troubleshooting and Common Issues

    • 10.1. Slow Startup Time
      • 10.1.1. Profiling Startup (zsh -xv)
      • 10.1.2. Optimizing Plugin Loading
      • 10.1.3. Lazy Loading Plugins
    • 10.2. Plugin Conflicts
    • 10.3. Theme Rendering Issues
      • 10.3.1. Font Problems
      • 10.3.2. Unicode Character Support
    • 10.4. .zshrc Errors
      • 10.4.1. Syntax Errors
      • 10.4.2. Missing Commands
    • 10.5. Updating Oh My Zsh (upgrade_oh_my_zsh)
    • 10.6. Uninstalling Oh My Zsh
  11. Community and Resources

    • 11.1. The Oh My Zsh GitHub Repository
    • 11.2. Awesome Zsh List
    • 11.3. Online Forums and Communities (Reddit, Stack Overflow)
    • 11.4. Zsh Documentation
  12. Conclusion: Taking Your Shell to the Next Level


1. Introduction: What is Oh My Zsh (and Why Should You Care?)

1.1. Beyond the Basic Shell

The command-line interface (CLI), often accessed through a terminal emulator, is a fundamental tool for developers, system administrators, and power users. It provides a direct and powerful way to interact with your operating system. However, the default shell (often Bash on Linux and macOS) can feel clunky, inefficient, and visually unappealing. This is where Oh My Zsh comes in.

1.2. The Power of Customization

Oh My Zsh is an open-source, community-driven framework for managing your Zsh (Z shell) configuration. It’s not a replacement for Zsh itself; rather, it’s a layer on top of Zsh that provides a vast collection of plugins, themes, and helper functions to enhance your shell experience. Think of it as a highly customizable and extensible toolbox for your terminal. It lets you tailor your shell to your specific needs and preferences, making your workflow faster, more efficient, and more enjoyable.

1.3. The Community Factor

One of Oh My Zsh’s greatest strengths is its vibrant and active community. Thousands of users and contributors have created a wealth of plugins and themes, and they actively share tips, tricks, and solutions to common problems. This collaborative environment means you’re not alone in your customization journey; you have access to a vast knowledge base and a supportive community.

1.4. Who is This Guide For?

This guide is for anyone who uses the command line and wants to improve their productivity and overall experience. Whether you’re a seasoned developer, a budding system administrator, or just someone who spends a significant amount of time in the terminal, this guide will provide you with the knowledge and tools you need to master Oh My Zsh. Some prior familiarity with the command line is helpful, but even beginners can benefit from learning about the power of Zsh and Oh My Zsh.

1.5 What is a Shell?
A shell is a command-line interpreter that provides a user interface for accessing an operating system’s services. Think of the shell as a translator between you and the complex inner workings of your computer. You type commands in human-readable text, and the shell translates those commands into instructions the operating system can understand.

1.6 What is Zsh?
Zsh, or the Z shell, is a powerful, highly customizable Unix shell.
* Extended Functionality: It builds upon the features of other shells like Bash (Bourne Again Shell) and ksh (Korn Shell), adding significant improvements and new capabilities.
* Enhanced Autocompletion: Zsh has far superior autocompletion compared to Bash. It can complete not just filenames and commands, but also options, arguments, and even code snippets in some cases.
* Powerful Globbing: Globbing is a way to use wildcards to match filenames. Zsh’s globbing capabilities are much more sophisticated, allowing for complex pattern matching.
* Spelling Correction: Zsh can automatically correct minor typos in commands, saving you time and frustration.
* Plugin and Theme Support: This is where Oh My Zsh comes in, but Zsh itself has a robust plugin and theme architecture.
* History Subsystem: Zsh has a great history management system.

1.7 Key Benefits of using Oh My Zsh

  • Increased Productivity: Automate repetitive tasks, use powerful autocompletion, and navigate your file system more efficiently.
  • Improved Workflow: Tailor your shell to your specific needs, integrating with your favorite tools and development environments.
  • Enhanced User Experience: Make your terminal visually appealing and informative with custom themes and prompts.
  • Community Support: Benefit from the collective knowledge and contributions of a large and active community.
  • Easy Customization: Manage your Zsh configuration with a simple and intuitive framework.

2. Installation and Setup

2.1. Prerequisites: Zsh and curl or wget

Before installing Oh My Zsh, you need to have Zsh installed on your system. You’ll also need either curl or wget, which are command-line tools for downloading files.

  • Checking for Zsh:
    Open a terminal and type:
    bash
    zsh --version

    If Zsh is installed, you’ll see its version number. If not, you’ll need to install it.

  • Checking for curl and wget:
    bash
    curl --version
    wget --version

    If either of these commands returns a version number, you’re good to go. If not, you’ll need to install one of them.

  • Installing Zsh (if needed):
    The installation process varies depending on your operating system:

    • Debian/Ubuntu:
      bash
      sudo apt update
      sudo apt install zsh
    • Fedora/CentOS/RHEL:
      bash
      sudo dnf install zsh # Or sudo yum install zsh on older systems
    • macOS (using Homebrew):
      bash
      brew install zsh
    • Arch Linux:
      bash
      sudo pacman -S zsh
    • Windows (using WSL): Zsh should be available in your chosen Linux distribution within WSL. Follow the instructions for that distribution (e.g., Debian/Ubuntu).
  • Installing curl or wget (if needed):
    Follow the same process as above, replacing zsh with curl or wget in the appropriate package manager command.

2.2. Installation Methods

2.2.1. Via curl

This is the most common and recommended method. Open your terminal and run:

bash
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

This command downloads the install.sh script from the Oh My Zsh GitHub repository and executes it. The script will:

  1. Clone the Oh My Zsh repository to ~/.oh-my-zsh.
  2. Back up your existing .zshrc file (if one exists) to something like .zshrc.pre-oh-my-zsh.
  3. Create a new .zshrc file that includes Oh My Zsh’s configuration.
  4. Prompt you to set Zsh as your default shell (more on this below).

2.2.2. Via wget

If you prefer wget, use this command:

bash
sh -c "$(wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)"

This does the same thing as the curl command.

2.2.3. Manual Installation (Advanced)

This method gives you more control but requires more manual steps. It’s generally not recommended unless you have a specific reason to avoid the automated scripts.

  1. Clone the repository:
    bash
    git clone https://github.com/ohmyzsh/ohmyzsh.git ~/.oh-my-zsh

  2. Back up your existing .zshrc (if it exists):
    bash
    cp ~/.zshrc ~/.zshrc.pre-oh-my-zsh

  3. Create a new .zshrc from the template:
    bash
    cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc

  4. Set Zsh as default shell.

2.2.4. Using Package Managers (e.g., apt, brew, pacman)

While you can sometimes install Oh My Zsh through package managers, this is not the recommended approach. The version in the package repositories is often outdated, and you might miss out on the latest features and bug fixes. It’s best to use the curl or wget method to install directly from the official repository.

2.3. Setting Zsh as Your Default Shell

After installation, you’ll likely be prompted to set Zsh as your default shell. If you weren’t, or if you want to do it manually, use the chsh (change shell) command:

bash
chsh -s $(which zsh)

* chsh -s: This tells the chsh command to change the login shell.
* $(which zsh): This finds the full path to the Zsh executable (e.g., /usr/bin/zsh or /bin/zsh). This ensures you’re using the correct Zsh installation.

You’ll need to log out and log back in (or open a new terminal window) for the change to take effect. To verify that Zsh is your default shell, open a new terminal and run:

bash
echo $SHELL

This should output the path to your Zsh executable.

2.4. Initial Configuration: The .zshrc File

The .zshrc file is the main configuration file for Zsh and Oh My Zsh. It’s located in your home directory (~/.zshrc). Oh My Zsh’s installation script creates a basic .zshrc file for you, but you’ll customize it extensively to tailor your shell environment. We’ll cover this in detail in the next section.

2.5. Troubleshooting Installation Issues

2.5.1 Permission Issues
If the installation script fails due to permission errors, make sure you have write access to your home directory. You might need to use sudo before the chsh command if you’re changing the shell for a user other than yourself. Never use sudo with the main Oh My Zsh installation command (sh -c ...).

2.5.2 Network Connectivity Problems
If you get errors about being unable to download the installation script, check your internet connection. You might also be behind a firewall or proxy that’s blocking access to GitHub.

2.5.3 Zsh Not Found Errors
If you get an error saying zsh is not found, even after installing it, double-check that it was installed correctly and that it’s in your system’s PATH. The output of which zsh should give you a valid path. If it doesn’t, the Zsh executable might not be where your system expects it to be. Reinstalling Zsh might help.


3. Understanding the .zshrc File

3.1. The Heart of Oh My Zsh Configuration

The .zshrc file is a shell script that’s executed every time you start a new interactive, non-login Zsh session. This means it runs when you open a new terminal window or tab. It’s where you define your aliases, functions, environment variables, plugin settings, theme, and any other customizations you want to apply to your shell.

3.2. Key Sections and Settings

Let’s break down the most important parts of a typical .zshrc file created by Oh My Zsh:

3.2.1. ZSH (Oh My Zsh Installation Path)

bash
ZSH="$HOME/.oh-my-zsh"

This line sets the ZSH environment variable to the directory where Oh My Zsh is installed. This variable is used by Oh My Zsh to locate its plugins, themes, and other files. You generally shouldn’t need to modify this.

3.2.2. plugins

bash
plugins=(
git
zsh-autosuggestions
zsh-syntax-highlighting
)

This is where you list the plugins you want to enable. Each plugin is a directory within $ZSH/plugins (or in a custom plugin directory) that contains scripts to enhance your shell. We’ll discuss plugins in detail later. The order of plugins can matter, as some plugins might depend on others or have conflicting configurations.

3.2.3. theme

bash
ZSH_THEME="robbyrussell"

This line sets your shell theme. Themes control the appearance of your prompt and other visual elements. robbyrussell is the default theme. We’ll dive deep into themes in a dedicated section.

3.2.4. export PATH (and other environment variables)

bash
export PATH="$HOME/bin:$PATH"
export EDITOR="nano"

  • PATH: This is a crucial environment variable. It’s a colon-separated list of directories where your shell looks for executable programs. When you type a command, the shell searches these directories in order. The example above adds $HOME/bin (your personal bin directory) to the beginning of the PATH. It’s common to add other directories here, such as those containing custom scripts or tools.
  • EDITOR: This sets your preferred text editor. Many command-line tools use this variable to determine which editor to launch. You can set it to nano, vim, emacs, code (for VS Code), or any other editor you prefer.
  • Other common Environment Variables:
    • LANG: Sets the locale for language and character encoding.
    • LC_ALL: Overrides other locale settings.
    • USER: Your username.
    • HOME: Your home directory.

3.2.5. Aliases

bash
alias la='ls -la'
alias ga='git add'
alias gc='git commit -m'

Aliases are shortcuts for commands. These examples define:

  • la: Runs ls -la (list all files, including hidden ones, in long format).
  • ga: Runs git add.
  • gc: Runs git commit -m (allowing you to quickly commit with a message).

3.2.6. Functions

bash
mkcd() {
mkdir -p "$1" && cd "$1"
}

Functions are more complex than aliases; they can contain multiple commands and logic. This example defines a function mkcd that creates a directory (using mkdir -p to create parent directories if needed) and then immediately changes the current directory to the newly created one.

3.2.7. Custom Code Blocks

You can include any valid Zsh code in your .zshrc. This might include:

  • Conditional statements (if, then, else).
  • Loops (for, while).
  • Case statements (case, esac).
  • Sourcing other files (see below).

3.3. Best Practices for Editing .zshrc

3.3.1. Backups!

Before making any changes to your .zshrc, create a backup:

bash
cp ~/.zshrc ~/.zshrc.bak

This allows you to easily revert to a working configuration if you make a mistake. Even better, use version control (see below).

3.3.2. Comments

Add comments to your .zshrc to explain what different sections do:

“`bash

Git aliases

alias ga=’git add’
alias gc=’git commit -m’

Function to create a directory and cd into it

mkcd() {
mkdir -p “$1” && cd “$1”
}
“`

Comments make your configuration easier to understand and maintain, especially as it grows more complex.

3.3.3. Version Control (Git)

The best way to manage your .zshrc (and other dotfiles) is to use Git. Create a Git repository in your home directory to track changes to your dotfiles:

bash
cd ~
git init
git add .zshrc
git commit -m "Initial commit of .zshrc"

This allows you to:

  • Track all changes you make.
  • Easily revert to previous versions.
  • Experiment with different configurations without fear of breaking things.
  • Sync your configuration across multiple machines.
  • Use a remote repository, for example, GitHub, to store your dotfiles.

3.3.4. Modularity (Sourcing other files)

As your .zshrc grows, it can become unwieldy. A good practice is to break it down into smaller, more manageable files. For example, you could create separate files for:

  • ~/.zsh_aliases (for aliases)
  • ~/.zsh_functions (for functions)
  • ~/.zsh_plugins (for custom plugin configurations)

Then, in your .zshrc, you would “source” these files:

bash
source ~/.zsh_aliases
source ~/.zsh_functions
source ~/.zsh_plugins

The source command (or its synonym .) reads and executes the contents of the specified file in the current shell context.

3.4. Reloading .zshrc (source ~/.zshrc)

After making changes to your .zshrc, you need to reload it for the changes to take effect. You can do this by:

  • Opening a new terminal window or tab.
  • Running source ~/.zshrc (or .~/.zshrc) in the current terminal.

This re-executes the .zshrc script, applying your new configuration.


4. Themes: Giving Your Terminal a Makeover

Themes are one of the most visible and immediately impactful aspects of Oh My Zsh. They control the look and feel of your terminal prompt, including colors, symbols, and the information displayed.

4.1. Built-in Themes

Oh My Zsh comes with a large collection of built-in themes located in the ~/.oh-my-zsh/themes directory.

4.1.1. robbyrussell (The Default)

This is the classic Oh My Zsh theme. It’s simple, clean, and shows basic information like the current user, host, and directory. It also indicates Git status (if you’re in a Git repository) with symbols like ? (untracked files), + (modified files), and ! (conflicts).

4.1.2. agnoster (Powerline-inspired)

agnoster is a popular theme that requires a Powerline-compatible font. It uses special characters to create a visually appealing and informative prompt with segments for:

  • User and host
  • Current directory
  • Git branch and status
  • Background jobs
  • Exit code of the last command

It uses different colors to indicate different states (e.g., green for success, red for error).

4.1.3. bira (Simple and Clean)

bira is a minimalist theme that focuses on simplicity and readability. It shows the current directory and Git status (if applicable) without any unnecessary clutter.

4.1.4. spaceship (Highly Configurable)

spaceship is a very popular and powerful theme with a huge number of configuration options. It’s designed to be modular, allowing you to choose which segments to display and how they should look. It can show information about:

  • Git status
  • Package versions (Node.js, Python, Ruby, etc.)
  • Docker context
  • Kubernetes context
  • AWS profile
  • Time
  • Battery level
  • And much more…

4.1.5 And many others
You can explore the full list of built-in themes in the ~/.oh-my-zsh/themes directory. Each theme is a .zsh-theme file, which is a Zsh script that defines the prompt.

4.2. External Themes

Beyond the built-in themes, there’s a vast ecosystem of external themes created by the community.

4.2.1. Powerlevel10k (Highly Recommended)

Powerlevel10k is arguably the best Zsh theme available. It’s a fork of the popular Powerlevel9k theme, but it’s significantly faster and more configurable.

4.2.1.1 Installation

bash
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k

This command clones the Powerlevel10k repository into your Oh My Zsh custom themes directory. Then in your .zshrc file, set:
bash
ZSH_THEME="powerlevel10k/powerlevel10k"

4.2.1.2 Configuration Wizard (p10k configure)

The first time you start a new terminal session after installing Powerlevel10k, it will automatically launch a configuration wizard. This wizard guides you through a series of questions to customize the appearance of your prompt. You can choose:

  • Prompt style (classic, lean, rainbow, etc.)
  • Character set (Unicode, ASCII)
  • Segments to display
  • Colors
  • And much more…

You can re-run the configuration wizard at any time by running p10k configure.

4.2.1.3 Customization Options

Powerlevel10k offers a huge number of configuration options that you can set in your .zshrc file after the ZSH_THEME line. These options are well-documented in the Powerlevel10k README on GitHub. Some examples include:

  • POWERLEVEL9K_LEFT_PROMPT_ELEMENTS: Controls the segments displayed on the left side of the prompt.
  • POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS: Controls the segments displayed on the right side of the prompt.
  • POWERLEVEL9K_MODE: Sets the overall style of the prompt.
  • POWERLEVEL9K_BACKGROUND_JOBS_FOREGROUND: Sets color.
  • POWERLEVEL9K_SHORTEN_DIR_LENGTH : Control directory shortening behavior.

4.2.2. Other Popular External Themes

  • Starship: A fast, customizable, and cross-shell prompt (works with Zsh, Bash, Fish, etc.). It’s written in Rust for performance.
  • Pure: A pretty, minimal, and fast Zsh prompt.

4.3. Creating Your Own Theme

If you can’t find a theme that perfectly suits your needs, you can create your own.

4.3.1. Theme Structure

A theme is simply a Zsh script (usually with a .zsh-theme extension) that defines the PROMPT (and optionally RPROMPT, SPROMPT, etc.) variables. These variables control what’s displayed in your terminal prompt.

4.3.2. Prompt Variables (e.g., %n, %m, %d, %~)

Zsh provides a set of special prompt variables that you can use to insert dynamic information into your prompt. Here are some of the most common ones:

  • %n: Username.
  • %m: Hostname (up to the first dot).
  • %M: Full hostname.
  • %d: Current working directory (full path).
  • %~: Current working directory (with ~ for your home directory).
  • %t: Current time (12-hour format).
  • %T: Current time (24-hour format).
  • %*: Current Time with Seconds.
  • %D: Current Date.
  • %?: Exit code of the last command.
  • %#: # if you’re root, $ otherwise.
  • %%: A literal % character.

You can find a complete list of prompt variables in the Zsh documentation (man zshmisc, section “EXPANSION OF PROMPT SEQUENCES”).

4.3.3. Colors and Styling

You can use ANSI escape codes to add colors and styling to your prompt. Oh My Zsh provides some helper functions to make this easier:

  • %F{color}: Sets the foreground color. color can be a color name (e.g., red, green, blue, yellow, magenta, cyan, white) or a number (0-255 for 256-color terminals).
  • %K{color}: Sets the background color.
  • %f: Resets the foreground color to the default.
  • %k: Resets the background color to the default.
  • %B: Starts bold text.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top