From: "Eduardo R. D'Avila" <erdavila@gmail.com>
To: git@vger.kernel.org
Cc: felipe.contreras@gmail.com, t.gummerer@gmail.com,
artagnon@gmail.com, zoltan.klinger@gmail.com, hegge@resisty.net,
martinerikwerner@gmail.com, s.oosthoek@xs4all.nl,
gitster@pobox.com, jonathan@leto.net, szeder@ira.uka.de,
"Eduardo R. D'Avila" <erdavila@gmail.com>
Subject: [PATCH v2 3/3] git-prompt.sh: enable color prompt in non-pcmode
Date: Mon, 17 Jun 2013 23:19:46 -0300 [thread overview]
Message-ID: <1371521986-10179-1-git-send-email-erdavila@gmail.com> (raw)
In-Reply-To: <7vhagxicu9.fsf@alter.siamese.dyndns.org>
The use of colors in a prompt is only possible in
pcmode (using the variable PROMPT_COMMAND).
Enable color prompt in non-pcmode (using the variable
PS1) for both Bash and ZSH.
Signed-off-by: Eduardo R. D'Avila <erdavila@gmail.com>
---
15 9 contrib/completion/git-prompt.sh
19 0 t/t9903-bash-prompt.sh
contrib/completion/git-prompt.sh | 24 +++++++++++++++---------
t/t9903-bash-prompt.sh | 19 +++++++++++++++++++
2 files changed, 34 insertions(+), 9 deletions(-)
diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index 70515cc..c5c75e7 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -13,7 +13,7 @@
# 3a) Change your PS1 to call __git_ps1 as
# command-substitution:
# Bash: PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
-# ZSH: PS1='[%n@%m %c$(__git_ps1 " (%s)")]\$ '
+# ZSH: setopt PROMPT_SUBST ; PS1='[%n@%m %c$(__git_ps1 " (%s)")]\$ '
# the optional argument will be used as format string.
# 3b) Alternatively, if you are using bash, __git_ps1 can be
# used for PROMPT_COMMAND with two parameters, <pre> and
@@ -235,12 +235,18 @@ __git_ps1_colorize_gitstring ()
local c_lblue='%F{blue}'
local c_clear='%f'
else
- # Using \[ and \] around colors
- # is necessary to prevent wrapping issues!
- local c_red='\[\e[31m\]'
- local c_green='\[\e[32m\]'
- local c_lblue='\[\e[1;34m\]'
- local c_clear='\[\e[0m\]'
+ local c_red='\e[31m'
+ local c_green='\e[32m'
+ local c_lblue='\e[1;34m'
+ local c_clear='\e[0m'
+ if [ $pcmode = yes ]; then
+ # Using \[ and \] around colors
+ # is necessary to prevent wrapping issues!
+ c_red="\[$c_red\]"
+ c_green="\[$c_green\]"
+ c_lblue="\[$c_lblue\]"
+ c_clear="\[$c_clear\]"
+ fi
fi
local bad_color=$c_red
local ok_color=$c_green
@@ -411,7 +417,7 @@ __git_ps1 ()
local z="${GIT_PS1_STATESEPARATOR-" "}"
# NO color option unless in PROMPT_COMMAND mode
- if [ $pcmode = yes ] && [ -n "${GIT_PS1_SHOWCOLORHINTS-}" ]; then
+ if [ -n "${GIT_PS1_SHOWCOLORHINTS-}" ]; then
__git_ps1_colorize_gitstring
fi
@@ -422,7 +428,7 @@ __git_ps1 ()
gitstring=$(printf -- "$printf_format" "$gitstring")
PS1="$ps1pc_start$gitstring$ps1pc_end"
else
- printf -- "$printf_format" "$gitstring"
+ printf -- "${printf_format//%s/%b}" "$gitstring"
fi
fi
}
diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh
index 1101adf..7dccc1c 100755
--- a/t/t9903-bash-prompt.sh
+++ b/t/t9903-bash-prompt.sh
@@ -789,4 +789,23 @@ test_expect_success 'prompt - zsh color pc mode - untracked files status indicat
test_cmp expected "$actual"
'
+test_expect_success 'prompt - bash color ps1 mode - untracked files status indicator' '
+ printf " (\e[32mmaster\e[0m)" >expected &&
+ (
+ GIT_PS1_SHOWCOLORHINTS=y &&
+ __git_ps1 >"$actual"
+ ) &&
+ test_cmp expected "$actual"
+'
+
+test_expect_success 'prompt - zsh color ps1 mode - untracked files status indicator' '
+ printf " (%%F{green}master%%f)" >expected &&
+ (
+ GIT_PS1_SHOWCOLORHINTS=y &&
+ ZSH_VERSION=5.0.0 &&
+ __git_ps1 >"$actual"
+ ) &&
+ test_cmp expected "$actual"
+'
+
test_done
--
1.8.3.1.440.g82707f8
next prev parent reply other threads:[~2013-06-18 2:20 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-16 17:32 [PATCH/RFC 0/3] enable color prompt in non-pcmode Eduardo R. D'Avila
2013-06-16 17:32 ` [PATCH/RFC 1/3] t9903: add tests for git-prompt pcmode Eduardo R. D'Avila
2013-06-17 4:24 ` Junio C Hamano
2013-06-18 2:15 ` [PATCH v2 " Eduardo R. D'Avila
2013-06-18 2:16 ` [PATCH v2 2/3] git-prompt.sh: refactor colored prompt code Eduardo R. D'Avila
2013-06-18 2:17 ` [PATCH 3/3] git-prompt.sh: enable color prompt in non-pcmode Eduardo R. D'Avila
2013-06-18 2:19 ` Eduardo R. D'Avila [this message]
2013-06-16 17:32 ` [PATCH/RFC 2/3] git-prompt.sh: refactor colored prompt code Eduardo R. D'Avila
2013-06-16 17:32 ` [PATCH/RFC 3/3] git-prompt.sh: enable color prompt in non-pcmode Eduardo R. D'Avila
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=1371521986-10179-1-git-send-email-erdavila@gmail.com \
--to=erdavila@gmail.com \
--cc=artagnon@gmail.com \
--cc=felipe.contreras@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=hegge@resisty.net \
--cc=jonathan@leto.net \
--cc=martinerikwerner@gmail.com \
--cc=s.oosthoek@xs4all.nl \
--cc=szeder@ira.uka.de \
--cc=t.gummerer@gmail.com \
--cc=zoltan.klinger@gmail.com \
/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.