From 54921d9294f981ccd79198f2cf6987d09a3a0fd1 Mon Sep 17 00:00:00 2001 From: Eduardo Bellido Bellido Date: Mon, 29 Dec 2014 02:26:09 +0100 Subject: [PATCH 1/9] Now git_prompt_vars indicates when HEAD not points to a branch --- themes/base.theme.bash | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 8b63189e..232fe222 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -34,7 +34,6 @@ RBFU_THEME_PROMPT_PREFIX=' |' RBFU_THEME_PROMPT_SUFFIX='|' function scm { - if [[ "$SCM_CHECK" = false ]]; then SCM=$SCM_NONE elif [[ -f .git/HEAD ]]; then SCM=$SCM_GIT elif which git &> /dev/null && [[ -n "$(git symbolic-ref HEAD 2> /dev/null)" ]]; then SCM=$SCM_GIT @@ -100,26 +99,35 @@ function git_prompt_vars { SCM_DIRTY=0 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 -q HEAD 2> /dev/null) - if [[ -n "$ref" ]]; then - SCM_BRANCH=${ref#refs/heads/} - SCM_IS_BRANCH=1 - SCM_IS_TAG=0 - else - SCM_BRANCH=$(git describe --tags --exact-match 2> /dev/null) - SCM_IS_TAG=1 - SCM_IS_BRANCH=0 - fi - 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 2> /dev/null | wc -l | tr -d ' ')" [[ "${stash_count}" -gt 0 ]] && SCM_GIT_STASH="{${stash_count}}" + + SCM_REF_TYPE="" + local ref=$(git symbolic-ref -q HEAD 2> /dev/null) + if [[ -n "$ref" ]]; then + SCM_BRANCH=${ref#refs/heads/} + SCM_REF_TYPE=branch + else + local commit_re='.+-g([a-zA-Z0-9]+)$' + ref=$(git describe --tags --all 2> /dev/null) + if [[ "$ref" =~ ${commit_re} ]]; then + SCM_BRANCH=${BASH_REMATCH[1]} + SCM_REF_TYPE=commit + SCM_IS_COMMIT=1 + else + SCM_BRANCH=${ref} + SCM_REF_TYPE=tag + fi + fi + + SCM_PREFIX=${GIT_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX} + SCM_SUFFIX=${GIT_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX} + SCM_CHANGE=$(git rev-parse HEAD 2>/dev/null) } function svn_prompt_vars { From b0ce36b8edbb53b55d5d0713bf9979fa6cd44470 Mon Sep 17 00:00:00 2001 From: Eduardo Bellido Bellido Date: Mon, 29 Dec 2014 02:38:00 +0100 Subject: [PATCH 2/9] Show ref type in git prompt in Powerline theme --- themes/powerline/powerline.theme.bash | 28 ++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/themes/powerline/powerline.theme.bash b/themes/powerline/powerline.theme.bash index bf7e33b3..0edd4f66 100644 --- a/themes/powerline/powerline.theme.bash +++ b/themes/powerline/powerline.theme.bash @@ -11,17 +11,15 @@ VIRTUALENV_THEME_PROMPT_COLOR=35 SCM_NONE_CHAR="" SCM_GIT_CHAR=" " -SCM_GIT_BEHIND_CHAR="↓" SCM_GIT_AHEAD_CHAR="↑" +SCM_GIT_BEHIND_CHAR="↓" SCM_GIT_UNTRACKED_CHAR="?:" SCM_GIT_UNSTAGED_CHAR="U:" SCM_GIT_STAGED_CHAR="S:" -if [[ -z "$THEME_SCM_TAG_PREFIX" ]]; then - SCM_TAG_PREFIX="tag > " -else - SCM_TAG_PREFIX="$THEME_SCM_TAG_PREFIX" -fi +SCM_THEME_BRANCH_PREFIX=${SCM_THEME_BRANCH_PREFIX:=} +SCM_THEME_TAG_PREFIX=${SCM_THEME_TAG_PREFIX:=tag:} +SCM_THEME_COMMIT_PREFIX=${SCM_THEME_COMMIT_PREFIX:=commit:} SCM_THEME_PROMPT_CLEAN="" SCM_THEME_PROMPT_DIRTY="" @@ -90,11 +88,19 @@ function powerline_scm_prompt { SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_CLEAN_COLOR} ${SCM_THEME_PROMPT_COLOR})" fi if [[ "${SCM_GIT_CHAR}" == "${SCM_CHAR}" ]]; then - local tag="" - if [[ $SCM_IS_TAG -eq "1" ]]; then - tag=$SCM_TAG_PREFIX - fi - SCM_PROMPT+=" ${SCM_CHAR}${tag}${SCM_BRANCH}${SCM_STATE} " + local ref_prefix="" + case ${SCM_REF_TYPE} in + branch) + ref_prefix=${SCM_THEME_BRANCH_PREFIX} + ;; + tag) + ref_prefix=${SCM_THEME_TAG_PREFIX} + ;; + commit) + ref_prefix=${SCM_THEME_COMMIT_PREFIX} + ;; + esac + SCM_PROMPT+=" ${SCM_CHAR}${ref_prefix}${SCM_BRANCH}${SCM_STATE} " [[ -n "${SCM_GIT_AHEAD}" ]] && SCM_PROMPT+="${SCM_GIT_AHEAD} " [[ -n "${SCM_GIT_BEHIND}" ]] && SCM_PROMPT+="${SCM_GIT_BEHIND} " [[ -n "${SCM_GIT_STAGED}" ]] && SCM_PROMPT+="${SCM_GIT_STAGED} " From 41b0677726156b95bd790fdc25a7cd99da74e690 Mon Sep 17 00:00:00 2001 From: Eduardo Bellido Bellido Date: Mon, 29 Dec 2014 02:38:09 +0100 Subject: [PATCH 3/9] Show ref type in git prompt in Powerline-plain theme --- .../powerline-plain.theme.bash | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/themes/powerline-plain/powerline-plain.theme.bash b/themes/powerline-plain/powerline-plain.theme.bash index 63606658..3caac981 100644 --- a/themes/powerline-plain/powerline-plain.theme.bash +++ b/themes/powerline-plain/powerline-plain.theme.bash @@ -9,17 +9,15 @@ VIRTUALENV_THEME_PROMPT_COLOR=35 SCM_NONE_CHAR="" SCM_GIT_CHAR="⎇ " -SCM_GIT_BEHIND_CHAR="↓" SCM_GIT_AHEAD_CHAR="↑" +SCM_GIT_BEHIND_CHAR="↓" SCM_GIT_UNTRACKED_CHAR="?:" SCM_GIT_UNSTAGED_CHAR="U:" SCM_GIT_STAGED_CHAR="S:" -if [[ -z "$THEME_SCM_TAG_PREFIX" ]]; then - SCM_TAG_PREFIX="tag > " -else - SCM_TAG_PREFIX="$THEME_SCM_TAG_PREFIX" -fi +SCM_THEME_BRANCH_PREFIX=${SCM_THEME_BRANCH_PREFIX:=} +SCM_THEME_TAG_PREFIX=${SCM_THEME_TAG_PREFIX:=tag:} +SCM_THEME_COMMIT_PREFIX=${SCM_THEME_COMMIT_PREFIX:=commit:} SCM_THEME_PROMPT_CLEAN="" SCM_THEME_PROMPT_DIRTY="" @@ -86,11 +84,19 @@ function powerline_scm_prompt { SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_CLEAN_COLOR} ${SCM_THEME_PROMPT_COLOR})" fi if [[ "${SCM_GIT_CHAR}" == "${SCM_CHAR}" ]]; then - local tag="" - if [[ $SCM_IS_TAG -eq "1" ]]; then - tag=$SCM_TAG_PREFIX - fi - SCM_PROMPT+=" ${SCM_CHAR}${tag}${SCM_BRANCH}${SCM_STATE} " + local ref_prefix="" + case ${SCM_REF_TYPE} in + branch) + ref_prefix=${SCM_THEME_BRANCH_PREFIX} + ;; + tag) + ref_prefix=${SCM_THEME_TAG_PREFIX} + ;; + commit) + ref_prefix=${SCM_THEME_COMMIT_PREFIX} + ;; + esac + SCM_PROMPT+=" ${SCM_CHAR}${ref_prefix}${SCM_BRANCH}${SCM_STATE} " [[ -n "${SCM_GIT_AHEAD}" ]] && SCM_PROMPT+="${SCM_GIT_AHEAD} " [[ -n "${SCM_GIT_BEHIND}" ]] && SCM_PROMPT+="${SCM_GIT_BEHIND} " [[ -n "${SCM_GIT_STAGED}" ]] && SCM_PROMPT+="${SCM_GIT_STAGED} " From 2830020c5dec304ae37e7c9dda74cffae29924c7 Mon Sep 17 00:00:00 2001 From: Eduardo Bellido Bellido Date: Mon, 29 Dec 2014 21:54:46 +0100 Subject: [PATCH 4/9] Added an option to show (defaults true) the details in git repos --- themes/base.theme.bash | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 232fe222..a8d065df 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -11,6 +11,7 @@ SCM_THEME_PROMPT_SUFFIX='|' SCM_GIT='git' SCM_GIT_CHAR='±' +SCM_GIT_SHOW_DETAILS=${SCM_GIT_SHOW_DETAILS:=true} SCM_HG='hg' SCM_HG_CHAR='☿' @@ -83,12 +84,14 @@ function git_prompt_vars { if [[ "$(git config --get bash-it.hide-status)" != "1" ]]; then local status="$(git status -b --porcelain 2> /dev/null || git status --porcelain 2> /dev/null)" if [[ -n "${status}" ]] && [[ "${status}" != "\n" ]] && [[ -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}" + if [[ "${SCM_GIT_SHOW_DETAILS}" = "true" ]]; 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}" + fi SCM_DIRTY=1 SCM_STATE=${GIT_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY} else @@ -104,6 +107,7 @@ function git_prompt_vars { 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 2> /dev/null | wc -l | tr -d ' ')" [[ "${stash_count}" -gt 0 ]] && SCM_GIT_STASH="{${stash_count}}" From 4b97037af428728bd3b29861c539fdd8ebf07f6c Mon Sep 17 00:00:00 2001 From: Eduardo Bellido Bellido Date: Wed, 31 Dec 2014 19:44:10 +0100 Subject: [PATCH 5/9] Moved some features from Powerline theme to base theme --- themes/base.theme.bash | 79 ++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 38 deletions(-) diff --git a/themes/base.theme.bash b/themes/base.theme.bash index a8d065df..13176e94 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -8,10 +8,20 @@ SCM_THEME_PROMPT_DIRTY=' ✗' SCM_THEME_PROMPT_CLEAN=' ✓' SCM_THEME_PROMPT_PREFIX=' |' SCM_THEME_PROMPT_SUFFIX='|' +SCM_THEME_BRANCH_PREFIX='' +SCM_THEME_TAG_PREFIX='tag:' +SCM_THEME_COMMIT_PREFIX='commit:' +SCM_THEME_REMOTE_PREFIX='' + +SCM_GIT_SHOW_DETAILS=${SCM_GIT_SHOW_DETAILS:=false} SCM_GIT='git' SCM_GIT_CHAR='±' -SCM_GIT_SHOW_DETAILS=${SCM_GIT_SHOW_DETAILS:=true} +SCM_GIT_AHEAD_CHAR="↑" +SCM_GIT_BEHIND_CHAR="↓" +SCM_GIT_UNTRACKED_CHAR="?:" +SCM_GIT_UNSTAGED_CHAR="U:" +SCM_GIT_STAGED_CHAR="S:" SCM_HG='hg' SCM_HG_CHAR='☿' @@ -75,59 +85,52 @@ function scm_prompt_info { } function git_prompt_vars { - SCM_GIT_AHEAD='' - SCM_GIT_BEHIND='' - SCM_GIT_STASH='' - SCM_GIT_UNTRACKED='' - SCM_GIT_UNSTAGED='' - SCM_GIT_STAGED='' + local details='' + SCM_STATE=${GIT_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN} if [[ "$(git config --get bash-it.hide-status)" != "1" ]]; then local status="$(git status -b --porcelain 2> /dev/null || git status --porcelain 2> /dev/null)" if [[ -n "${status}" ]] && [[ "${status}" != "\n" ]] && [[ -n "$(grep -v ^# <<< "${status}")" ]]; then + SCM_DIRTY=1 if [[ "${SCM_GIT_SHOW_DETAILS}" = "true" ]]; 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}" + [[ "${staged_count}" -gt 0 ]] && details+=" ${SCM_GIT_STAGED_CHAR}${staged_count}" && SCM_DIRTY=3 + [[ "${unstaged_count}" -gt 0 ]] && details+=" ${SCM_GIT_UNSTAGED_CHAR}${unstaged_count}" && SCM_DIRTY=2 + [[ "${untracked_count}" -gt 0 ]] && details+=" ${SCM_GIT_UNTRACKED_CHAR}${untracked_count}" && SCM_DIRTY=1 fi - SCM_DIRTY=1 SCM_STATE=${GIT_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY} - else - SCM_DIRTY=0 - SCM_STATE=${GIT_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN} fi + fi + + local ref=$(git symbolic-ref -q HEAD 2> /dev/null) + if [[ -n "$ref" ]]; then + SCM_BRANCH=${SCM_THEME_BRANCH_PREFIX}${ref#refs/heads/} else - SCM_DIRTY=0 - SCM_STATE=${GIT_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN} + ref=$(git describe --tags --exact-match 2> /dev/null) + if [[ -n "$ref" ]]; then + SCM_BRANCH=${SCM_THEME_TAG_PREFIX}${ref} + else + local commit_re='(^remotes/)?(.+-g[a-zA-Z0-9]+)$' + local remote_re='^remotes/(.+)$' + ref=$(git describe --tags --all --always 2> /dev/null) + if [[ "$ref" =~ ${commit_re} ]]; then + SCM_BRANCH=${SCM_THEME_COMMIT_PREFIX}${BASH_REMATCH[2]} + elif [[ "$ref" =~ ${remote_re} ]]; then + SCM_BRANCH=${SCM_THEME_REMOTE_PREFIX}${BASH_REMATCH[1]} + fi + fi fi 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_BRANCH+=" ${SCM_GIT_AHEAD_CHAR}${BASH_REMATCH[1]}" + [[ "${status}" =~ ${behind_re} ]] && SCM_BRANCH+=" ${SCM_GIT_BEHIND_CHAR}${BASH_REMATCH[1]}" local stash_count="$(git stash list 2> /dev/null | wc -l | tr -d ' ')" - [[ "${stash_count}" -gt 0 ]] && SCM_GIT_STASH="{${stash_count}}" + [[ "${stash_count}" -gt 0 ]] && SCM_BRANCH+=" {${stash_count}}" - SCM_REF_TYPE="" - local ref=$(git symbolic-ref -q HEAD 2> /dev/null) - if [[ -n "$ref" ]]; then - SCM_BRANCH=${ref#refs/heads/} - SCM_REF_TYPE=branch - else - local commit_re='.+-g([a-zA-Z0-9]+)$' - ref=$(git describe --tags --all 2> /dev/null) - if [[ "$ref" =~ ${commit_re} ]]; then - SCM_BRANCH=${BASH_REMATCH[1]} - SCM_REF_TYPE=commit - SCM_IS_COMMIT=1 - else - SCM_BRANCH=${ref} - SCM_REF_TYPE=tag - fi - fi + SCM_BRANCH+=${details} SCM_PREFIX=${GIT_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX} SCM_SUFFIX=${GIT_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX} @@ -137,10 +140,10 @@ function git_prompt_vars { function svn_prompt_vars { if [[ -n $(svn status 2> /dev/null) ]]; then SCM_DIRTY=1 - SCM_STATE=${SVN_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY} + SCM_STATE=${SVN_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY} else SCM_DIRTY=0 - SCM_STATE=${SVN_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN} + SCM_STATE=${SVN_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN} fi SCM_PREFIX=${SVN_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX} SCM_SUFFIX=${SVN_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX} From 01aaf69a96a293c6a0c129089e3be18ecfbceb42 Mon Sep 17 00:00:00 2001 From: Eduardo Bellido Bellido Date: Wed, 31 Dec 2014 19:45:10 +0100 Subject: [PATCH 6/9] Adapted Powerline theme to new base theme --- themes/powerline/powerline.theme.bash | 46 ++++++--------------------- 1 file changed, 9 insertions(+), 37 deletions(-) diff --git a/themes/powerline/powerline.theme.bash b/themes/powerline/powerline.theme.bash index 0edd4f66..a879ff17 100644 --- a/themes/powerline/powerline.theme.bash +++ b/themes/powerline/powerline.theme.bash @@ -11,15 +11,7 @@ VIRTUALENV_THEME_PROMPT_COLOR=35 SCM_NONE_CHAR="" SCM_GIT_CHAR=" " -SCM_GIT_AHEAD_CHAR="↑" -SCM_GIT_BEHIND_CHAR="↓" -SCM_GIT_UNTRACKED_CHAR="?:" -SCM_GIT_UNSTAGED_CHAR="U:" -SCM_GIT_STAGED_CHAR="S:" - -SCM_THEME_BRANCH_PREFIX=${SCM_THEME_BRANCH_PREFIX:=} -SCM_THEME_TAG_PREFIX=${SCM_THEME_TAG_PREFIX:=tag:} -SCM_THEME_COMMIT_PREFIX=${SCM_THEME_COMMIT_PREFIX:=commit:} +SCM_GIT_SHOW_DETAILS=true SCM_THEME_PROMPT_CLEAN="" SCM_THEME_PROMPT_DIRTY="" @@ -76,39 +68,19 @@ function powerline_scm_prompt { scm_prompt_vars if [[ "${SCM_NONE_CHAR}" != "${SCM_CHAR}" ]]; then - if [[ "${SCM_DIRTY}" -eq 1 ]]; then - if [[ -n "${SCM_GIT_STAGED}" ]]; then - SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_STAGED_COLOR} ${SCM_THEME_PROMPT_COLOR})" - elif [[ -n "${SCM_GIT_UNSTAGED}" ]]; then - SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_UNSTAGED_COLOR} ${SCM_THEME_PROMPT_COLOR})" - else - SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_DIRTY_COLOR} ${SCM_THEME_PROMPT_COLOR})" - fi + if [[ "${SCM_DIRTY}" -eq 3 ]]; then + SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_STAGED_COLOR} ${SCM_THEME_PROMPT_COLOR})" + elif [[ "${SCM_DIRTY}" -eq 2 ]]; then + SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_UNSTAGED_COLOR} ${SCM_THEME_PROMPT_COLOR})" + elif [[ "${SCM_DIRTY}" -eq 1 ]]; then + SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_DIRTY_COLOR} ${SCM_THEME_PROMPT_COLOR})" else SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_CLEAN_COLOR} ${SCM_THEME_PROMPT_COLOR})" fi if [[ "${SCM_GIT_CHAR}" == "${SCM_CHAR}" ]]; then - local ref_prefix="" - case ${SCM_REF_TYPE} in - branch) - ref_prefix=${SCM_THEME_BRANCH_PREFIX} - ;; - tag) - ref_prefix=${SCM_THEME_TAG_PREFIX} - ;; - commit) - ref_prefix=${SCM_THEME_COMMIT_PREFIX} - ;; - esac - SCM_PROMPT+=" ${SCM_CHAR}${ref_prefix}${SCM_BRANCH}${SCM_STATE} " - [[ -n "${SCM_GIT_AHEAD}" ]] && SCM_PROMPT+="${SCM_GIT_AHEAD} " - [[ -n "${SCM_GIT_BEHIND}" ]] && SCM_PROMPT+="${SCM_GIT_BEHIND} " - [[ -n "${SCM_GIT_STAGED}" ]] && SCM_PROMPT+="${SCM_GIT_STAGED} " - [[ -n "${SCM_GIT_UNSTAGED}" ]] && SCM_PROMPT+="${SCM_GIT_UNSTAGED} " - [[ -n "${SCM_GIT_UNTRACKED}" ]] && SCM_PROMPT+="${SCM_GIT_UNTRACKED} " - [[ -n "${SCM_GIT_STASH}" ]] && SCM_PROMPT+="${SCM_GIT_STASH} " + SCM_PROMPT+=" ${SCM_CHAR}${SCM_BRANCH}${SCM_STATE}" fi - SCM_PROMPT="$(set_rgb_color ${LAST_THEME_COLOR} ${SCM_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}${normal}${SCM_PROMPT}${normal}" + SCM_PROMPT="$(set_rgb_color ${LAST_THEME_COLOR} ${SCM_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}${normal}${SCM_PROMPT} ${normal}" LAST_THEME_COLOR=${SCM_THEME_PROMPT_COLOR} else SCM_PROMPT="" From 48f5763fc6ff825c1e20ee32945e9ed780dbf8aa Mon Sep 17 00:00:00 2001 From: Eduardo Bellido Bellido Date: Wed, 31 Dec 2014 19:57:41 +0100 Subject: [PATCH 7/9] Adapted Powerline-plain theme to new base theme --- .../powerline-plain.theme.bash | 44 ++++--------------- 1 file changed, 8 insertions(+), 36 deletions(-) diff --git a/themes/powerline-plain/powerline-plain.theme.bash b/themes/powerline-plain/powerline-plain.theme.bash index 3caac981..0ea915f3 100644 --- a/themes/powerline-plain/powerline-plain.theme.bash +++ b/themes/powerline-plain/powerline-plain.theme.bash @@ -9,15 +9,7 @@ VIRTUALENV_THEME_PROMPT_COLOR=35 SCM_NONE_CHAR="" SCM_GIT_CHAR="⎇ " -SCM_GIT_AHEAD_CHAR="↑" -SCM_GIT_BEHIND_CHAR="↓" -SCM_GIT_UNTRACKED_CHAR="?:" -SCM_GIT_UNSTAGED_CHAR="U:" -SCM_GIT_STAGED_CHAR="S:" - -SCM_THEME_BRANCH_PREFIX=${SCM_THEME_BRANCH_PREFIX:=} -SCM_THEME_TAG_PREFIX=${SCM_THEME_TAG_PREFIX:=tag:} -SCM_THEME_COMMIT_PREFIX=${SCM_THEME_COMMIT_PREFIX:=commit:} +SCM_GIT_SHOW_DETAILS=true SCM_THEME_PROMPT_CLEAN="" SCM_THEME_PROMPT_DIRTY="" @@ -72,37 +64,17 @@ function powerline_scm_prompt { scm_prompt_vars if [[ "${SCM_NONE_CHAR}" != "${SCM_CHAR}" ]]; then - if [[ "${SCM_DIRTY}" -eq 1 ]]; then - if [[ -n "${SCM_GIT_STAGED}" ]]; then - SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_STAGED_COLOR} ${SCM_THEME_PROMPT_COLOR})" - elif [[ -n "${SCM_GIT_UNSTAGED}" ]]; then - SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_UNSTAGED_COLOR} ${SCM_THEME_PROMPT_COLOR})" - else - SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_DIRTY_COLOR} ${SCM_THEME_PROMPT_COLOR})" - fi + if [[ "${SCM_DIRTY}" -eq 3 ]]; then + SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_STAGED_COLOR} ${SCM_THEME_PROMPT_COLOR})" + elif [[ "${SCM_DIRTY}" -eq 2 ]]; then + SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_UNSTAGED_COLOR} ${SCM_THEME_PROMPT_COLOR})" + elif [[ "${SCM_DIRTY}" -eq 1 ]]; then + SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_DIRTY_COLOR} ${SCM_THEME_PROMPT_COLOR})" else SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_CLEAN_COLOR} ${SCM_THEME_PROMPT_COLOR})" fi if [[ "${SCM_GIT_CHAR}" == "${SCM_CHAR}" ]]; then - local ref_prefix="" - case ${SCM_REF_TYPE} in - branch) - ref_prefix=${SCM_THEME_BRANCH_PREFIX} - ;; - tag) - ref_prefix=${SCM_THEME_TAG_PREFIX} - ;; - commit) - ref_prefix=${SCM_THEME_COMMIT_PREFIX} - ;; - esac - SCM_PROMPT+=" ${SCM_CHAR}${ref_prefix}${SCM_BRANCH}${SCM_STATE} " - [[ -n "${SCM_GIT_AHEAD}" ]] && SCM_PROMPT+="${SCM_GIT_AHEAD} " - [[ -n "${SCM_GIT_BEHIND}" ]] && SCM_PROMPT+="${SCM_GIT_BEHIND} " - [[ -n "${SCM_GIT_STAGED}" ]] && SCM_PROMPT+="${SCM_GIT_STAGED} " - [[ -n "${SCM_GIT_UNSTAGED}" ]] && SCM_PROMPT+="${SCM_GIT_UNSTAGED} " - [[ -n "${SCM_GIT_UNTRACKED}" ]] && SCM_PROMPT+="${SCM_GIT_UNTRACKED} " - [[ -n "${SCM_GIT_STASH}" ]] && SCM_PROMPT+="${SCM_GIT_STASH} " + SCM_PROMPT+=" ${SCM_CHAR}${SCM_BRANCH}${SCM_STATE} " fi SCM_PROMPT="${SCM_PROMPT}${normal}" else From 5632575efe85ce049a874d259612b3e2ae7a6b41 Mon Sep 17 00:00:00 2001 From: Eduardo Bellido Bellido Date: Mon, 5 Jan 2015 20:19:38 +0100 Subject: [PATCH 8/9] Updated README.md --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index 53fe7384..981fe532 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,19 @@ Set `SCM_CHECK` to 'true' (the default value) to **turn on** version control che **NOTE:** It is possible for themes to ignore the `SCM_CHECK` flag and query specific version control information directly. For example, themes that use functions like `git_prompt_vars` skip the `SCM_CHECK` flag to retrieve and display git prompt information. If you turned version control checking off and you still see version control information within your prompt, then functions like `git_prompt_vars` are most likely the reason why. +### Git repository info in the prompt +Bash it can show some information about Git repositories in the shell prompt: the current branch, tag or commit you are at, how many commits the local branch is ahead or behind from the remote branch, and if you have changes stashed. + +Additionally, you can view the status of your working copy and get the count of staged, unstaged and untracked files. This feature is controlled through the flag `SCM_GIT_SHOW_DETAILS` as follows: + +Set `SCM_GIT_SHOW_DETAILS` to 'true' to **show** the working copy details in your prompt: + +* `export SCM_GIT_SHOW_DETAILS=true` + +Set `SCM_GIT_SHOW_DETAILS` to 'false' (the default value) to **don't show** it: + +* `export SCM_GIT_SHOW_DETAILS=false` + ## Help out I think everyone has their own custom scripts accumulated over time. And so, following in the footsteps of oh-my-zsh, bash it is a framework for easily customizing your bash shell. Everyone's got a custom toolbox, so let's start making them even better, **as a community!** From 418e6fae14825adde76a8b77880ce8b75089f5d2 Mon Sep 17 00:00:00 2001 From: Eduardo Bellido Bellido Date: Tue, 6 Jan 2015 12:57:57 +0100 Subject: [PATCH 9/9] Changed default value to true for SCM_GIT_SHOW_DETAILS --- README.md | 4 ++-- themes/base.theme.bash | 2 +- themes/powerline-plain/powerline-plain.theme.bash | 1 - themes/powerline/powerline.theme.bash | 1 - 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 981fe532..5ab37632 100644 --- a/README.md +++ b/README.md @@ -71,11 +71,11 @@ Bash it can show some information about Git repositories in the shell prompt: th Additionally, you can view the status of your working copy and get the count of staged, unstaged and untracked files. This feature is controlled through the flag `SCM_GIT_SHOW_DETAILS` as follows: -Set `SCM_GIT_SHOW_DETAILS` to 'true' to **show** the working copy details in your prompt: +Set `SCM_GIT_SHOW_DETAILS` to 'true' (the default value) to **show** the working copy details in your prompt: * `export SCM_GIT_SHOW_DETAILS=true` -Set `SCM_GIT_SHOW_DETAILS` to 'false' (the default value) to **don't show** it: +Set `SCM_GIT_SHOW_DETAILS` to 'false' to **don't show** it: * `export SCM_GIT_SHOW_DETAILS=false` diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 13176e94..584fb9ce 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -13,7 +13,7 @@ SCM_THEME_TAG_PREFIX='tag:' SCM_THEME_COMMIT_PREFIX='commit:' SCM_THEME_REMOTE_PREFIX='' -SCM_GIT_SHOW_DETAILS=${SCM_GIT_SHOW_DETAILS:=false} +SCM_GIT_SHOW_DETAILS=${SCM_GIT_SHOW_DETAILS:=true} SCM_GIT='git' SCM_GIT_CHAR='±' diff --git a/themes/powerline-plain/powerline-plain.theme.bash b/themes/powerline-plain/powerline-plain.theme.bash index 0ea915f3..dbe0f7c2 100644 --- a/themes/powerline-plain/powerline-plain.theme.bash +++ b/themes/powerline-plain/powerline-plain.theme.bash @@ -9,7 +9,6 @@ VIRTUALENV_THEME_PROMPT_COLOR=35 SCM_NONE_CHAR="" SCM_GIT_CHAR="⎇ " -SCM_GIT_SHOW_DETAILS=true SCM_THEME_PROMPT_CLEAN="" SCM_THEME_PROMPT_DIRTY="" diff --git a/themes/powerline/powerline.theme.bash b/themes/powerline/powerline.theme.bash index a879ff17..1bc4eca9 100644 --- a/themes/powerline/powerline.theme.bash +++ b/themes/powerline/powerline.theme.bash @@ -11,7 +11,6 @@ VIRTUALENV_THEME_PROMPT_COLOR=35 SCM_NONE_CHAR="" SCM_GIT_CHAR=" " -SCM_GIT_SHOW_DETAILS=true SCM_THEME_PROMPT_CLEAN="" SCM_THEME_PROMPT_DIRTY=""