Code

Show presence of stashed changes in bash prompt.
authorDaniel Trstenjak <daniel.trstenjak@online.de>
Tue, 2 Jun 2009 18:03:22 +0000 (20:03 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 4 Jun 2009 05:38:17 +0000 (22:38 -0700)
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>
contrib/completion/git-completion.bash

index 98b9cbedc2bcae32491fc69641740b186a64ab26..80190a6b165f22c28be8c94db735abdaafccc85a 100755 (executable)
 #       with the bash.showDirtyState variable, which defaults to true
 #       once GIT_PS1_SHOWDIRTYSTATE is enabled.
 #
+#       You can also see if currently something is stashed, by setting
+#       GIT_PS1_SHOWSTASHSTATE to a nonempty value. If something is stashed,
+#       then a '$' will be shown next to the branch name.
+#
 # To submit patches:
 #
 #    *) Read Documentation/SubmittingPatches
@@ -127,6 +131,7 @@ __git_ps1 ()
 
                local w
                local i
+               local s
                local c
 
                if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then
@@ -148,12 +153,15 @@ __git_ps1 ()
                                        fi
                                fi
                        fi
+                       if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ]; then
+                               git rev-parse --verify refs/stash >/dev/null 2>&1 && s="$"
+                       fi
                fi
 
                if [ -n "${1-}" ]; then
-                       printf "$1" "$c${b##refs/heads/}$w$i$r"
+                       printf "$1" "$c${b##refs/heads/}$w$i$s$r"
                else
-                       printf " (%s)" "$c${b##refs/heads/}$w$i$r"
+                       printf " (%s)" "$c${b##refs/heads/}$w$i$s$r"
                fi
        fi
 }