Zsh Prompt Customization

Prompt Variables

PROMPT and RPROMPT
# PS1 / PROMPT — left prompt
# RPS1 / RPROMPT — right prompt (auto-hides when typing overlaps)

# Basic prompt
PROMPT='%n@%m %~ %# '
# evan@modestus-aw ~/atelier %

# With colors
PROMPT='%F{green}%n%f@%F{blue}%m%f %F{yellow}%~%f %# '

Prompt Escapes

Prompt expansion sequences
# Identity
%n           # username
%m           # hostname (short)
%M           # hostname (FQDN)

# Directory
%~           # current dir with ~ substitution
%d or %/     # current dir (full path)
%c or %.     # trailing component of current dir
%3~          # last 3 path components with ~

# Time
%D           # date: yy-mm-dd
%T           # time: HH:MM (24h)
%t or %@     # time: HH:MM AM/PM
%*           # time: HH:MM:SS (24h)
%D{%F %T}    # custom strftime format

# Status
%#           # # for root, % for user
%?           # exit code of last command
%(?.√.✗)     # conditional: √ if success, ✗ if failure

# Visual
%B %b        # bold on/off
%U %u        # underline on/off
%F{color}    # foreground color start
%f           # foreground color reset
%K{color}    # background color start
%k           # background color reset

Conditional Prompts

Dynamic prompt based on context
# Exit code indicator
PROMPT='%(?.%F{green}✓%f.%F{red}✗ %?%f) %F{blue}%~%f %# '

# Privilege indicator
PROMPT='%(!.%F{red}ROOT%f.%F{green}%n%f) %~ %# '

# Truncate long paths
PROMPT='%F{cyan}%3~%f %# '              # max 3 components

# Git branch in prompt (requires vcs_info)
autoload -Uz vcs_info
precmd() { vcs_info }
zstyle ':vcs_info:git:*' formats ' %F{magenta}(%b)%f'
setopt PROMPT_SUBST
PROMPT='%F{blue}%~%f${vcs_info_msg_0_} %# '

Starship and Powerlevel10k

Modern prompt frameworks
# Starship (cross-shell, Rust-based)
# Install
curl -sS https://starship.rs/install.sh | sh

# Enable in .zshrc
eval "$(starship init zsh)"

# Config: ~/.config/starship.toml
# [character]
# success_symbol = "[➜](bold green)"
# error_symbol = "[✗](bold red)"
#
# [directory]
# truncation_length = 3
Powerlevel10k
# Install (zinit)
zinit ice depth=1
zinit light romkatv/powerlevel10k

# Run configuration wizard
p10k configure

# Instant prompt (add to top of .zshrc)
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

RPROMPT Patterns

Right-side prompt
# Execution time
RPROMPT='%F{yellow}%D{%T}%f'            # current time

# Git + time
RPROMPT='${vcs_info_msg_0_} %F{242}%D{%T}%f'

# Disappearing RPROMPT (auto-hides when cursor reaches it)
# This is default behavior -- no config needed