From 4b8c8da3ef06cb258d6a5a429e45bb0b94e05024 Mon Sep 17 00:00:00 2001 From: Christian Boltz Date: Sun, 17 Dec 2017 22:47:14 +0100 Subject: [PATCH] Allow different color for master branch - add $GIT_PROMPT_MASTER_BRANCH - color for master branch - add $GIT_PROMPT_MASTER_BRANCHES - branch name(s) that use $GIT_PROMPT_MASTER_BRANCH color, 'master' by default) All other branches will continue to use $GIT_PROMPT_BRANCH Fixes https://github.com/magicmonty/bash-git-prompt/issues/311 --- gitprompt.sh | 10 +++++++++- themes/Custom.bgptemplate | 9 ++++++++- themes/Default.bgptheme | 7 +++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index 98b9381..8c76ac3 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -519,7 +519,15 @@ function updatePrompt() { local NEW_PROMPT="$EMPTY_PROMPT" if [[ -n "$git_status_fields" ]]; then - local STATUS_PREFIX="${PROMPT_LEADING_SPACE}${GIT_PROMPT_PREFIX}${GIT_PROMPT_BRANCH}\${GIT_BRANCH}${ResetColor}${GIT_FORMATTED_UPSTREAM}" + + case "$GIT_BRANCH" in + $GIT_PROMPT_MASTER_BRANCHES) + local STATUS_PREFIX="${PROMPT_LEADING_SPACE}${GIT_PROMPT_PREFIX}${GIT_PROMPT_MASTER_BRANCH}\${GIT_BRANCH}${ResetColor}${GIT_FORMATTED_UPSTREAM}" + ;; + *) + local STATUS_PREFIX="${PROMPT_LEADING_SPACE}${GIT_PROMPT_PREFIX}${GIT_PROMPT_BRANCH}\${GIT_BRANCH}${ResetColor}${GIT_FORMATTED_UPSTREAM}" + ;; + esac local STATUS="" # __add_status KIND VALEXPR INSERT diff --git a/themes/Custom.bgptemplate b/themes/Custom.bgptemplate index d494198..6fc2e9f 100644 --- a/themes/Custom.bgptemplate +++ b/themes/Custom.bgptemplate @@ -14,6 +14,7 @@ override_git_prompt_colors() { # GIT_PROMPT_SEPARATOR="|" # separates each item # GIT_PROMPT_BRANCH="${Magenta}" # the git branch that is active in the current directory + # GIT_PROMPT_MASTER_BRANCH="${Magenta}" # used if the git branch that is active in the current directory is $GIT_PROMPT_MASTER_BRANCHES # GIT_PROMPT_STAGED="${Red}●" # the number of staged files/directories # GIT_PROMPT_CONFLICTS="${Red}✖ " # the number of files in conflict # GIT_PROMPT_CHANGED="${Blue}✚ " # the number of changed files @@ -53,6 +54,12 @@ override_git_prompt_colors() { # GIT_PROMPT_SYMBOLS_BEHIND="↓·" # The symbol for "n versions behind of origin" # GIT_PROMPT_SYMBOLS_PREHASH=":" # Written before hash of commit, if no name could be found # GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="L" # This symbol is written after the branch, if the branch is not tracked + + # branch name(s) that will use $GIT_PROMPT_MASTER_BRANCH color + # To specify multiple branches, use + # shopt -s extglob + # GIT_PROMPT_MASTER_BRANCHES='@(master|production)' + # GIT_PROMPT_MASTER_BRANCHES="master" } -reload_git_prompt_colors "Custom" \ No newline at end of file +reload_git_prompt_colors "Custom" diff --git a/themes/Default.bgptheme b/themes/Default.bgptheme index be680c5..ade65f5 100644 --- a/themes/Default.bgptheme +++ b/themes/Default.bgptheme @@ -42,6 +42,7 @@ define_undefined_git_prompt_colors() { if [ -z ${GIT_PROMPT_SEPARATOR+x} ]; then GIT_PROMPT_SEPARATOR="|"; fi # separates each item if [ -z ${GIT_PROMPT_BRANCH+x} ]; then GIT_PROMPT_BRANCH="${Magenta}"; fi # the git branch that is active in the current directory + if [ -z ${GIT_PROMPT_MASTER_BRANCH+x} ]; then GIT_PROMPT_MASTER_BRANCH="${Magenta}"; fi # used if the git branch that is active in the current directory is $GIT_PROMPT_MASTER_BRANCHES if [ -z ${GIT_PROMPT_STAGED+x} ]; then GIT_PROMPT_STAGED="${Red}●"; fi # the number of staged files/directories if [ -z ${GIT_PROMPT_CONFLICTS+x} ]; then GIT_PROMPT_CONFLICTS="${Red}✖ "; fi # the number of files in conflict if [ -z ${GIT_PROMPT_CHANGED+x} ]; then GIT_PROMPT_CHANGED="${Blue}✚ "; fi # the number of changed files @@ -88,6 +89,12 @@ define_undefined_git_prompt_colors() { if [ -z ${GIT_PROMPT_SYMBOLS_BEHIND+x} ]; then GIT_PROMPT_SYMBOLS_BEHIND="↓·"; fi # The symbol for "n versions behind of origin" if [ -z ${GIT_PROMPT_SYMBOLS_PREHASH+x} ]; then GIT_PROMPT_SYMBOLS_PREHASH=":"; fi # Written before hash of commit, if no name could be found if [ -z ${GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING+x} ]; then GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="L"; fi # This symbol is written after the branch, if the branch is not tracked + + # branch name(s) that will use $GIT_PROMPT_MASTER_BRANCH color + # To specify multiple branches, use + # shopt -s extglob + # GIT_PROMPT_MASTER_BRANCHES='@(master|production)' + if [ -z ${GIT_PROMPT_MASTER_BRANCHES+x} ]; then GIT_PROMPT_MASTER_BRANCHES="master"; fi } # call only from theme file