diff options
Diffstat (limited to 'hyperterm/core')
| -rw-r--r-- | hyperterm/core/git.sh | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/hyperterm/core/git.sh b/hyperterm/core/git.sh index 8b285ab..1e11bde 100644 --- a/hyperterm/core/git.sh +++ b/hyperterm/core/git.sh @@ -13,6 +13,7 @@ _init_git_symbols() { GIT_SYMBOLS[ahead]="↑" GIT_SYMBOLS[behind]="↓" GIT_SYMBOLS[diverged]="↕" + GIT_SYMBOLS[no_upstream]="○" GIT_SYMBOLS[untracked]="?" GIT_SYMBOLS[added]="+" GIT_SYMBOLS[deleted]="D" @@ -48,6 +49,7 @@ _parse_git_status() { # Get ahead/behind counts - use more reliable method if git rev-parse --abbrev-ref "@{upstream}" >/dev/null 2>&1; then + GIT_STATUS[has_upstream]=1 # 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)" @@ -61,6 +63,7 @@ _parse_git_status() { fi fi else + GIT_STATUS[has_upstream]=0 GIT_STATUS[behind]=0 GIT_STATUS[ahead]=0 fi @@ -116,24 +119,40 @@ _get_git_status_fast() { local output="" - # 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 + # Check if completely clean (no dirty files AND no ahead/behind AND has upstream) + if [[ ${GIT_STATUS[dirty]} -eq 0 && ${GIT_STATUS[ahead]} -eq 0 && ${GIT_STATUS[behind]} -eq 0 && ${GIT_STATUS[has_upstream]} -eq 1 ]]; then echo -n "${BOLD}${CYAN}${GIT_SYMBOLS[clean]}${RESET}" return fi + # Check if clean but no upstream (local branch only) + if [[ ${GIT_STATUS[dirty]} -eq 0 && ${GIT_STATUS[has_upstream]} -eq 0 ]]; then + echo -n "${BOLD}${PURPLE}${GIT_SYMBOLS[no_upstream]}${RESET}" + return + fi + # 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 # Add ahead/behind status with semantic colors - if [[ ${GIT_STATUS[ahead]} -gt 0 && ${GIT_STATUS[behind]} -gt 0 ]]; then - 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}" + if [[ ${GIT_STATUS[has_upstream]} -eq 1 ]]; then + # Create pattern: "ahead_behind" (0=false, 1=true) + local ahead_flag + local behind_flag + ahead_flag=$([[ ${GIT_STATUS[ahead]} -gt 0 ]] && echo "1" || echo "0") + behind_flag=$([[ ${GIT_STATUS[behind]} -gt 0 ]] && echo "1" || echo "0") + + case "${ahead_flag}${behind_flag}" in + "11") output+="${BOLD}${ORANGE}${GIT_SYMBOLS[diverged]}${GIT_STATUS[ahead]}/${GIT_STATUS[behind]}${RESET}" ;; + "10") output+="${BOLD}${GREEN}${GIT_SYMBOLS[ahead]}${GIT_STATUS[ahead]}${RESET}" ;; + "01") output+="${BOLD}${RED}${GIT_SYMBOLS[behind]}${GIT_STATUS[behind]}${RESET}" ;; + "00") ;; # Clean state, no additional symbol needed + esac + else + # No upstream - show no-upstream indicator + output+="${BOLD}${PURPLE}${GIT_SYMBOLS[no_upstream]}${RESET}" fi # File status indicators with semantic colors |
