@matheusbsbs / matheus-bagliano / commits / 397f7c6371
Fork 0

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>

Daniel Trstenjak committed Jul 22, 2009 at 10:31 UTC 397f7c6371d309aa399bf32b773397f3c068d0c9
1 file changed +13 -2
contrib/completion/git-completion.bash
+13 -2
@@ -44,6 +44,10 @@
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 +# 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 +#
51 # To submit patches:
52 #
53 # *) Read Documentation/SubmittingPatches
@@ -132,6 +136,7 @@ __git_ps1 ()
136 local w
137 local i
138 local s
139 + local u
140 local c
141
142 if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then
@@ -156,12 +161,18 @@ __git_ps1 ()
161 if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ]; then
162 git rev-parse --verify refs/stash >/dev/null 2>&1 && s="$"
163 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
170 fi
171
172 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"
174 else
164 - printf " (%s)" "$c${b##refs/heads/}$w$i$s$r"
175 + printf " (%s)" "$c${b##refs/heads/}$w$i$s$u$r"
176 fi
177 fi
178 }