Created
March 9, 2026 17:29
-
-
Save kungfusheep/862d9dd0f9bbbcef0921d8de0f8b3c5f to your computer and use it in GitHub Desktop.
zero-fork ps1 prompt with git branch + worktree support
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
| # fast-prompt: zero-fork zsh prompt with git branch + worktree support | |
| # | |
| # shows: repo/subdir:branch (git) or full path (non-git) | |
| # style: dim text, block cursor prompt | |
| # | |
| # usage: source this file in .zshrc | |
| setopt PROMPT_SUBST | |
| _prompt_update() { | |
| local d=$PWD head root line | |
| while [[ -n "$d" ]]; do | |
| if [[ -f "$d/.git/HEAD" ]]; then | |
| read -r head < "$d/.git/HEAD" | |
| root="${d:t}" | |
| if [[ "$PWD" == "$d" ]]; then | |
| PROMPT_INFO="${root}:${head#ref: refs/heads/}" | |
| else | |
| PROMPT_INFO="${root}/${PWD#$d/}:${head#ref: refs/heads/}" | |
| fi | |
| return | |
| elif [[ -f "$d/.git" ]]; then | |
| read -r line < "$d/.git" | |
| line="${line#gitdir: }" | |
| if [[ -f "$line/HEAD" ]]; then | |
| read -r head < "$line/HEAD" | |
| root="${d:t}" | |
| if [[ "$PWD" == "$d" ]]; then | |
| PROMPT_INFO="${root}:${head#ref: refs/heads/}" | |
| else | |
| PROMPT_INFO="${root}/${PWD#$d/}:${head#ref: refs/heads/}" | |
| fi | |
| return | |
| fi | |
| fi | |
| d=${d%/*} | |
| done | |
| PROMPT_INFO="$PWD" | |
| } | |
| precmd_functions+=(_prompt_update) | |
| PS1=$'\n%{\e[2m%}${PROMPT_INFO}\n■ %{\e[0m%}' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment