Created
March 7, 2026 21:42
-
-
Save jweiss/b76d668164e168a9477be65e1eac5bfb to your computer and use it in GitHub Desktop.
ZSH prompt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ─── ZSH Prompt ─────────────────────────────────────────────────────────────── | |
| autoload -Uz vcs_info | |
| setopt prompt_subst | |
| # ── Git info ────────────────────────────────────────────────────────────────── | |
| # Formats: branch name, with * for unstaged changes, + for staged | |
| zstyle ':vcs_info:*' enable git | |
| zstyle ':vcs_info:git:*' check-for-changes true | |
| zstyle ':vcs_info:git:*' unstagedstr '*' | |
| zstyle ':vcs_info:git:*' stagedstr '+' | |
| zstyle ':vcs_info:git:*' formats ' %F{yellow}(%b%u%c)%f' | |
| zstyle ':vcs_info:git:*' actionformats ' %F{yellow}(%b|%a%u%c)%f' # e.g. (main|REBASE*) | |
| # Capture exit code before precmd functions (like vcs_info) overwrite $? | |
| _prompt_precmd() { | |
| _last_exit_code=$? | |
| vcs_info | |
| } | |
| precmd_functions+=(_prompt_precmd) | |
| # ── Helper functions ─────────────────────────────────────────────────────────── | |
| # Show non-zero exit code from last command | |
| _prompt_exit_code() { | |
| (( _last_exit_code != 0 )) && print -n " %F{red}[exit:$_last_exit_code]%f" | |
| } | |
| # Show active Python venv or conda env | |
| _prompt_venv() { | |
| local env="${VIRTUAL_ENV:-$CONDA_DEFAULT_ENV}" | |
| [[ -n $env ]] && print -n " %F{cyan}($(basename $env))%f" | |
| } | |
| # Show background job count if any | |
| _prompt_jobs() { | |
| local jobs=$(jobs -l 2>/dev/null | wc -l | tr -d ' ') | |
| (( jobs > 0 )) && print -n " %F{magenta}[${jobs}bg]%f" | |
| } | |
| # ── Prompt layout ────────────────────────────────────────────────────────────── | |
| # | |
| # Line 1: user@host ~/some/path (git-branch*+) (venv) [exit:1] [1bg] | |
| # Line 2: $ (or # for root) | |
| # | |
| # To drop user@host (single machine, no SSH), remove the first segment. | |
| PROMPT=' | |
| %F{green}%n@%m%f %F{blue}%~%f${vcs_info_msg_0_}$(_prompt_venv)$(_prompt_exit_code)$(_prompt_jobs) | |
| %(!.%F{red}#%f.%F{green}$%f) ' | |
| # Right prompt: 24h time — disappears when you type near it | |
| RPROMPT='%F{242}%T%f' | |
| # ── Optional tweaks (uncomment to enable) ───────────────────────────────────── | |
| # Show full hostname instead of short name: | |
| # Replace %m with %M in PROMPT | |
| # Shorter path (only last 2 components): | |
| # Replace %~ with %(4~|.../%2~|%~) | |
| # Two-char prompt symbol (lambda, arrow, etc.): | |
| # Replace $ with λ or ❯ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment