Prezto is a configuration framework for Zsh that can load modules and scripts much faster than its more popular counterpart, Oh My Zsh, by leveraging Zsh’s native promptinit and avoiding unnecessary shell restarts.
Let’s see Prezto in action. Here’s a typical interactive Zsh session with Prezto loaded, showing a prompt that includes Git status and the current directory.
% git status
On branch main
Your branch is up to date with 'origin/main'.
nothing to commit, working tree clean
% cd ~/projects/my-app
~/projects/my-app on main ✗ %
The ✗ indicates uncommitted changes in the Git repository. This information is dynamically updated by a Prezto module.
Prezto’s core idea is to provide a lean and fast way to manage your Zsh configuration. It achieves this by organizing your Zsh settings into modules. Each module can contain scripts, completion definitions, and prompt themes. When Prezto starts, it loads only the enabled modules, rather than parsing a large, monolithic configuration file. This modular approach, combined with Zsh’s optimized prompt theme loading, is what gives Prezto its speed advantage.
The primary problem Prezto solves is the slow startup time often associated with feature-rich Zsh configurations. Oh My Zsh, while powerful, can become a bottleneck as you add more plugins and themes, leading to noticeable delays when opening new terminal windows or tabs. Prezto aims to deliver a similar level of functionality with significantly less overhead.
Here’s a breakdown of the key components and how they work:
-
~/.zpreztorc: This is the main configuration file for Prezto. It’s where you enable modules, set up your prompt theme, and define custom variables. It’s a relatively small file, designed for quick parsing. -
Modules: These are directories located in
~/.zprezto/modules/. Each directory contains scripts (.zshfiles) that are sourced when the module is enabled. Common modules includegit,history,completion, andprompt. -
Prompt Themes: These are also organized within modules, typically under
~/.zprezto/modules/prompt/functions/. A prompt theme is a Zsh function that defines what your command prompt looks like. Prezto uses Zsh’s built-inpromptinitto load these themes efficiently. -
~/.zshrc: Your main Zsh startup file. For Prezto, this file is very simple. It typically just needs to source the Prezto init script:# ~/.zshrc ZDOTDIR=${ZDOTDIR:-$HOME} ZSH=$ZDOTDIR/.zprezto # Source Prezto if [[ -z "$ZSH_VERSION" ]]; then export ZSH=$ZDOTDIR/.zprezto exec zsh -l else EMERGENCY_EXIT=1 for rtc in ~/.zshrc.pre ~/.zshrc.local; do [ -f $rtc ] && source $rtc done unset EMERGENCY_EXIT source "$ZSH/init.zsh" fiThe
source "$ZSH/init.zsh"line is the magic that kicks off the Prezto loading process.
The configuration in ~/.zpreztorc is straightforward. Here’s an example:
# ~/.zpreztorc
# Set the prompt theme
zstyle ':prezto:module:prompt' theme 'adam1'
# Enable modules
zmodload zsh/datetime
Zstyle ':prezto:module:history' module-path "$ZSH/modules"
zstyle ':prezto:module:history' hook-functions 'prezto-history-hook'
zstyle ':prezto:module:completion' auto-completions true
zstyle ':prezto:module:git' promptsuffix ' '
zstyle ':prezto:module:git' promptstatus 'yes'
# Add custom modules
zstyle ':prezto:module:mycustom' module-path '/path/to/my/custom/modules'
# Load modules
zstyle ':prezto:load' command pmodule
zmodule git
module completion
module history
module prompt
Notice how modules are enabled using zmodule or module commands. The zstyle commands configure specific aspects of these modules. For instance, zstyle ':prezto:module:prompt' theme 'adam1' tells Prezto to load the adam1 prompt theme.
The "faster alternative" claim isn’t just marketing. Prezto avoids loading a large, often complex, single script like Oh My Zsh’s oh-my-zsh.sh. Instead, it initializes Zsh’s promptinit system and then iterates through your enabled modules, sourcing their respective files. This is a more granular approach. Furthermore, many plugins in Oh My Zsh are loaded via source commands within a large plugins=(...) array in .zshrc. Prezto’s module system is designed to manage these dependencies and loading order more intelligently, often using Zsh’s built-in completion system and function loading mechanisms more effectively.
When Prezto loads a module, it’s not just sourceing a file. It’s often registering functions or completion definitions that Zsh can then manage internally. For example, the git module doesn’t just dump a bunch of Git commands into your environment. It defines functions and completion rules that are integrated into Zsh’s completion system. This means Zsh can provide completions for Git commands very efficiently, and the Git status in your prompt is updated only when necessary, often triggered by Zsh’s prompt expansion hooks.
The most surprising thing about Prezto is how it achieves its speed by being less opinionated about its internal structure than Oh My Zsh. Oh My Zsh essentially wraps Zsh and provides its own elaborate plugin loading mechanism. Prezto, on the other hand, leverages Zsh’s native capabilities more directly. It uses Zsh’s promptinit system, which is highly optimized for loading prompt themes, and its module loading is a straightforward iteration of source commands, but organized into a discoverable and manageable structure. This allows Zsh’s internal optimizations to shine.
After fixing your Prezto setup, the next thing you’ll likely encounter is configuring custom aliases or functions that don’t fit neatly into the module structure.