Skip to content

Commit 2414b45

Browse files
Daniel Trstenjakgitster
authored andcommitted
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 <[email protected]> Acked-by: Shawn O. Pearce <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b11cf09 commit 2414b45

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

contrib/completion/git-completion.bash

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040
# with the bash.showDirtyState variable, which defaults to true
4141
# once GIT_PS1_SHOWDIRTYSTATE is enabled.
4242
#
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+
#
4347
# To submit patches:
4448
#
4549
# *) Read Documentation/SubmittingPatches
@@ -127,6 +131,7 @@ __git_ps1 ()
127131

128132
local w
129133
local i
134+
local s
130135
local c
131136

132137
if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then
@@ -148,12 +153,15 @@ __git_ps1 ()
148153
fi
149154
fi
150155
fi
156+
if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ]; then
157+
git rev-parse --verify refs/stash >/dev/null 2>&1 && s="$"
158+
fi
151159
fi
152160

153161
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"
155163
else
156-
printf " (%s)" "$c${b##refs/heads/}$w$i$r"
164+
printf " (%s)" "$c${b##refs/heads/}$w$i$s$r"
157165
fi
158166
fi
159167
}

0 commit comments

Comments
 (0)