{"thread":{"id":"59084","subject":"[PATCH] git-prompt: customizable symbols","startedAt":"2023-01-13T18:01:08Z","lastAt":"2023-01-13T18:01:08Z","messageCount":1,"participants":["Alessandro via GitGitGadget"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"470292","messageId":"pull.1433.git.git.1673632438204.gitgitgadget@gmail.com","threadId":"59084","inReplyTo":null,"subject":"[PATCH] git-prompt: customizable symbols","fromName":"Alessandro via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2023-01-13T17:53:58Z","receivedAt":"2023-01-13T18:01:08Z","isPatch":true,"sender":{"key":"name:Alessandro","avatar":null},"body":"From: Alessandro <alezini94@hotmail.it>\n\nAdd the possibility to customize git-prompt symbols by adding a bunch of\nadditional variables. The variables default to the original symbol.\n\nSigned-off-by: Alessandro Zini <alezini94@hotmail.it>\n---\n    git-prompt: customizable symbols\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1433%2Faleeraser%2Ffeat%2Fcustomize-git-prompt-symbols-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1433/aleeraser/feat/customize-git-prompt-symbols-v1\nPull-Request: https://github.com/git/git/pull/1433\n\n contrib/completion/git-prompt.sh | 39 ++++++++++++++++++++------------\n 1 file changed, 24 insertions(+), 15 deletions(-)\n\ndiff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\nindex 57972c2845c..d29209f0cef 100644\n--- a/contrib/completion/git-prompt.sh\n+++ b/contrib/completion/git-prompt.sh\n@@ -39,25 +39,31 @@\n # unstaged (*) and staged (+) changes will be shown next to the branch\n # name.  You can configure this per-repository with the\n # bash.showDirtyState variable, which defaults to true once\n-# GIT_PS1_SHOWDIRTYSTATE is enabled.\n+# GIT_PS1_SHOWDIRTYSTATE is enabled. Variables GIT_PS1_UNSTAGED_SYMBOL\n+# and GIT_PS1_STAGED_SYMBOL can be used to change the shown symbol.\n #\n # You can also see if currently something is stashed, by setting\n # GIT_PS1_SHOWSTASHSTATE to a nonempty value. If something is stashed,\n-# then a '$' will be shown next to the branch name.\n+# then a '$' will be shown next to the branch name. Variable\n+# GIT_PS1_STASH_SYMBOL can be used to change the shown symbol.\n #\n # If you would like to see if there're untracked files, then you can set\n # GIT_PS1_SHOWUNTRACKEDFILES to a nonempty value. If there're untracked\n # files, then a '%' will be shown next to the branch name.  You can\n # configure this per-repository with the bash.showUntrackedFiles\n # variable, which defaults to true once GIT_PS1_SHOWUNTRACKEDFILES is\n-# enabled.\n+# enabled. Variable GIT_PS1_UNTRACKED_SYMBOL can be used to change the\n+# shown symbol.\n #\n # If you would like to see the difference between HEAD and its upstream,\n # set GIT_PS1_SHOWUPSTREAM=\"auto\".  A \"<\" indicates you are behind, \">\"\n # indicates you are ahead, \"<>\" indicates you have diverged and \"=\"\n-# indicates that there is no difference. You can further control\n-# behaviour by setting GIT_PS1_SHOWUPSTREAM to a space-separated list\n-# of values:\n+# indicates that there is no difference. Symbols can be configured by\n+# setting variables GIT_PS1_UPSTREAM_NOT_PRESENT_SYMBOL,\n+# GIT_PS1_UPSTREAM_EQUAL_SYMBOL, GIT_PS1_UPSTREAM_AHEAD_SYMBOL,\n+# GIT_PS1_UPSTREAM_BEHIND_SYMBOL, GIT_PS1_UPSTREAM_DIVERGED_SYMBOL\n+# You can further control behaviour by setting GIT_PS1_SHOWUPSTREAM to a\n+# space-separated list of values:\n #\n #     verbose       show number of commits ahead/behind (+/-) upstream\n #     name          if verbose, then also show the upstream abbrev name\n@@ -208,15 +214,15 @@ __git_ps1_show_upstream ()\n \tif [[ -z \"$verbose\" ]]; then\n \t\tcase \"$count\" in\n \t\t\"\") # no upstream\n-\t\t\tp=\"\" ;;\n+\t\t\tp=\"${GIT_PS1_UPSTREAM_NOT_PRESENT_SYMBOL-}\" ;;\n \t\t\"0\t0\") # equal to upstream\n-\t\t\tp=\"=\" ;;\n+\t\t\tp=\"${GIT_PS1_UPSTREAM_EQUAL_SYMBOL-\"=\"}\" ;;\n \t\t\"0\t\"*) # ahead of upstream\n-\t\t\tp=\">\" ;;\n+\t\t\tp=\"${GIT_PS1_UPSTREAM_AHEAD_SYMBOL-\">\"}\" ;;\n \t\t*\"\t0\") # behind upstream\n-\t\t\tp=\"<\" ;;\n+\t\t\tp=\"${GIT_PS1_UPSTREAM_BEHIND_SYMBOL-\"<\"}\" ;;\n \t\t*)\t    # diverged from upstream\n-\t\t\tp=\"<>\" ;;\n+\t\t\tp=\"${GIT_PS1_UPSTREAM_DIVERGED_SYMBOL-\"<>\"}\" ;;\n \t\tesac\n \telse # verbose, set upstream instead of p\n \t\tcase \"$count\" in\n@@ -537,8 +543,8 @@ __git_ps1 ()\n \t\tif [ -n \"${GIT_PS1_SHOWDIRTYSTATE-}\" ] &&\n \t\t   [ \"$(git config --bool bash.showDirtyState)\" != \"false\" ]\n \t\tthen\n-\t\t\tgit diff --no-ext-diff --quiet || w=\"*\"\n-\t\t\tgit diff --no-ext-diff --cached --quiet || i=\"+\"\n+\t\t\tgit diff --no-ext-diff --quiet || w=\"${GIT_PS1_UNSTAGED_SYMBOL-\"*\"}\"\n+\t\t\tgit diff --no-ext-diff --cached --quiet || i=\"${GIT_PS1_STAGED_SYMBOL-\"+\"}\"\n \t\t\tif [ -z \"$short_sha\" ] && [ -z \"$i\" ]; then\n \t\t\t\ti=\"#\"\n \t\t\tfi\n@@ -546,14 +552,17 @@ __git_ps1 ()\n \t\tif [ -n \"${GIT_PS1_SHOWSTASHSTATE-}\" ] &&\n \t\t   git rev-parse --verify --quiet refs/stash >/dev/null\n \t\tthen\n-\t\t\ts=\"$\"\n+\t\t\ts=\"${GIT_PS1_STASH_SYMBOL-\"$\"}\"\n \t\tfi\n \n \t\tif [ -n \"${GIT_PS1_SHOWUNTRACKEDFILES-}\" ] &&\n \t\t   [ \"$(git config --bool bash.showUntrackedFiles)\" != \"false\" ] &&\n \t\t   git ls-files --others --exclude-standard --directory --no-empty-directory --error-unmatch -- ':/*' >/dev/null 2>/dev/null\n \t\tthen\n-\t\t\tu=\"%${ZSH_VERSION+%}\"\n+\t\t\tu=\"${GIT_PS1_UNTRACKED_SYMBOL-\"%\"}\"\n+\t\t\tif [ -n \"$ZSH_VERSION\" ] && [ \"$u\" = \"%\" ]; then\n+\t\t\t\tu=\"%%\"\n+\t\t\tfi\n \t\tfi\n \n \t\tif [ -n \"${GIT_PS1_COMPRESSSPARSESTATE-}\" ] &&\n\nbase-commit: a38d39a4c50d1275833aba54c4dbdfce9e2e9ca1\n-- \ngitgitgadget\n"}]}