@@ -7,12 +7,12 @@ _init_git_symbols() {
_colors_bash " $@ "
GIT_SYMBOLS[ pipe] = "\x7C "
GIT_SYMBOLS[ clean] = "✔ "
GIT_SYMBOLS[ dirty] = "∗ "
GIT_SYMBOLS[ pipe] = "| "
GIT_SYMBOLS[ clean] = "✓ "
GIT_SYMBOLS[ dirty] = "* "
GIT_SYMBOLS[ ahead] = "↑"
GIT_SYMBOLS[ behind] = "↓"
GIT_SYMBOLS[ diverged] = "⇅ "
GIT_SYMBOLS[ diverged] = "↕ "
GIT_SYMBOLS[ untracked] = "?"
GIT_SYMBOLS[ added] = "+"
GIT_SYMBOLS[ deleted] = "D"
@@ -46,11 +46,20 @@ _parse_git_status() {
# Single git status call
status_output = " $( git status --porcelain= v1 2>/dev/null) "
# Get ahead/behind counts in one call
# Get ahead/behind counts - use more reliable method
if git rev-parse --abbrev-ref "@{upstream}" >/dev/null 2>& 1; then
# Use separate commands for more reliable parsing
GIT_STATUS[ ahead] = " $( git rev-list --count HEAD ^"@{upstream}" 2>/dev/null || echo 0) "
GIT_STATUS[ behind] = " $( git rev-list --count "@{upstream}" ^HEAD 2>/dev/null || echo 0) "
# Fallback to original method if separate commands fail
if [ [ " ${ GIT_STATUS [ahead] } " = = "0" && " ${ GIT_STATUS [behind] } " = = "0" ] ] ; then
ahead_behind = " $( git rev-list --left-right --count "@{upstream}" ...HEAD 2>/dev/null) "
GIT_STATUS[ behind] = " ${ ahead_behind % * } "
GIT_STATUS[ ahea d] = " ${ ahead_behind #* } "
if [ [ " $ahead_behind " = ~ ^( [ 0-9] +) [ [ :space:] ] +( [ 0-9] +) $ ] ] ; then
GIT_STATUS[ behin d] = " ${ BASH_REMATCH [1] } "
GIT_STATUS[ ahead] = " ${ BASH_REMATCH [2] } "
fi
fi
else
GIT_STATUS[ behind] = 0
GIT_STATUS[ ahead] = 0
@@ -107,30 +116,32 @@ _get_git_status_fast() {
local output = ""
# Clean repo
if [ [ ${ GIT_STATUS [dirty] } -eq 0 ] ] ; then
echo -n " ${ BOLD } ${ CYA N} ${ GIT_SYMBOLS [clean] } ${ RESET } "
# Check if completely clean (no dirty files AND no ahead/behind)
if [ [ ${ GIT_STATUS [dirty] } -eq 0 && ${ GIT_STATUS [ahead] } -eq 0 && ${ GIT_STATUS [behind] } -eq 0 ] ] ; then
echo -n " ${ BOLD } ${ GREE N} ${ GIT_SYMBOLS [clean] } ${ RESET } "
return
fi
# Dirty count
output = " ${ BOLD } ${ RED } ${ GIT_SYMBOLS [dirty] } ${ GIT_STATUS [dirty] } ${ RESET } "
# Start with dirty indicator if there are dirty files
if [ [ ${ GIT_STATUS [dirty] } -gt 0 ] ] ; then
output = " ${ BOLD } ${ YELLOW } ${ GIT_SYMBOLS [dirty] } ${ GIT_STATUS [dirty] } ${ RESET } "
fi
# Ahead/behind
# Add a head/behind status with semantic colors
if [ [ ${ GIT_STATUS [ahead] } -gt 0 && ${ GIT_STATUS [behind] } -gt 0 ] ] ; then
output += " ${ BOLD } ${ YELLOW } ${ GIT_SYMBOLS [diverged] } ${ GIT_STATUS [ahead] } / ${ GIT_STATUS [behind] } ${ RESET } "
output += " ${ BOLD } ${ ORANGE } ${ GIT_SYMBOLS [diverged] } ${ GIT_STATUS [ahead] } / ${ GIT_STATUS [behind] } ${ RESET } "
elif [ [ ${ GIT_STATUS [ahead] } -gt 0 ] ] ; then
output += " ${ BOLD } ${ GREEN } ${ GIT_SYMBOLS [ahead] } ${ GIT_STATUS [ahead] } ${ RESET } "
elif [ [ ${ GIT_STATUS [behind] } -gt 0 ] ] ; then
output += " ${ BOLD } ${ RED } ${ GIT_SYMBOLS [behind] } ${ GIT_STATUS [behind] } ${ RESET } "
fi
# File status indicators
# File status indicators with semantic colors
[ [ ${ GIT_STATUS [staged] } -gt 0 ] ] && output += " ${ BOLD } ${ GREEN } ${ GIT_SYMBOLS [staged] } ${ RESET } "
[ [ ${ GIT_STATUS [untracked] } -gt 0 ] ] && output += " ${ BOLD } ${ RED } ${ GIT_SYMBOLS [untracked] } ${ RESET } "
[ [ ${ GIT_STATUS [untracked] } -gt 0 ] ] && output += " ${ BOLD } ${ G REY } ${ GIT_SYMBOLS [untracked] } ${ RESET } "
[ [ ${ GIT_STATUS [added] } -gt 0 ] ] && output += " ${ BOLD } ${ GREEN } ${ GIT_SYMBOLS [added] } ${ RESET } "
[ [ ${ GIT_STATUS [deleted] } -gt 0 ] ] && output += " ${ BOLD } ${ RED } ${ GIT_SYMBOLS [deleted] } ${ RESET } "
[ [ ${ GIT_STATUS [renamed] } -gt 0 ] ] && output += " ${ BOLD } ${ BLUE } ${ GIT_SYMBOLS [renamed] } ${ RESET } "
[ [ ${ GIT_STATUS [renamed] } -gt 0 ] ] && output += " ${ BOLD } ${ CYAN } ${ GIT_SYMBOLS [renamed] } ${ RESET } "
echo -n " $output "
}
@@ -144,7 +155,12 @@ _prompt_get_git_info_fast() {
if [ [ -n " $branch " ] ] ; then
local status
status = " $( _get_git_status_fast " $@ " ) "
printf '%b%s%s%b' " ${ BOLD } ${ YELLOW } " " git:( $branch " " $status " " ${ BOLD } ${ YELLOW } ) "
# Use different colors for different parts
printf '%bgit:(%b%s%b%s%b)%b' \
" ${ GREY } " \
" ${ BOLD } ${ LEMON } " " $branch " " ${ RESET } " \
" $status " \
" ${ GREY } " " ${ RESET } "
fi
}