Show Git root on prompt

- Show Git root folder name when SCM_THEME_ROOT_SUFFIX is set
- Default is off
pull/537/head
Heikki Ritola 2015-06-24 16:45:35 +03:00 committed by Heikki Ritola
parent 766eb1f8c9
commit 0a79b24ecf
1 changed files with 10 additions and 0 deletions

View File

@ -12,6 +12,7 @@ SCM_THEME_BRANCH_PREFIX=''
SCM_THEME_TAG_PREFIX='tag:'
SCM_THEME_COMMIT_PREFIX='commit:'
SCM_THEME_REMOTE_PREFIX=''
SCM_THEME_ROOT_SUFFIX=''
SCM_GIT_SHOW_DETAILS=${SCM_GIT_SHOW_DETAILS:=true}
@ -84,6 +85,10 @@ function scm_prompt_info {
[[ $SCM == $SCM_SVN ]] && svn_prompt_info && return
}
function get_git_root {
basename $(git rev-parse --show-toplevel)
}
function git_prompt_vars {
local details=''
SCM_STATE=${GIT_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN}
@ -122,6 +127,11 @@ function git_prompt_vars {
fi
fi
if [[ -n "$SCM_THEME_ROOT_SUFFIX" ]]; then
SCM_GIT_ROOT=$(get_git_root)
SCM_BRANCH=$(echo ${SCM_GIT_ROOT}${SCM_THEME_ROOT_SUFFIX}${SCM_BRANCH})
fi
local ahead_re='.+ahead ([0-9]+).+'
local behind_re='.+behind ([0-9]+).+'
[[ "${status}" =~ ${ahead_re} ]] && SCM_BRANCH+=" ${SCM_GIT_AHEAD_CHAR}${BASH_REMATCH[1]}"