From e0267fe001e68cf8f8654ba7fb12d8e421279163 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Skalski?= Date: Fri, 29 Nov 2019 22:56:29 +0100 Subject: [PATCH 1/2] Enhance git_prompt_help and example with real colors and markers Additional fix when ${GIT_PROMPT_PREFIX} or ${GIT_PROMPT_SUFFIX} contain color sequences git_prompt_help's formatting was wrong --- git-prompt-help.sh | 47 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/git-prompt-help.sh b/git-prompt-help.sh index ffa3da57..d7cea58f 100755 --- a/git-prompt-help.sh +++ b/git-prompt-help.sh @@ -5,11 +5,12 @@ git_prompt_help() { source "${__GIT_PROMPT_DIR}/prompt-colors.sh" source "${__GIT_PROMPT_DIR}/themes/Default.bgptheme" + cat <${GIT_PROMPT_SEPARATOR}${GIT_PROMPT_SUFFIX} +The git prompt format is ${GIT_PROMPT_PREFIX}${GIT_PROMPT_SEPARATOR}${GIT_PROMPT_SUFFIX}${ResetColor} -BRANCH is a branch name, such as "master" or "stage", a tag name, or commit -hash prefixed with ':'. +BRANCH is a branch name, such as "${GIT_PROMPT_MASTER_BRANCH}master${ResetColor}" or "${GIT_PROMPT_BRANCH}stage${ResetColor}", a tag name, or commit +${GIT_PROMPT_SYMBOLS_PREHASH}hash${ResetColor} prefixed with '${GIT_PROMPT_SYMBOLS_PREHASH:-':'}${ResetColor}'. TRACKING indicates how the local branch differs from the remote branch. It can be empty, or one of: @@ -34,32 +35,50 @@ EOF help_git_prompt() { git_prompt_help ; } git_prompt_examples() { + + format_branch() { + case "$1" in + ${GIT_PROMPT_MASTER_BRANCHES}) + echo "${GIT_PROMPT_MASTER_BRANCH}$1${ResetColor}" + ;; + *) + echo "${GIT_PROMPT_BRANCH}$1${ResetColor}" + ;; + esac + } + local p="${GIT_PROMPT_PREFIX}" + local s="${GIT_PROMPT_SUFFIX}${ResetColor}" + cat < Date: Thu, 19 Dec 2019 12:14:56 +0100 Subject: [PATCH 2/2] git-help-examples-fixup: Some more minor tweaks in help and examples --- git-prompt-help.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/git-prompt-help.sh b/git-prompt-help.sh index d7cea58f..0b93950e 100755 --- a/git-prompt-help.sh +++ b/git-prompt-help.sh @@ -17,7 +17,7 @@ remote branch. It can be empty, or one of: ${GIT_PROMPT_BRANCH}${ResetColor}${GIT_PROMPT_REMOTE}${GIT_PROMPT_SYMBOLS_AHEAD}N${ResetColor} - ahead of remote by N commits ${GIT_PROMPT_BRANCH}${ResetColor}${GIT_PROMPT_REMOTE}${GIT_PROMPT_SYMBOLS_BEHIND}M${ResetColor} - behind remote by M commits - ${GIT_PROMPT_BRANCH}${ResetColor}${GIT_PROMPT_REMOTE}${GIT_PROMPT_SYMBOLS_AHEAD}N${GIT_PROMPT_SYMBOLS_BEHIND}M${ResetColor} - branches diverged, other by M commits, yours by N commits + ${GIT_PROMPT_BRANCH}${ResetColor}${GIT_PROMPT_REMOTE}${GIT_PROMPT_SYMBOLS_BEHIND}M${GIT_PROMPT_SYMBOLS_AHEAD}N${ResetColor} - branches diverged, other by M commits, yours by N commits LOCALSTATUS is one of the following: @@ -63,7 +63,7 @@ These are examples of the git prompt: ${p}`format_branch master`${GIT_PROMPT_SEPARATOR}${GIT_PROMPT_STASHED}2${ResetColor}${s} - on branch "master", 2 stash entries - ${p}`format_branch experimental`${GIT_PROMPT_REMOTE}${GIT_PROMPT_SEPARATOR}${GIT_PROMPT_SYMBOLS_AHEAD}2${GIT_PROMPT_SYMBOLS_BEHIND}3${ResetColor}${s} + ${p}`format_branch experimental`${GIT_PROMPT_REMOTE}${GIT_PROMPT_SYMBOLS_BEHIND}2${GIT_PROMPT_SYMBOLS_AHEAD}3${ResetColor}${GIT_PROMPT_SEPARATOR}${GIT_PROMPT_CLEAN}${ResetColor}${s} - on branch "experimental"; your branch has diverged by 3 commits, remote by 2 commits; the repository is otherwise clean