From: Eduardo Bellido Bellido Date: Tue, 12 Nov 2013 22:54:07 +0000 (+0100) Subject: Added support to show commits ahead, commits behind and stashes count in Git X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=38575181da716e92e6ed737af2ae02bd0b7e73c0;p=common%2Fbash_it.git Added support to show commits ahead, commits behind and stashes count in Git through variables --- diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 001ca65..96c7cf0 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -70,18 +70,28 @@ function scm_prompt_info { } function git_prompt_vars { - if [[ -n $(git status -s 2> /dev/null |grep -v ^# |grep -v "working directory clean") ]]; then + SCM_GIT_AHEAD='' + SCM_GIT_BEHIND='' + SCM_GIT_STASH='' + local status="$(git status -bs --porcelain 2> /dev/null)" + if [[ -n "$(grep -v ^# <<< "${status}")" ]]; then SCM_DIRTY=1 - SCM_STATE=${GIT_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY} + SCM_STATE=${GIT_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY} else SCM_DIRTY=0 - SCM_STATE=${GIT_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN} + SCM_STATE=${GIT_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN} fi SCM_PREFIX=${GIT_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX} SCM_SUFFIX=${GIT_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX} local ref=$(git symbolic-ref HEAD 2> /dev/null) SCM_BRANCH=${ref#refs/heads/} 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]}" + local stash_count="$(git stash list | wc -l)" + [[ "${stash_count}" -gt 0 ]] && SCM_GIT_STASH=" {${stash_count}}" } function svn_prompt_vars {