Skip to content

Commit d8d99a1

Browse files
committed
Add state and step
fixes #360
1 parent f183825 commit d8d99a1

File tree

2 files changed

+54
-7
lines changed

2 files changed

+54
-7
lines changed

gitprompt.sh

+6-6
Original file line numberDiff line numberDiff line change
@@ -570,12 +570,12 @@ function updatePrompt() {
570570
__chk_gitvar_status 'REMOTE' '-n'
571571
if [[ $GIT_CLEAN -eq 0 ]] || [[ $GIT_PROMPT_CLEAN != "" ]]; then
572572
__add_status "$GIT_PROMPT_SEPARATOR"
573-
__chk_gitvar_status 'STAGED' '-ne 0'
574-
__chk_gitvar_status 'CONFLICTS' '-ne 0'
575-
__chk_gitvar_status 'CHANGED' '-ne 0'
576-
__chk_gitvar_status 'UNTRACKED' '-ne 0'
577-
__chk_gitvar_status 'STASHED' '-ne 0'
578-
__chk_gitvar_status 'CLEAN' '-eq 1' -
573+
__chk_gitvar_status 'STAGED' '!= "0" -a $GIT_STAGED != "^"'
574+
__chk_gitvar_status 'CONFLICTS' '!= "0"'
575+
__chk_gitvar_status 'CHANGED' '!= "0"'
576+
__chk_gitvar_status 'UNTRACKED' '!= "0"'
577+
__chk_gitvar_status 'STASHED' '!= "0"'
578+
__chk_gitvar_status 'CLEAN' '= "1"' -
579579
fi
580580
__add_status "$ResetColor$GIT_PROMPT_SUFFIX"
581581

gitstatus.sh

+48-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,53 @@ gitstatus=$( LC_ALL=C git status ${_ignore_submodules} --untracked-files=${__GIT
2626
# if the status is fatal, exit now
2727
[[ "$?" -ne 0 ]] && exit 0
2828

29+
git_dir="$(git rev-parse --git-dir 2>/dev/null)"
30+
[[ -z "$git_dir" ]] && exit 0
31+
32+
__git_prompt_read ()
33+
{
34+
local f="$1"
35+
shift
36+
test -r "$f" && read "$@" <"$f"
37+
}
38+
39+
state=""
40+
step=""
41+
total=""
42+
if [ -d "${git_dir}/rebase-merge" ]; then
43+
__git_prompt_read "${git_dir}/rebase-merge/msgnum" step
44+
__git_prompt_read "${git_dir}/rebase-merge/end" total
45+
if [ -f "${git_dir}/rebase-merge/interactive" ]; then
46+
state="|REBASE-i"
47+
else
48+
state="|REBASE-m"
49+
fi
50+
else
51+
if [ -d "${git_dir}/rebase-apply" ]; then
52+
__git_prompt_read "${git_dir}/rebase-apply/next" step
53+
__git_prompt_read "${git_dir}/rebase-apply/last" total
54+
if [ -f "${git_dir}/rebase-apply/rebasing" ]; then
55+
state="|REBASE"
56+
elif [ -f "${git_dir}/rebase-apply/applying" ]; then
57+
state="|AM"
58+
else
59+
state="|AM/REBASE"
60+
fi
61+
elif [ -f "${git_dir}/MERGE_HEAD" ]; then
62+
state="|MERGING"
63+
elif [ -f "${git_dir}/CHERRY_PICK_HEAD" ]; then
64+
state="|CHERRY-PICKING"
65+
elif [ -f "${git_dir}/REVERT_HEAD" ]; then
66+
state="|REVERTING"
67+
elif [ -f "${git_dir}/BISECT_LOG" ]; then
68+
state="|BISECTING"
69+
fi
70+
fi
71+
72+
if [ -n "$step" ] && [ -n "$total" ]; then
73+
state="${state} ${step}/${total}"
74+
fi
75+
2976
num_staged=0
3077
num_changed=0
3178
num_conflicts=0
@@ -118,7 +165,7 @@ if [[ -z "$upstream" ]] ; then
118165
fi
119166

120167
printf "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n" \
121-
"$branch" \
168+
"${branch}${state}" \
122169
"$remote" \
123170
"$upstream" \
124171
$num_staged \

0 commit comments

Comments
 (0)