From 37e5e832d11c3a67c4908152b054caa1a1fba640 Mon Sep 17 00:00:00 2001 From: Eduardo Bellido Bellido Date: Tue, 11 Feb 2014 22:00:29 +0100 Subject: [PATCH] More info about Git repository added Now, staged, unstaged and untracked files count can be shown in themes --- themes/base.theme.bash | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 629e81d7..500f49e3 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -73,8 +73,17 @@ function git_prompt_vars { SCM_GIT_AHEAD='' SCM_GIT_BEHIND='' SCM_GIT_STASH='' - local status="$(git status -bs --porcelain 2> /dev/null)" + SCM_GIT_UNTRACKED='' + SCM_GIT_UNSTAGED='' + SCM_GIT_STAGED='' + local status=$(git status -bs --porcelain 2> /dev/null) if [[ -n "$(grep -v ^# <<< "${status}")" ]]; then + local untracked_count="$(egrep -c '^\?\? .+' <<< "${status}")" + local unstaged_count="$(egrep -c '^.[^ ?#] .+' <<< "${status}")" + local staged_count="$(egrep -c '^[^ ?#]. .+' <<< "${status}")" + [[ "${untracked_count}" -gt 0 ]] && SCM_GIT_UNTRACKED="${SCM_GIT_UNTRACKED_CHAR}${untracked_count}" + [[ "${unstaged_count}" -gt 0 ]] && SCM_GIT_UNSTAGED="${SCM_GIT_UNSTAGED_CHAR}${unstaged_count}" + [[ "${staged_count}" -gt 0 ]] && SCM_GIT_STAGED="${SCM_GIT_STAGED_CHAR}${staged_count}" SCM_DIRTY=1 SCM_STATE=${GIT_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY} else @@ -88,10 +97,10 @@ function git_prompt_vars { SCM_CHANGE=$(git rev-parse HEAD 2>/dev/null) local ahead_re='.+ahead ([0-9]+).+' local behind_re='.+behind ([0-9]+).+' - [[ "${status}" =~ ${ahead_re} ]] && SCM_GIT_AHEAD=" ${SCM_GIT_AHEAD_CHAR}${BASH_REMATCH[1]}" - [[ "${status}" =~ ${behind_re} ]] && SCM_GIT_BEHIND=" ${SCM_GIT_BEHIND_CHAR}${BASH_REMATCH[1]}" + [[ "${status}" =~ ${ahead_re} ]] && SCM_GIT_AHEAD="${SCM_GIT_AHEAD_CHAR}${BASH_REMATCH[1]}" + [[ "${status}" =~ ${behind_re} ]] && SCM_GIT_BEHIND="${SCM_GIT_BEHIND_CHAR}${BASH_REMATCH[1]}" local stash_count="$(git stash list | wc -l | tr -d ' ')" - [[ "${stash_count}" -gt 0 ]] && SCM_GIT_STASH=" {${stash_count}}" + [[ "${stash_count}" -gt 0 ]] && SCM_GIT_STASH="{${stash_count}}" } function svn_prompt_vars {