[PATCH] git-prompt: customizable symbols

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Alessandro <alezini94@xxxxxxxxxx>

Add the possibility to customize git-prompt symbols by adding a bunch of
additional variables. The variables default to the original symbol.

Signed-off-by: Alessandro Zini <alezini94@xxxxxxxxxx>
---
    git-prompt: customizable symbols

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1433%2Faleeraser%2Ffeat%2Fcustomize-git-prompt-symbols-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1433/aleeraser/feat/customize-git-prompt-symbols-v1
Pull-Request: https://github.com/git/git/pull/1433

 contrib/completion/git-prompt.sh | 39 ++++++++++++++++++++------------
 1 file changed, 24 insertions(+), 15 deletions(-)

diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index 57972c2845c..d29209f0cef 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -39,25 +39,31 @@
 # unstaged (*) and staged (+) changes will be shown next to the branch
 # name.  You can configure this per-repository with the
 # bash.showDirtyState variable, which defaults to true once
-# GIT_PS1_SHOWDIRTYSTATE is enabled.
+# GIT_PS1_SHOWDIRTYSTATE is enabled. Variables GIT_PS1_UNSTAGED_SYMBOL
+# and GIT_PS1_STAGED_SYMBOL can be used to change the shown symbol.
 #
 # You can also see if currently something is stashed, by setting
 # GIT_PS1_SHOWSTASHSTATE to a nonempty value. If something is stashed,
-# then a '$' will be shown next to the branch name.
+# then a '$' will be shown next to the branch name. Variable
+# GIT_PS1_STASH_SYMBOL can be used to change the shown symbol.
 #
 # If you would like to see if there're untracked files, then you can set
 # GIT_PS1_SHOWUNTRACKEDFILES to a nonempty value. If there're untracked
 # files, then a '%' will be shown next to the branch name.  You can
 # configure this per-repository with the bash.showUntrackedFiles
 # variable, which defaults to true once GIT_PS1_SHOWUNTRACKEDFILES is
-# enabled.
+# enabled. Variable GIT_PS1_UNTRACKED_SYMBOL can be used to change the
+# shown symbol.
 #
 # If you would like to see the difference between HEAD and its upstream,
 # set GIT_PS1_SHOWUPSTREAM="auto".  A "<" indicates you are behind, ">"
 # indicates you are ahead, "<>" indicates you have diverged and "="
-# indicates that there is no difference. You can further control
-# behaviour by setting GIT_PS1_SHOWUPSTREAM to a space-separated list
-# of values:
+# indicates that there is no difference. Symbols can be configured by
+# setting variables GIT_PS1_UPSTREAM_NOT_PRESENT_SYMBOL,
+# GIT_PS1_UPSTREAM_EQUAL_SYMBOL, GIT_PS1_UPSTREAM_AHEAD_SYMBOL,
+# GIT_PS1_UPSTREAM_BEHIND_SYMBOL, GIT_PS1_UPSTREAM_DIVERGED_SYMBOL
+# You can further control behaviour by setting GIT_PS1_SHOWUPSTREAM to a
+# space-separated list of values:
 #
 #     verbose       show number of commits ahead/behind (+/-) upstream
 #     name          if verbose, then also show the upstream abbrev name
@@ -208,15 +214,15 @@ __git_ps1_show_upstream ()
 	if [[ -z "$verbose" ]]; then
 		case "$count" in
 		"") # no upstream
-			p="" ;;
+			p="${GIT_PS1_UPSTREAM_NOT_PRESENT_SYMBOL-}" ;;
 		"0	0") # equal to upstream
-			p="=" ;;
+			p="${GIT_PS1_UPSTREAM_EQUAL_SYMBOL-"="}" ;;
 		"0	"*) # ahead of upstream
-			p=">" ;;
+			p="${GIT_PS1_UPSTREAM_AHEAD_SYMBOL-">"}" ;;
 		*"	0") # behind upstream
-			p="<" ;;
+			p="${GIT_PS1_UPSTREAM_BEHIND_SYMBOL-"<"}" ;;
 		*)	    # diverged from upstream
-			p="<>" ;;
+			p="${GIT_PS1_UPSTREAM_DIVERGED_SYMBOL-"<>"}" ;;
 		esac
 	else # verbose, set upstream instead of p
 		case "$count" in
@@ -537,8 +543,8 @@ __git_ps1 ()
 		if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ] &&
 		   [ "$(git config --bool bash.showDirtyState)" != "false" ]
 		then
-			git diff --no-ext-diff --quiet || w="*"
-			git diff --no-ext-diff --cached --quiet || i="+"
+			git diff --no-ext-diff --quiet || w="${GIT_PS1_UNSTAGED_SYMBOL-"*"}"
+			git diff --no-ext-diff --cached --quiet || i="${GIT_PS1_STAGED_SYMBOL-"+"}"
 			if [ -z "$short_sha" ] && [ -z "$i" ]; then
 				i="#"
 			fi
@@ -546,14 +552,17 @@ __git_ps1 ()
 		if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ] &&
 		   git rev-parse --verify --quiet refs/stash >/dev/null
 		then
-			s="$"
+			s="${GIT_PS1_STASH_SYMBOL-"$"}"
 		fi
 
 		if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ] &&
 		   [ "$(git config --bool bash.showUntrackedFiles)" != "false" ] &&
 		   git ls-files --others --exclude-standard --directory --no-empty-directory --error-unmatch -- ':/*' >/dev/null 2>/dev/null
 		then
-			u="%${ZSH_VERSION+%}"
+			u="${GIT_PS1_UNTRACKED_SYMBOL-"%"}"
+			if [ -n "$ZSH_VERSION" ] && [ "$u" = "%" ]; then
+				u="%%"
+			fi
 		fi
 
 		if [ -n "${GIT_PS1_COMPRESSSPARSESTATE-}" ] &&

base-commit: a38d39a4c50d1275833aba54c4dbdfce9e2e9ca1
-- 
gitgitgadget



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux