Skip to content

Commit c2701bb

Browse files
authored
.d/vcs_git: cache git info in git status
We should probably copy from git's contrib/completion
1 parent 719b13a commit c2701bb

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

bashrc.d/.vcs_git

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@ 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-
git branch &>/dev/null || return 1
36-
if LC_ALL=C git status | grep -q "nothing to commit"; then
37-
echo -e "\01\e[1m\02@\01\e[0;32m\0002$(__git_branch)\01\e[0m\02"
38-
elif LC_ALL=C git status | grep -q "nothing added to commit"; then # Untracked
39-
echo -e "\01\e[1m\02@\01\e[0;35m\0002$(__git_branch)\01\e[0m\02"
35+
local gbr=$(git branch 2>/dev/null) || return 1
36+
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
39+
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
41+
echo -e "\01\e[1m\02@\01\e[0;35m\0002$gbr\01\e[0m\02"
4042
else # Change not added/not merged yet
41-
echo -e "\01\e[1m\02@\01$IRED\0002$(__git_branch)\01\e[0m\02"
43+
echo -e "\01\e[1m\02@\01$IRED\0002$gbr\01\e[0m\02"
4244
fi
4345
}
4446

0 commit comments

Comments
 (0)