My personal zsh setup for macOS. Same comfort as my old oh-my-zsh setup (theme, fuzzy finder, autosuggestions, syntax highlighting, completions, nvm), a fraction of the startup time.
Shell startup: 2,342 ms → 44 ms, measured with zprof on a MacBook Pro 2015 (macOS 12).
| Setup | Startup time |
|---|---|
| oh-my-zsh + fzf, nvm, autosuggestions, syntax highlighting, interactive-cd | 2,342 ms |
| This config, nvm loaded at startup | 1,217 ms |
| This config, nvm lazy-loaded, completion dump not compiled | ~375 ms |
| This config, current version | 44 ms (1,316 ms once a day, when the completion cache is rebuilt) |
The full measurement log, step by step, is in docs/benchmarks.md.
- No framework. Plugins are git submodules, sourced directly. Nothing else is loaded.
- nvm is lazy-loaded. Loading nvm at startup cost about 1 second. Now
node,npmandnvmare small autoloaded functions that load nvm on first use, then replace themselves. Every other binary in the active Node version's bin directory (npx, corepack, global npm installs) gets the same stub, created at startup bynvm_lazy_stubs. A global install made after the shell starts is covered from the next start. - The completion dump is rebuilt once a day and compiled.
compinitre-parsing about 1,000compdefcalls on every start was the next bottleneck. The dump is now regenerated when older than 24 hours, then compiled to bytecode withzcompile. Other starts usecompinit -Con the compiled file: about 6 ms instead of 25. Careful when copying the staleness check: the(#q…)glob qualifier in$ZSH_COMPDUMP(#qN.mh+24)is silently ignored unlesssetopt extendedglobis on. - fzf's shell integration is cached.
source <(fzf --zsh)launched the fzf binary on every start for output that only changes with fzf itself. It is now generated once, compiled, and regenerated only when the fzf binary changes. - No needless subprocesses. For example, the cache directory is only created when it doesn't exist yet.
- Theme: agnoster (needs a Powerline-compatible font)
- Plugins: fzf, zsh-autosuggestions, fast-syntax-highlighting, zsh-completions, git completion
- History: shared between sessions, duplicates removed, 10,000 entries
- Directories:
auto_cd, directory stack (cd -1,cd -2…) - Functions (autoloaded, one file per function):
mkcd,kill_port, lazynode/npm/nvm, andnvm_lazy_stubs(lazy stubs for the other nvm binaries, run at startup) - Aliases: safe
rm/cp/mv, and a few personal shortcuts
git clone --recurse-submodules https://github.com/mistergraphx/zsh.git ~/path/to/zshThen in ~/.zshrc:
# Set to 1 to print a zprof report and the startup time
export PROFILING_MODE=0
source ~/path/to/zsh/main.zshenv.zsh contains macOS paths specific to my machine (Homebrew, MacPorts, MAMP): adapt them to yours.
Set PROFILING_MODE=1 and open a new terminal: you get the zprof report and the startup time in milliseconds. Run it a few times, since the first start after a change (or once a day) rebuilds the caches.
main.zsh entry point: options, theme, plugins, completion, profiling
env.zsh PATH and environment
aliases.zsh aliases
functions/ autoloaded functions, one per file
plugins/ git submodules (+ git completion)
themes/ git submodule (agnoster)
.cache/ history, completion dump, fzf cache (generated)
- zsh options reference
- Optimizing zsh startup performance
- Some pearls from my zshrc (lazy-loading nvm)