Skip to content

Commit 3d22ee2

Browse files
author
Steve Losh
committed
Improve the git prompt.
1 parent aa15f1b commit 3d22ee2

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

lib/git.zsh

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,18 @@ function git_prompt_info() {
55
}
66

77
parse_git_dirty () {
8-
if [[ $((git status 2> /dev/null) | tail -n1) != "nothing to commit (working directory clean)" ]]; then
9-
echo "$ZSH_THEME_GIT_PROMPT_DIRTY"
10-
else
11-
echo "$ZSH_THEME_GIT_PROMPT_CLEAN"
8+
gitstat=$(git status 2>/dev/null | grep '\(# Untracked\|# Changes\|# Changed but not updated:\)')
9+
10+
if [[ $(echo ${gitstat} | grep -c "^# Changes to be committed:$") > 0 ]]; then
11+
echo -n "$ZSH_THEME_GIT_PROMPT_DIRTY"
12+
fi
13+
14+
if [[ $(echo ${gitstat} | grep -c "^\(# Untracked files:\|# Changed but not updated:\)$") > 0 ]]; then
15+
echo -n "$ZSH_THEME_GIT_PROMPT_UNTRACKED"
16+
fi
17+
18+
if [[ $(echo ${gitstat} | wc -l | tr -d ' ') == 0 ]]; then
19+
echo -n "$ZSH_THEME_GIT_PROMPT_CLEAN"
1220
fi
1321
}
1422

themes/prose.zsh-theme

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,5 @@ RPROMPT='$(battery_charge)'
3333
ZSH_THEME_GIT_PROMPT_PREFIX=" on %{$fg[magenta]%}"
3434
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
3535
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[green]%}!"
36+
ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg[green]%}?"
3637
ZSH_THEME_GIT_PROMPT_CLEAN=""

0 commit comments

Comments
 (0)