Skip to content

Commit 286732d

Browse files
authored
.vcs_git: fix condition of return; fix bug in .git
Update 18#; Fix #15.
1 parent de0c9c8 commit 286732d

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

bashrc.d/.vcs_git

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,17 @@ alias __git_branch="git branch 2>/dev/null | grep '*' | sed 's/*\ //g'"
3232
# From http://mediadoneright.com/content/ultimate-git-ps1-bash-prompt
3333
# Modified.
3434
_git_status() {
35-
local gbr=$(git branch 2>/dev/null) || return 1
35+
local gbr
36+
gbr=$(git branch 2>/dev/null) || return 1
3637
gbr=$(printf %s "$gbr" | grep '*' | sed 's/*\ //g')
37-
local gst=$(LC_ALL=C git status)
38-
if printf %s "$gst" | grep -q "nothing to commit"; then
38+
local gst
39+
gst=$(LC_ALL=C git status 2>&1)
40+
if printf %s "$gst" | grep -q "nothing to commit"; then
3941
echo -e "\01\e[1m\02@\01\e[0;32m\0002$gbr\01\e[0m\02"
40-
elif printf %s "$gst" || grep -q "nothing added to commit"; then # Untracked
42+
elif printf %s "$gst" | grep -q "nothing added to commit"; then # Untracked
4143
echo -e "\01\e[1m\02@\01\e[0;35m\0002$gbr\01\e[0m\02"
44+
elif printf %s "$gst" | grep -q "must be run in a work tree"; then # Not in work tree
45+
echo -e "\01\e[1m\02@\01\e[0;37m\0002$gbr\01\e[0m\02"
4246
else # Change not added/not merged yet
4347
echo -e "\01\e[1m\02@\01$IRED\0002$gbr\01\e[0m\02"
4448
fi

0 commit comments

Comments
 (0)