Skip to content

Commit e752019

Browse files
robinrosenberggitster
authored andcommitted
Improve bash prompt to detect various states like an unfinished merge
This patch makes the git prompt (when enabled) show if a merge or a rebase is unfinished. It also detects if a bisect is being done as well as detached checkouts. An uncompleted git-am cannot be distinguised from a rebase (the non-interactive version). Instead of having an even longer prompt we simply ignore that and hope the power users that use git-am knows the difference. Signed-off-by: Robin Rosenberg <[email protected]> Acked-by: Shawn O. Pearce <[email protected]>
1 parent b828fef commit e752019

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

contrib/completion/git-completion.bash

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,41 @@ __gitdir ()
6464

6565
__git_ps1 ()
6666
{
67-
local b="$(git symbolic-ref HEAD 2>/dev/null)"
68-
if [ -n "$b" ]; then
67+
local g="$(git rev-parse --git-dir 2>/dev/null)"
68+
if [ -n "$g" ]; then
69+
local r
70+
local b
71+
if [ -d "$g/../.dotest" ]
72+
then
73+
r="|AM/REBASE"
74+
b="$(git symbolic-ref HEAD 2>/dev/null)"
75+
elif [ -f "$g/.dotest-merge/interactive" ]
76+
then
77+
r="|REBASE-i"
78+
b="$(cat $g/.dotest-merge/head-name)"
79+
elif [ -d "$g/.dotest-merge" ]
80+
then
81+
r="|REBASE-m"
82+
b="$(cat $g/.dotest-merge/head-name)"
83+
elif [ -f "$g/MERGE_HEAD" ]
84+
then
85+
r="|MERGING"
86+
b="$(git symbolic-ref HEAD 2>/dev/null)"
87+
else
88+
if [ -f $g/BISECT_LOG ]
89+
then
90+
r="|BISECTING"
91+
fi
92+
if ! b="$(git symbolic-ref HEAD 2>/dev/null)"
93+
then
94+
b="$(cut -c1-7 $g/HEAD)..."
95+
fi
96+
fi
97+
6998
if [ -n "$1" ]; then
70-
printf "$1" "${b##refs/heads/}"
99+
printf "$1" "${b##refs/heads/}$r"
71100
else
72-
printf " (%s)" "${b##refs/heads/}"
101+
printf " (%s)" "${b##refs/heads/}$r"
73102
fi
74103
fi
75104
}

0 commit comments

Comments
 (0)