Skip to content

Commit 397f7c6

Browse files
Daniel Trstenjakgitster
authored andcommitted
Show the presence of untracked files in the bash prompt.
Added the envvar GIT_PS1_SHOWUNTRACKEDFILES to 'git-completion.bash'. When set to a nonempty value, then the char '%' will be shown next to the branch name in the bash prompt. Signed-off-by: Daniel Trstenjak <daniel.trstenjak@science-computing.de> Acked-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent f87dd21 commit 397f7c6

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

contrib/completion/git-completion.bash

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444
# GIT_PS1_SHOWSTASHSTATE to a nonempty value. If something is stashed,
4545
# then a '$' will be shown next to the branch name.
4646
#
47+
# If you would like to see if there're untracked files, then you can
48+
# set GIT_PS1_SHOWUNTRACKEDFILES to a nonempty value. If there're
49+
# untracked files, then a '%' will be shown next to the branch name.
50+
#
4751
# To submit patches:
4852
#
4953
# *) Read Documentation/SubmittingPatches
@@ -132,6 +136,7 @@ __git_ps1 ()
132136
local w
133137
local i
134138
local s
139+
local u
135140
local c
136141

137142
if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then
@@ -156,12 +161,18 @@ __git_ps1 ()
156161
if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ]; then
157162
git rev-parse --verify refs/stash >/dev/null 2>&1 && s="$"
158163
fi
164+
165+
if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ]; then
166+
if [ -n "$(git ls-files --others --exclude-standard)" ]; then
167+
u="%"
168+
fi
169+
fi
159170
fi
160171

161172
if [ -n "${1-}" ]; then
162-
printf "$1" "$c${b##refs/heads/}$w$i$s$r"
173+
printf "$1" "$c${b##refs/heads/}$w$i$s$u$r"
163174
else
164-
printf " (%s)" "$c${b##refs/heads/}$w$i$s$r"
175+
printf " (%s)" "$c${b##refs/heads/}$w$i$s$u$r"
165176
fi
166177
fi
167178
}

0 commit comments

Comments
 (0)