feat(git): show pending branch name as unbolded (#1)

* feat(git): show pending branch name as unbolded

When changing branches on a large repository it would show the old branch name and update async. With this PR, the branch name is a different color (unbolded) so that the user knows that the branch name update is still pending.

* test names

* testing

---------

Co-authored-by: Josh Allen <jallen@slack-corp.com>
This commit is contained in:
Josh Allen 2026-03-14 09:46:40 -04:00 committed by GitHub
commit 0e02d0278a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 279 additions and 28 deletions

View file

@ -46,7 +46,7 @@ function _omz_register_handler {
function _omz_async_request {
setopt localoptions noksharrays unset
local -i ret=$?
typeset -gA _OMZ_ASYNC_FDS _OMZ_ASYNC_PIDS _OMZ_ASYNC_OUTPUT
typeset -gA _OMZ_ASYNC_FDS _OMZ_ASYNC_PIDS _OMZ_ASYNC_OUTPUT _OMZ_ASYNC_PENDING
# executor runs a subshell for all async requests based on key
local handler
@ -79,6 +79,7 @@ function _omz_async_request {
# Define global variables to store the file descriptor, PID and output
_OMZ_ASYNC_FDS[$handler]=-1
_OMZ_ASYNC_PIDS[$handler]=-1
_OMZ_ASYNC_PENDING[$handler]=1
# Fork a process to fetch the git status and open a pipe to read from it
exec {fd}< <(
@ -117,14 +118,23 @@ function _omz_async_callback() {
# Get handler name from fd
local handler="${(k)_OMZ_ASYNC_FDS[(r)$fd]}"
# Store old output which is supposed to be already printed
# Store old output and pending state before updating
local old_output="${_OMZ_ASYNC_OUTPUT[$handler]}"
local was_pending="${_OMZ_ASYNC_PENDING[$handler]}"
# Mark handler as no longer pending
_OMZ_ASYNC_PENDING[$handler]=0
# Read output from fd
IFS= read -r -u $fd -d '' "_OMZ_ASYNC_OUTPUT[$handler]"
# Repaint prompt if output has changed
if [[ "$old_output" != "${_OMZ_ASYNC_OUTPUT[$handler]}" ]]; then
# Repaint prompt if output has changed, or if the git prompt handler was
# pending — even when the output is identical, the prompt needs redrawing
# to clear stale/unbolded styling applied while the handler was in-flight.
# Only the git handler uses pending-state styling, so other handlers skip
# the extra repaint to avoid unnecessary redraws.
if [[ "$old_output" != "${_OMZ_ASYNC_OUTPUT[$handler]}" ]] \
|| { (( was_pending )) && [[ "$handler" == _omz_git_prompt_info ]]; }; then
zle .reset-prompt
zle -R
fi