Zsh Productivity Guide: Aliases, Functions, Plugins, Prompt and History (with a Ready .zshrc)
zsh-productivity is a practical guide to making the Z shell (Zsh) fast and pleasant, plus a ready-to-use .zshrc that starts in about 20 ms without any framework. It covers the options that matter, shared and searchable history, smart tab completion, key bindings, aliases (including Zsh-only global and suffix aliases), a set of tested shell functions, the best Zsh plugins and plugin managers, prompt choices like Starship, glob qualifiers and parameter expansion tricks, modern CLI tools (fzf, zoxide, eza, bat, atuin), and how to profile a slow shell.
It is for macOS users (Zsh has been the default shell since macOS Catalina), Linux users switching from Bash, and anyone whose .zshrc is a pile of copied snippets.
Last reviewed: December 2026. Tested with Zsh 5.9 on macOS; the latest Zsh release is 5.9.2 (July 2026). Plugin and tool links were checked for recent activity at review time.
git clone https://github.com/Ralpberry-Labs/zsh-productivity ~/.zsh-productivity
~/.zsh-productivity/install.sh # backs up your .zshrc and links the new one
exec zsh # restart the shell
plug-install # clone the 3 recommended plugins
Table of Contents
- What Is in This Repo
- Zsh Startup Files: Which One Runs When
- Tour of the .zshrc
- Options Worth Setting
- History: Never Lose a Command Again
- Tab Completion
- Key Bindings and Line Editing
- Aliases: Regular, Global and Suffix
- Functions Included
- Writing Your Own Functions
- Globbing Superpowers
- Parameter Expansion Cheat Sheet
- Directory Navigation
- Best Zsh Plugins
- Plugin Managers Compared
- Prompts Compared
- Modern CLI Tools That Pair With Zsh
- Make Zsh Start Fast
- Bash to Zsh: Differences That Bite
- Secrets and Machine-Specific Config
- Tests
- FAQ
- Where to Go Next
- Contributing
- License
- More free resources
What Is in This Repo
| File | Purpose |
|---|---|
zshrc |
The ready .zshrc: options, history, completion, keys, aliases, plugins, tool hooks, prompt |
zshenv |
Minimal .zshenv (XDG paths only) |
zshrc.local.example |
Template for machine-specific settings and secrets |
functions/ |
13 autoloaded functions: mkcd, up, extract, bak, port, serve, retry, calc, json, fcd, fkill, gbclean, zsh-startup-time |
install.sh |
Backs up your .zshrc and symlinks this one |
tests/run.sh |
Syntax checks, a clean-HOME interactive startup test and function tests |
Design rules: no framework, every external tool is optional (guarded by (( $+commands[tool] ))), nothing slow runs at startup, and everything is commented so you can delete what you do not need.
Prefer to copy only parts? Every section of the zshrc stands alone.
Zsh Startup Files: Which One Runs When
Zsh reads up to five files from $ZDOTDIR (defaults to $HOME), in this order:
| File | Login shell | Interactive shell | Scripts | Put here |
|---|---|---|---|---|
.zshenv |
Yes | Yes | Yes | Only env vars every zsh needs (XDG_*, ZDOTDIR). No output |
.zprofile |
Yes | Login setup: eval "$(/opt/homebrew/bin/brew shellenv)" |
||
.zshrc |
Yes | Everything interactive: options, aliases, completion, prompt | ||
.zlogin |
Yes | Rarely needed (runs after .zshrc) |
||
.zlogout |
On logout | Cleanup |
On macOS, every new Terminal or iTerm2 window is a login shell, so both .zprofile and .zshrc run. Most Linux terminal emulators start non-login interactive shells, so only .zshenv and .zshrc run. Putting PATH changes in .zshrc (as this repo does) works everywhere for interactive use.
System-wide files (/etc/zshenv, /etc/zprofile, /etc/zshrc) run before each user file. On macOS, /etc/zprofile runs path_helper, which can reorder PATH; that is why Homebrew’s setup goes in .zprofile.
Keep $HOME tidy by moving the files: put export ZDOTDIR=$HOME/.config/zsh in ~/.zshenv and the rest in ~/.config/zsh/.
Tour of the .zshrc
The zshrc is split into numbered sections:
| # | Section | Highlights |
|---|---|---|
| 0 | Paths | typeset -U path removes duplicates; ~/.local/bin first |
| 1 | Options | AUTO_CD, AUTO_PUSHD, EXTENDED_GLOB, INTERACTIVE_COMMENTS |
| 2 | History | 100k lines, shared between terminals, timestamps, leading-space commands not saved |
| 3 | Completion | Menu selection, case-insensitive matching, cached, compinit dump rebuilt at most daily |
| 4 | Key bindings | Up/Down search history by prefix, Ctrl-X Ctrl-E edits in $EDITOR |
| 5 | Environment | EDITOR, LESS flags, colours |
| 6 | Aliases | Navigation, safety, ~25 git aliases, global and suffix aliases |
| 7 | Functions | Autoloaded from functions/ on first use |
| 8 | Plugins | Plain git clones managed by plug-install and plug-update |
| 9 | Tools | fzf, zoxide, direnv, mise, atuin: each only if installed |
| 10 | Prompt | Starship if installed, otherwise a built-in prompt with git branch, dirty marks, exit code, duration and job count |
| 11 | Local overrides | ~/.zshrc.local, then syntax highlighting last |
The built-in prompt looks like this:
~/code/api main*+ 12s [1] %
Directory, git branch (* unstaged, + staged changes), duration of the last command when it took 3 s or more, the exit code in red when it failed, and a background job count on the right.
Options Worth Setting
setopt NAME turns an option on, unsetopt NAME (or setopt NO_NAME) turns it off. Option names ignore case and underscores. List what is on with setopt; read about one with man zshoptions.
| Option | Effect | In this zshrc |
|---|---|---|
AUTO_CD |
~/code alone changes directory |
Yes |
AUTO_PUSHD |
Every cd pushes onto the directory stack |
Yes |
PUSHD_IGNORE_DUPS |
No duplicates in the stack | Yes |
EXTENDED_GLOB |
Enables ^, ~, # and (#q...) in patterns |
Yes |
GLOB_DOTS |
* matches dotfiles too |
Yes |
NO_CASE_GLOB |
Case-insensitive globbing | Yes |
INTERACTIVE_COMMENTS |
# comments allowed at the prompt |
Yes |
NO_BEEP |
Silence | Yes |
NO_FLOW_CONTROL |
Ctrl-S no longer freezes the terminal | Yes |
CORRECT |
“Did you mean …?” for commands | No (can be annoying) |
NO_CLOBBER |
> refuses to overwrite files (use >|) |
No; consider it |
RM_STAR_WAIT |
Wait 10 s before rm * |
No; consider it |
NUMERIC_GLOB_SORT |
file2 before file10 |
No; nice to have |
MENU_COMPLETE |
First Tab inserts a match immediately | No |
NO_NOMATCH |
Unmatched globs passed literally (Bash style) | No |
History: Never Lose a Command Again
HISTFILE=${XDG_STATE_HOME:-$HOME/.local/state}/zsh/history
HISTSIZE=100000
SAVEHIST=100000
setopt EXTENDED_HISTORY # ": <start>:<duration>;command" format
setopt SHARE_HISTORY # all terminals see each other's commands
setopt HIST_IGNORE_ALL_DUPS # keep only the newest copy of a command
setopt HIST_IGNORE_SPACE # " export TOKEN=..." is not saved
setopt HIST_REDUCE_BLANKS
setopt HIST_VERIFY # show !! expansions before running
Choose one of SHARE_HISTORY, INC_APPEND_HISTORY or INC_APPEND_HISTORY_TIME: they overlap. SHARE_HISTORY both writes immediately and imports other shells’ commands.
| Keys / command | Does |
|---|---|
| Up / Down | Previous / next command starting with what you typed (this zshrc) |
| Ctrl-R | Search history (fzf or atuin take over when installed) |
!! |
Last command (sudo !!) |
!$ / Alt-. |
Last argument of the previous command |
!* |
All arguments of the previous command |
!git |
Last command starting with git |
!?foo? |
Last command containing foo |
^old^new |
Rerun the last command replacing old with new |
fc |
Edit the last command in $EDITOR, then run it |
history -i 1 (alias h) |
Full history with ISO timestamps |
history -D |
With durations |
fc -l -10 |
Last 10 commands |
Want history synced across machines with full-text search, exit codes and directories? See atuin.
Tab Completion
Zsh completion is programmable and context-aware: it knows git checkout <Tab> wants branches and kill <Tab> wants processes. Turn it on with compinit, then tune with zstyle.
autoload -Uz compinit && compinit
zmodload zsh/complist
zstyle ':completion:*' menu select # navigate matches with arrows
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|=*' 'l:|=* r:|=*'
zstyle ':completion:*:descriptions' format '%F{yellow}-- %d --%f'
zstyle ':completion:*' use-cache on
| Trick | Example |
|---|---|
| Case-insensitive | cd doc<Tab> finds Documents |
| Partial words | cd /u/lo/b<Tab> becomes /usr/local/bin |
| Options with descriptions | ls -<Tab> |
| Kill by name | kill <Tab> lists processes |
| Expand globs and variables | ls *.log<Tab>, echo $HOME<Tab> |
| Directory stack | cd -<Tab> lists recent directories |
| SSH hosts | ssh <Tab> reads ~/.ssh/config and known hosts |
| Git | Branches, remotes, files, subcommands with descriptions |
Add completions for tools that generate them:
# Many CLIs print a completion script: write it to a folder on fpath, before compinit
mkdir -p ~/.local/share/zsh/completions
kubectl completion zsh > ~/.local/share/zsh/completions/_kubectl
gh completion -s zsh > ~/.local/share/zsh/completions/_gh
rustup completions zsh > ~/.local/share/zsh/completions/_rustup
# in .zshrc, before compinit:
fpath=(~/.local/share/zsh/completions $fpath)
After adding completions, delete the cached dump (rm ~/.cache/zsh/zcompdump*) and restart. For a fuzzy completion menu, try the fzf-tab plugin.
Key Bindings and Line Editing
Zsh’s line editor (ZLE) defaults to Emacs-style keys (bindkey -e). These work in every Zsh, macOS Terminal and most Linux terminals:
| Keys | Action |
|---|---|
| Ctrl-A / Ctrl-E | Start / end of line |
| Alt-B / Alt-F | Back / forward one word |
| Ctrl-W | Delete word before cursor |
| Alt-D | Delete word after cursor |
| Ctrl-U | Delete the whole line (Zsh default kills the whole line, not just before the cursor) |
| Ctrl-K | Delete to end of line |
| Ctrl-Y | Paste what you deleted |
| Ctrl-_ | Undo |
| Ctrl-L | Clear screen |
| Ctrl-R | Search history |
| Alt-. | Insert last argument of previous command (repeat to go further back) |
| Alt-Q | Push the line aside, run another command, get it back |
| Ctrl-X Ctrl-E | Edit the command in $EDITOR (this zshrc) |
| Alt-‘ | Quote the current line |
| Ctrl-Space | Accept autosuggestion (this zshrc, with the plugin) |
Prefer Vim keys? Use bindkey -v and add export KEYTIMEOUT=1 to make Esc fast. bindkey alone lists every binding; run cat (or press Ctrl-V then a key) to see the escape code a key sends.
Custom widget example: Ctrl-G runs git status without disturbing what you are typing.
git-status-widget() { zle push-input; BUFFER='git status -sb'; zle accept-line }
zle -N git-status-widget
bindkey '^G' git-status-widget
Aliases: Regular, Global and Suffix
alias gs='git status -sb' # regular: replaces the first word
alias -g G='| grep -i' # global: replaced anywhere in the line
alias -s md=$EDITOR # suffix: typing README.md opens it
alias # list all
unalias gs # remove
\gs # bypass an alias once
Global aliases in this zshrc:
| Alias | Expands to | Example |
|---|---|---|
G |
\| grep -i |
ps aux G node |
L |
\| less |
git log L |
H / T |
\| head / \| tail |
ls -lt H |
C |
\| wc -l |
ls C |
NE |
2>/dev/null |
find / -name x NE |
Git aliases (selection):
| Alias | Command |
|---|---|
gs |
git status -sb |
gap |
git add -p (stage hunk by hunk) |
gcm "msg" |
git commit -m |
gca |
git commit --amend --no-edit |
gswc name |
git switch -c name |
gl / gla |
Graph log, last 20 / all branches |
gpf |
git push --force-with-lease (safer than --force) |
gpl |
git pull --rebase |
gds |
Staged diff |
Rules of thumb: alias what you type ten times a day; do not shadow commands in ways that surprise you on other machines (this config makes rm, cp, mv interactive, which is a deliberate safety choice; remove those lines if you prefer). Use a function when you need arguments in the middle of a command.
Functions Included
All live in functions/ and are autoloaded: Zsh reads each file only the first time you call it, so they cost nothing at startup.
| Function | Usage | Does |
|---|---|---|
mkcd |
mkcd path/to/dir |
Make directories and cd into them |
up |
up 3, up src |
Go up N levels, or up to the parent named src |
extract |
extract file.tar.gz other.zip |
Unpack tar, gz, bz2, xz, zst, zip, 7z, rar by extension |
bak |
bak config.yaml |
Timestamped backup copy |
port |
port 3000 |
Which process listens on a port (lsof or ss) |
serve |
serve 8080 |
Static file server for the current folder (Python) |
retry |
retry -n 5 -d 2 curl -f url |
Rerun until success |
calc |
calc '2**10 / 3', calc 'sqrt(2)' |
Floating-point maths using Zsh itself |
json |
curl -s api \| json |
Pretty-print JSON (jq or Python) |
fcd |
fcd ~/code |
Fuzzy-pick a subdirectory and cd (fzf) |
fkill |
fkill, fkill KILL |
Fuzzy-pick processes to kill (fzf) |
gbclean |
gbclean |
Delete local branches already merged (keeps main/master/develop) |
zsh-startup-time |
zsh-startup-time 10 |
Average interactive startup time |
Writing Your Own Functions
Create a file in functions/ whose name is the function name, containing only the body:
# functions/note: append a timestamped line to ~/notes.md
print -r -- "- $(date '+%Y-%m-%d %H:%M') $*" >> ~/notes.md
Open a new shell (or autoload -Uz note) and run note call the bank.
Patterns worth knowing:
myfn() {
emulate -L zsh # predictable options inside the function
setopt local_options extended_glob
local name=${1:?usage: myfn <name>} # required argument with an error message
local count=${2:-10} # default value
(( $# > 2 )) && { print -u2 "too many args"; return 1 }
print -r -- "name=$name count=$count" # print -r: no escape processing
}
# Options parsing with zparseopts
deploy() {
local -A opts
zparseopts -D -E -A opts -- e: -env: n -dry-run
local env=${opts[-e]:-${opts[--env]:-staging}}
(( ${+opts[-n]} || ${+opts[--dry-run]} )) && print "dry run"
print "deploying to $env: $@"
}
Hooks run code at specific moments: add-zsh-hook precmd fn (before each prompt), preexec (before each command), chpwd (after each directory change).
autoload -Uz add-zsh-hook
auto_venv() { [[ -f .venv/bin/activate ]] && source .venv/bin/activate }
add-zsh-hook chpwd auto_venv # activate a Python venv when entering a project
Globbing Superpowers
With EXTENDED_GLOB, Zsh patterns replace many find commands.
| Pattern | Matches |
|---|---|
**/*.py |
All Python files, recursively |
*.(jpg\|png) |
Either extension |
^*.log |
Everything except .log files |
*~*.min.js |
All files except minified JS (~ = “but not”) |
file<1-10>.txt |
Numeric ranges |
(#i)readme* |
Case-insensitive |
**/node_modules(/) |
Directories named node_modules |
Glob qualifiers in parentheses at the end filter by file attributes:
| Qualifier | Meaning | Example |
|---|---|---|
(.) |
Regular files | ls **/*(.) |
(/) |
Directories | print -l *(/) |
(@) |
Symlinks | ls -l *(@) |
(*) |
Executables | ls *(*) |
(N) |
No error if nothing matches | rm -f *.tmp(N) |
(D) |
Include dotfiles | ls *(D) |
(Lm+100) |
Larger than 100 MB | ls -lh **/*(.Lm+100) |
(mh-1) |
Modified in the last hour | ls *(mh-1) |
(mw+2) |
Modified more than 2 weeks ago | rm ~/Downloads/*(.mw+2) |
(om[1,5]) |
5 most recently modified | ls *(om[1,5]) |
(OL[1,3]) |
3 largest | ls -lh **/*(.OL[1,3]) |
(u:root:) |
Owned by root | ls -l /usr/local/**/*(u:root:) |
(:t) / (:h) / (:r) / (:e) |
Tail, head, root (no extension), extension | print *.jpg(:r) |
Batch rename with zmv:
autoload -Uz zmv
zmv -n '(*).jpeg' '$1.jpg' # -n = dry run: show what would happen
zmv '(*).jpeg' '$1.jpg'
zmv -W '*.JPG' '*.jpg' # -W: wildcard style
zmv '(**/)(*) (*)' '$1$2_$3' # replace spaces with underscores, recursively
Parameter Expansion Cheat Sheet
f=/home/me/photos/beach.tar.gz
print ${f:t} # beach.tar.gz (tail, like basename)
print ${f:h} # /home/me/photos (head, like dirname)
print ${f:r} # /home/me/photos/beach.tar (remove one extension)
print ${f:e} # gz (extension)
print ${f:A} # absolute path with symlinks resolved
s="Hello World"
print ${s:l} ${s:u} # hello world HELLO WORLD
print ${#s} # 11 (length)
print ${s/World/Zsh} # Hello Zsh (first match; // for all)
print ${s:0:5} # Hello (substring)
print ${s#Hello } # World (remove shortest prefix; ## longest)
print ${s%World} # "Hello " (remove suffix)
print ${name:-default} # default if unset or empty
print ${name:=default} # ...and assign it
print ${name:?message} # error if unset
print ${+name} # 1 if set, 0 if not
arr=(b a c a)
print ${#arr} # 4 elements
print ${arr[1]} # b (arrays are 1-indexed!)
print ${arr[-1]} # a (last)
print ${(o)arr} # a a b c (sorted)
print ${(u)arr} # b a c (unique)
print ${(j:,:)arr} # b,a,c,a (join)
csv="x,y,z"; parts=(${(s:,:)csv}) # split on commas
lines=(${(f)"$(cat file)"}) # split on newlines
print ${(U)s} # HELLO WORLD (flag form)
print ${arr:#a} # remove elements matching a -> b c
Words are not split on spaces by default in Zsh (unlike Bash): $var with spaces stays one argument. Use ${=var} to split explicitly.
Directory Navigation
| Command | Does |
|---|---|
.., ..., .... |
Up 1, 2, 3 levels (aliases) |
- |
Previous directory |
d |
Show the directory stack with numbers |
cd -<Tab> / cd -3 |
Jump to a stack entry |
~/code |
Just type a path (AUTO_CD) |
cd old new |
Zsh-only: replace old with new in the current path (/srv/app/v1 to /srv/app/v2 via cd v1 v2) |
hash -d proj=~/code/project |
Named directory: cd ~proj, and the prompt shows ~proj |
z part |
zoxide: jump to the best match from your history |
zi part |
zoxide interactive with fzf |
fcd |
Fuzzy-pick a subdirectory (this repo) |
up src |
Up to the parent called src (this repo) |
Best Zsh Plugins
The three plugins enabled in this zshrc cover most of what people want from a framework:
| Plugin | What it does | Why it is worth it |
|---|---|---|
| zsh-autosuggestions | Grey suggestion from history as you type; Right arrow or Ctrl-Space accepts | Feels like autocomplete in an IDE |
| zsh-syntax-highlighting | Colours valid commands green and typos red before you press Enter | Catch mistakes early (load it last) |
| zsh-completions | Extra completion definitions for hundreds of tools | Better Tab results |
Other good picks:
| Plugin | What it does |
|---|---|
| fast-syntax-highlighting | Alternative highlighter with themes; use instead of zsh-syntax-highlighting, not both |
| zsh-history-substring-search | Up arrow searches for the typed text anywhere in history |
| fzf-tab | Replaces the completion menu with fzf (fuzzy filtering and previews) |
| fzf-git.sh | Key bindings to fuzzy-pick git branches, commits, files and stashes |
Adding a plugin to this config: append owner/repo to ZPLUGINS, run plug-install, then source its main file in section 8 of the zshrc. Update all with plug-update.
Plugin Managers Compared
You do not need a plugin manager for three plugins (this config uses two tiny functions). If you want one:
| Manager | Style | Best for |
|---|---|---|
| None (this repo) | git clone + source |
Few plugins, full control, fastest |
| antidote | Plain text plugin list compiled to a static file | Simple and fast; a good default |
| zinit | Turbo mode (deferred loading), ice modifiers | Power users with many plugins who want lazy loading |
| sheldon | TOML config, written in Rust, works with Bash too | Declarative config fans |
| zimfw | Framework + manager with curated modules | Batteries included, still fast |
| Prezto | Configuration framework with modules | A complete, opinionated setup |
| znap | Lightweight manager with instant-prompt style caching | Minimal setups |
Whichever you choose, check startup time before and after (zsh-startup-time).
Prompts Compared
| Prompt | Notes | Pick it if |
|---|---|---|
| Built-in (this repo) | vcs_info + hooks, no dependencies |
You want zero dependencies |
| Starship | Fast cross-shell prompt written in Rust, configured in ~/.config/starship.toml; shows language versions, cloud context, git state |
You use several shells or want rich info with easy config |
| Pure | Minimal two-line prompt with async git status | You like minimal |
| Powerlevel10k | Very fast, highly configurable, instant prompt | You already use it: its README says the project now has very limited support, so new setups may prefer Starship |
Starship setup:
brew install starship # or: curl -sS https://starship.rs/install.sh | sh
starship preset nerd-font-symbols -o ~/.config/starship.toml # optional preset
The zshrc already runs eval "$(starship init zsh)" when Starship is installed. A Nerd Font in the terminal makes icons render.
Prompt escape codes for your own prompt:
| Code | Shows |
|---|---|
%~ |
Current directory with ~ |
%1~ |
Last path component |
%n / %m |
User / short host name |
%# |
# for root, % otherwise |
%? |
Exit code of the last command |
%(?.ok.fail) |
Conditional on exit code |
%j |
Number of background jobs |
%T / %* |
Time HH:MM / HH:MM:SS |
%F{red}...%f |
Colour (names or 0-255) |
%B...%b |
Bold |
Modern CLI Tools That Pair With Zsh
Each is optional; the zshrc wires them up only when installed.
| Tool | Replaces / adds | Zsh integration | Install (Homebrew) |
|---|---|---|---|
| fzf | Fuzzy finder | Ctrl-T files, Ctrl-R history, Alt-C cd, **<Tab> |
brew install fzf |
| zoxide | Smarter cd |
z proj, zi |
brew install zoxide |
| atuin | Shell history | SQLite history with search, optional encrypted sync | brew install atuin |
| eza | ls |
Git status column, tree view, icons | brew install eza |
| bat | cat |
Syntax highlighting, line numbers | brew install bat |
| ripgrep | grep -r |
Very fast, respects .gitignore |
brew install ripgrep |
| fd | find |
Simple syntax, fast | brew install fd |
| direnv | Per-folder env | Loads .envrc on cd |
brew install direnv |
| mise | nvm, pyenv, asdf | Per-project tool versions and env | brew install mise |
| delta | git diff pager |
Side-by-side, syntax-highlighted diffs | brew install git-delta |
| Starship | Prompt | See above | brew install starship |
On Debian/Ubuntu most are available with apt (some under different names, such as fd-find and bat installed as batcat).
Make Zsh Start Fast
Measure first:
zsh-startup-time 10 # this repo's function
time zsh -i -c exit # quick check
Profile with zprof: add zmodload zsh/zprof as the first line of .zshrc and zprof as the last, open a new shell, and read the table (sorted by time).
Common causes and fixes:
| Cause | Fix |
|---|---|
compinit security check on every start |
Rebuild the dump once a day, use compinit -C otherwise (this zshrc does) |
nvm loaded eagerly (often 200 ms+) |
Use mise or fnm, or lazy-load nvm in a wrapper function |
eval "$(tool init)" for many tools |
Cache the output to a file and regenerate when the tool updates |
| Many framework plugins | Keep only what you use; consider deferred loading (zinit turbo) |
brew shellenv, pyenv init in .zshrc |
Move login-only setup to .zprofile |
| Slow prompt in big git repos | Use an async prompt (Starship, Pure) or disable check-for-changes |
Anything under about 100 ms feels instant. This repo’s zshrc starts in roughly 20 ms on a recent Mac without external tools.
Bash to Zsh: Differences That Bite
| Behaviour | Bash | Zsh |
|---|---|---|
Unquoted $var with spaces |
Split into words | Stays one word (use ${=var} to split) |
| Array indexes | Start at 0 | Start at 1 (setopt KSH_ARRAYS for 0) |
Unmatched glob *.xyz |
Passed literally | Error “no matches found” (use (N) or quote it) |
echo -e |
Needed for escapes | echo interprets escapes; prefer print -r -- |
read -p "prompt" |
Prompt text | Use read "var?prompt " |
$BASH_SOURCE |
Current file | ${(%):-%x} or $0 in sourced files |
| Config file | .bashrc |
.zshrc |
[[ $a == $b ]] with patterns |
Same | Same |
source <(cmd) |
Works | Works |
| Associative arrays | declare -A |
typeset -A (or local -A) |
Run a Bash script with Bash: keep #!/usr/bin/env bash as the shebang, and switching your interactive shell does not affect scripts. Inside Zsh, emulate sh -c 'source file.sh' runs POSIX-style code.
Change your login shell to Zsh: chsh -s "$(command -v zsh)" (on Linux, the path must be listed in /etc/shells).
Secrets and Machine-Specific Config
- Keep tokens out of your dotfiles repo. Put them in
~/.zshrc.local(sourced last, never committed), load them from a password manager CLI on demand, or use direnv.envrcfiles per project. - Start a command with a space to keep it out of history (
HIST_IGNORE_SPACEis on): ` export API_KEY=…`. - Check your history for leaks occasionally:
grep -iE 'key|token|secret|password' $HISTFILE.
Tests
zsh tests/run.sh
It checks that every file parses (zsh -n), starts a full interactive shell with this zshrc in a throwaway HOME and verifies there are no errors, then exercises the functions (mkcd, up, extract, bak, retry, calc, json). All 29 checks pass on Zsh 5.9 (macOS, December 2026).
FAQ
Do I need a framework or plugin manager? No. The features most people want (autosuggestions, syntax highlighting, extra completions, a git-aware prompt, aliases) take about 300 lines and three plugins, which is exactly this repo. Frameworks are convenient when you want dozens of prepackaged modules.
Why is my Zsh slow to start?
Usually a version manager (nvm), many eval "$(... init)" lines, a framework loading many plugins, or compinit running its security check every time. Profile with zprof and see Make Zsh Start Fast.
How do I make Zsh my default shell?
chsh -s "$(command -v zsh)", then log out and back in. On macOS it already is the default for new accounts.
Where should I put PATH changes?
For interactive use, .zshrc is fine. If GUI apps or scripts launched without a terminal need them, use .zprofile (login) or .zshenv (every shell, keep it tiny).
How do I reload my config?
exec zsh (alias reload) replaces the shell with a fresh one. source ~/.zshrc also works but keeps old aliases and functions around.
How do I see where an alias, function or command comes from?
whence -v name (or type name), which -a name for all matches, functions name to print a function’s body, alias name for an alias.
Why does rm *.tmp say “no matches found”?
Zsh treats an unmatched glob as an error instead of passing it literally. Use rm -f *.tmp(N) or quote the pattern if you meant the literal text.
How do I enable Vim mode?
bindkey -v and export KEYTIMEOUT=1. Keep bindkey -M viins '^R' history-incremental-search-backward or fzf’s binding for history search.
Can I share this config between macOS and Linux?
Yes. It checks for each tool before using it and uses XDG paths. Put OS-specific lines behind [[ $OSTYPE == darwin* ]] or [[ $OSTYPE == linux* ]].
How do I uninstall?
Delete the ~/.zshrc symlink, restore the backup the installer created (~/.zshrc.backup.<date>), and remove ~/.local/share/zsh/plugins if you no longer want the plugins.
Where to Go Next
- Read
man zshoptions,man zshexpn(expansion and globbing) andman zshzle(line editor); they are long but complete. Online: the Zsh manual. - The Zsh user guide is an older but friendly tour of the shell.
- Learn fzf well; it upgrades history search, file picking and git workflows. Its README has many examples.
- Put your dotfiles in a git repo and manage them with a tool like chezmoi or GNU Stow.
- Explore the curated plugin list awesome-zsh-plugins when you need something specific.
Contributing
PRs are welcome. Keep the zshrc framework-free, fast and commented. New functions need a usage line at the top and a test in tests/run.sh; run zsh tests/run.sh before opening a PR. Keep tool and plugin entries accurate and actively maintained.
License
MIT. See LICENSE.
If this helped you, a star helps others find it.
More free resources
Part of the Ralpberry Labs open-source collection. See also Top 100 Open Source.