Skip to content

Commit 4b8c8da

Browse files
author
Christian Boltz
committed
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 #311
1 parent 50eb8fb commit 4b8c8da

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

gitprompt.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,15 @@ function updatePrompt() {
519519

520520
local NEW_PROMPT="$EMPTY_PROMPT"
521521
if [[ -n "$git_status_fields" ]]; then
522-
local STATUS_PREFIX="${PROMPT_LEADING_SPACE}${GIT_PROMPT_PREFIX}${GIT_PROMPT_BRANCH}\${GIT_BRANCH}${ResetColor}${GIT_FORMATTED_UPSTREAM}"
522+
523+
case "$GIT_BRANCH" in
524+
$GIT_PROMPT_MASTER_BRANCHES)
525+
local STATUS_PREFIX="${PROMPT_LEADING_SPACE}${GIT_PROMPT_PREFIX}${GIT_PROMPT_MASTER_BRANCH}\${GIT_BRANCH}${ResetColor}${GIT_FORMATTED_UPSTREAM}"
526+
;;
527+
*)
528+
local STATUS_PREFIX="${PROMPT_LEADING_SPACE}${GIT_PROMPT_PREFIX}${GIT_PROMPT_BRANCH}\${GIT_BRANCH}${ResetColor}${GIT_FORMATTED_UPSTREAM}"
529+
;;
530+
esac
523531
local STATUS=""
524532

525533
# __add_status KIND VALEXPR INSERT

themes/Custom.bgptemplate

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ override_git_prompt_colors() {
1414
# GIT_PROMPT_SEPARATOR="|" # separates each item
1515

1616
# GIT_PROMPT_BRANCH="${Magenta}" # the git branch that is active in the current directory
17+
# GIT_PROMPT_MASTER_BRANCH="${Magenta}" # used if the git branch that is active in the current directory is $GIT_PROMPT_MASTER_BRANCHES
1718
# GIT_PROMPT_STAGED="${Red}●" # the number of staged files/directories
1819
# GIT_PROMPT_CONFLICTS="${Red}✖ " # the number of files in conflict
1920
# GIT_PROMPT_CHANGED="${Blue}✚ " # the number of changed files
@@ -53,6 +54,12 @@ override_git_prompt_colors() {
5354
# GIT_PROMPT_SYMBOLS_BEHIND="↓·" # The symbol for "n versions behind of origin"
5455
# GIT_PROMPT_SYMBOLS_PREHASH=":" # Written before hash of commit, if no name could be found
5556
# GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="L" # This symbol is written after the branch, if the branch is not tracked
57+
58+
# branch name(s) that will use $GIT_PROMPT_MASTER_BRANCH color
59+
# To specify multiple branches, use
60+
# shopt -s extglob
61+
# GIT_PROMPT_MASTER_BRANCHES='@(master|production)'
62+
# GIT_PROMPT_MASTER_BRANCHES="master"
5663
}
5764

58-
reload_git_prompt_colors "Custom"
65+
reload_git_prompt_colors "Custom"

themes/Default.bgptheme

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ define_undefined_git_prompt_colors() {
4242
if [ -z ${GIT_PROMPT_SEPARATOR+x} ]; then GIT_PROMPT_SEPARATOR="|"; fi # separates each item
4343

4444
if [ -z ${GIT_PROMPT_BRANCH+x} ]; then GIT_PROMPT_BRANCH="${Magenta}"; fi # the git branch that is active in the current directory
45+
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
4546
if [ -z ${GIT_PROMPT_STAGED+x} ]; then GIT_PROMPT_STAGED="${Red}●"; fi # the number of staged files/directories
4647
if [ -z ${GIT_PROMPT_CONFLICTS+x} ]; then GIT_PROMPT_CONFLICTS="${Red}✖ "; fi # the number of files in conflict
4748
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() {
8889
if [ -z ${GIT_PROMPT_SYMBOLS_BEHIND+x} ]; then GIT_PROMPT_SYMBOLS_BEHIND="↓·"; fi # The symbol for "n versions behind of origin"
8990
if [ -z ${GIT_PROMPT_SYMBOLS_PREHASH+x} ]; then GIT_PROMPT_SYMBOLS_PREHASH=":"; fi # Written before hash of commit, if no name could be found
9091
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
92+
93+
# branch name(s) that will use $GIT_PROMPT_MASTER_BRANCH color
94+
# To specify multiple branches, use
95+
# shopt -s extglob
96+
# GIT_PROMPT_MASTER_BRANCHES='@(master|production)'
97+
if [ -z ${GIT_PROMPT_MASTER_BRANCHES+x} ]; then GIT_PROMPT_MASTER_BRANCHES="master"; fi
9198
}
9299

93100
# call only from theme file

0 commit comments

Comments
 (0)