Show presence of stashed changes in bash prompt.
Add a '$' in the __git_ps1 output to show stashed changes are present, when GIT_PS1_SHOWSTASHSTATE is set to a nonempty value. The code for checking if the stash has entries is taken from 'git-stash.sh'. Signed-off-by: Daniel Trstenjak <daniel.trstenjak@online.de> Acked-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Daniel Trstenjak committed
Jun 2, 2009 at 20:03 UTC
2414b45ce0c56f7744e00e7fef3682a77375701e
1 file changed
+10
-2
contrib/completion/git-completion.bash
+10
-2
@@ -40,6 +40,10 @@
40
# with the bash.showDirtyState variable, which defaults to true
41
# once GIT_PS1_SHOWDIRTYSTATE is enabled.
42
#
43
+# You can also see if currently something is stashed, by setting
44
+# GIT_PS1_SHOWSTASHSTATE to a nonempty value. If something is stashed,
45
+# then a '$' will be shown next to the branch name.
46
+#
47
# To submit patches:
48
#
49
# *) Read Documentation/SubmittingPatches
@@ -127,6 +131,7 @@ __git_ps1 ()
131
132
local w
133
local i
134
+ local s
135
local c
136
137
if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then
@@ -148,12 +153,15 @@ __git_ps1 ()
153
fi
154
fi
155
fi
156
+ if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ]; then
157
+ git rev-parse --verify refs/stash >/dev/null 2>&1 && s="$"
158
+ fi
159
fi
160
161
if [ -n "${1-}" ]; then
154
- printf "$1" "$c${b##refs/heads/}$w$i$r"
162
+ printf "$1" "$c${b##refs/heads/}$w$i$s$r"
163
else
156
- printf " (%s)" "$c${b##refs/heads/}$w$i$r"
164
+ printf " (%s)" "$c${b##refs/heads/}$w$i$s$r"
165
fi
166
fi
167
}