@matheusbsbs / matheus-bagliano / commits / e75201963f
Fork 0

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 <robin.rosenberg@dewire.com> Acked-by: Shawn O. Pearce <spearce@spearce.org>

Robin Rosenberg committed Sep 30, 2007 at 02:20 UTC e75201963f6722ad84491c8f17dff8406ec0a198
1 file changed +33 -4
contrib/completion/git-completion.bash
+33 -4
@@ -64,12 +64,41 @@ __gitdir ()
64
65 __git_ps1 ()
66 {
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 +
98 if [ -n "$1" ]; then
70 - printf "$1" "${b##refs/heads/}"
99 + printf "$1" "${b##refs/heads/}$r"
100 else
72 - printf " (%s)" "${b##refs/heads/}"
101 + printf " (%s)" "${b##refs/heads/}$r"
102 fi
103 fi
104 }