All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alessandro via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Alessandro <alezini94@hotmail.it>, Alessandro <alezini94@hotmail.it>
Subject: [PATCH] git-prompt: customizable symbols
Date: Fri, 13 Jan 2023 17:53:58 +0000	[thread overview]
Message-ID: <pull.1433.git.git.1673632438204.gitgitgadget@gmail.com> (raw)

From: Alessandro <alezini94@hotmail.it>

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@hotmail.it>
---
    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

                 reply	other threads:[~2023-01-13 18:01 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=pull.1433.git.git.1673632438204.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=alezini94@hotmail.it \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.