diff options
| -rw-r--r-- | .config/bash/prompt | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/.config/bash/prompt b/.config/bash/prompt index 13316c3..82cdccf 100644 --- a/.config/bash/prompt +++ b/.config/bash/prompt @@ -25,16 +25,17 @@ function prompt_jobs() { ((job_count > 0)) && printf '%s:%s ' $'' "$job_count" } -# Diverging commits vs the upstream branch — empty when in sync, no upstream, or outside a repo +# Current branch (short SHA if detached) plus divergence vs upstream — empty outside a repo function prompt_git() { - local ahead behind - read -r ahead behind < <(git rev-list --left-right --count "HEAD...@{u}" 2>/dev/null) || return - ((ahead == 0 && behind == 0)) && return local green=$'\001\e[01;32m\002' red=$'\001\e[01;31m\002' reset=$'\001\e[00m\002' - local out= - ((ahead > 0)) && out+="${green}↑${ahead}${reset}" - ((behind > 0)) && out+="${red}↓${behind}${reset}" - printf '%s ' "$out" + local branch ahead behind diverge= + branch=$(git symbolic-ref --short HEAD 2>/dev/null) || branch=$(git rev-parse --short HEAD 2>/dev/null) || return + branch=$green'('$branch')'$reset + if read -r ahead behind < <(git rev-list --left-right --count "HEAD...@{u}" 2>/dev/null); then + ((ahead > 0)) && diverge+="${green}↑${ahead}${reset}" + ((behind > 0)) && diverge+="${red}↓${behind}${reset}" + fi + printf '%s%s ' "$branch" "${diverge:+ $diverge}" } PS1=${colors[bold_green]}'[\u@\h'${colors[bold_white]}' \W $(prompt_git)$(prompt_shlvl)$(prompt_jobs)${colors[bold_green]}]\$'${colors[reset]}' ' |
