Skip to content

Commit a65647d

Browse files
committed
fix: git changes update
1 parent 93dbad1 commit a65647d

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

configs/zsh/.zshrc

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,34 @@ ICON=""
5757

5858

5959

60+
61+
6062
git_prompt() {
6163
command git rev-parse --is-inside-work-tree &>/dev/null || return
6264

63-
local branch dirty
65+
local branch staged unstaged out
6466

6567
branch=$(command git symbolic-ref --short HEAD 2>/dev/null \
6668
|| command git describe --tags --exact-match 2>/dev/null)
6769

68-
command git diff --quiet --ignore-submodules HEAD &>/dev/null || dirty="*"
70+
# Count staged files
71+
staged=$(git diff --cached --name-only 2>/dev/null | wc -l | tr -d ' ')
72+
73+
# Count unstaged + untracked files
74+
unstaged=$(
75+
{ git diff --name-only 2>/dev/null
76+
git ls-files --others --exclude-standard 2>/dev/null; } | sort -u | wc -l | tr -d ' '
77+
)
78+
79+
out="%F{213} ${branch}%f"
80+
81+
# Show staged count
82+
(( staged > 0 )) && out+=" %F{82}${staged}%f"
83+
84+
# Show unstaged / untracked count
85+
(( unstaged > 0 )) && out+=" %F{226}${unstaged}%f"
6986

70-
echo "%F{213}  ${branch}${dirty}%f"
87+
print -P "$out"
7188
}
7289

7390

0 commit comments

Comments
 (0)