dotfiles

Personal dotfiles
git clone https://git.bracken.jp/dotfiles.git
Log | Files | Refs | LICENSE

commit a090c4e5483e37e7dadaaf3e561a7d1373cf329e
parent 38156d4dfd5e193c5fe5b4e8582edb4f177d87c6
Author: Chris Bracken <chris@bracken.jp>
Date:   Sun,  7 Jun 2026 08:48:25 +0900

zsh: optimise prompt vcs check

Since for jj repos we just show a target character in the prompt, don't
waste time forking jj on every prompt; just walk up parent directories
looking for a .jj directory.

In local profiling, I see this check drop from 5.x ms to 0.4 ms.

We could probably do something similar for git but the complexity is
higher since we show the branch in git prompts. We'd probably need to:
* locate .git; similar to this change but also handle files in case
  we're in a worktree.
* if .git is a file, read the path of the real git dir
* read .git/HEAD
* if it's a ref then strip off the `refs/heads/` prefix
* if it's not, then display the SHA

This seems like a ton of complexity and most of my repos are jj repos
anyway. The jj check I tweaked in this patch actually saves us 5ms for
git repos too so this is already a win either way.

In local measurement, git prompts went from 17.x ms before this change
to 11.x ms afterwards.

Diffstat:
M.config/zsh/.zshrc | 17+++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/.config/zsh/.zshrc b/.config/zsh/.zshrc @@ -50,18 +50,15 @@ unset zcompdump # Current VCS branch (for prompt). vcs_branch() { - # If in a jj repo, indicate that we're in a repo. - if (( $+commands[jj] )) && jj root > /dev/null 2>&1; then - echo -n " ◉ " - return - fi - - # If we're in a git repo, output the current branch name. + # Walk up looking for .jj — avoids forking jj just to ask "are we in one?" + local d=$PWD + while [[ $d != / ]]; do + [[ -d $d/.jj ]] && { echo -n " ◉ "; return } + d=${d:h} + done local branch branch="$(git symbolic-ref --short HEAD 2>/dev/null || git rev-parse --short HEAD 2>/dev/null)" - if [[ -n $branch ]]; then - echo -n " ($branch)" - fi + [[ -n $branch ]] && echo -n " ($branch)" } # Prompt.