* [PATCH 0/2] Colored prompt for zsh
@ 2013-05-11 16:25 Ramkumar Ramachandra
2013-05-11 16:25 ` [PATCH 1/2] git-prompt.sh: strip unnecessary space in prompt string Ramkumar Ramachandra
2013-05-11 16:25 ` [PATCH 2/2] git-prompt.zsh: introduce thin ZSH wrapper Ramkumar Ramachandra
0 siblings, 2 replies; 16+ messages in thread
From: Ramkumar Ramachandra @ 2013-05-11 16:25 UTC (permalink / raw)
To: Git List; +Cc: Junio C Hamano
Hi,
I was using ZSH's vcs_info until now, and just discovered
contrib/completion/git-prompt.sh. Other differences aside, it's
simple enough that I can hack on it.
The first patch strips a small whitespace (we can't waste valuable
real estate on unnecessary whitespace), and the second patch should
get you a beautiful colored prompt in ZSH.
Enjoy!
Ramkumar Ramachandra (2):
git-prompt.sh: strip unnecessary space in prompt string
git-prompt.zsh: introduce thin ZSH wrapper
contrib/completion/git-prompt.sh | 80 ++++++++++++++++++++-------------------
contrib/completion/git-prompt.zsh | 59 +++++++++++++++++++++++++++++
2 files changed, 101 insertions(+), 38 deletions(-)
create mode 100644 contrib/completion/git-prompt.zsh
--
1.8.3.rc1.52.g4537cf1
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 1/2] git-prompt.sh: strip unnecessary space in prompt string
2013-05-11 16:25 [PATCH 0/2] Colored prompt for zsh Ramkumar Ramachandra
@ 2013-05-11 16:25 ` Ramkumar Ramachandra
2013-05-13 4:57 ` Junio C Hamano
2013-05-11 16:25 ` [PATCH 2/2] git-prompt.zsh: introduce thin ZSH wrapper Ramkumar Ramachandra
1 sibling, 1 reply; 16+ messages in thread
From: Ramkumar Ramachandra @ 2013-05-11 16:25 UTC (permalink / raw)
To: Git List; +Cc: Junio C Hamano
Nobody has branch names that end with + or *. Then why put a space
after the branch name and before [*|+][=|<|>] in the prompt string?
Before this, your prompt might have looked like:
artagnon|master *=:~/src/git$
Now, it will look like:
artagnon|master*=:~/src/git$
Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
contrib/completion/git-prompt.sh | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index eaf5c36..08c9b22 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -383,9 +383,6 @@ __git_ps1 ()
# is necessary to prevent wrapping issues!
gitstring="\[$branch_color\]$branchstring\[$c_clear\]"
- if [ -n "$w$i$s$u$r$p" ]; then
- gitstring="$gitstring "
- fi
if [ "$w" = "*" ]; then
gitstring="$gitstring\[$bad_color\]$w"
fi
@@ -400,13 +397,13 @@ __git_ps1 ()
fi
gitstring="$gitstring\[$c_clear\]$r$p"
else
- gitstring="$c${b##refs/heads/}${f:+ $f}$r$p"
+ gitstring="$c${b##refs/heads/}${f:+$f}$r$p"
fi
gitstring=$(printf -- "$printf_format" "$gitstring")
PS1="$ps1pc_start$gitstring$ps1pc_end"
else
# NO color option unless in PROMPT_COMMAND mode
- printf -- "$printf_format" "$c${b##refs/heads/}${f:+ $f}$r$p"
+ printf -- "$printf_format" "$c${b##refs/heads/}${f:+$f}$r$p"
fi
fi
}
--
1.8.3.rc1.52.g4537cf1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 2/2] git-prompt.zsh: introduce thin ZSH wrapper
2013-05-11 16:25 [PATCH 0/2] Colored prompt for zsh Ramkumar Ramachandra
2013-05-11 16:25 ` [PATCH 1/2] git-prompt.sh: strip unnecessary space in prompt string Ramkumar Ramachandra
@ 2013-05-11 16:25 ` Ramkumar Ramachandra
2013-05-11 21:26 ` Felipe Contreras
1 sibling, 1 reply; 16+ messages in thread
From: Ramkumar Ramachandra @ 2013-05-11 16:25 UTC (permalink / raw)
To: Git List; +Cc: Junio C Hamano
To facilitate a colored prompt in ZSH, write a thin wrapper around
git-prompt.sh, factoring out and overriding the coloring logic. Since
ZSH lacks a PROMPT_COMMAND, instruct the user to execute __git_ps1
inside precmd().
Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
contrib/completion/git-prompt.sh | 73 +++++++++++++++++++++------------------
contrib/completion/git-prompt.zsh | 59 +++++++++++++++++++++++++++++++
2 files changed, 99 insertions(+), 33 deletions(-)
create mode 100644 contrib/completion/git-prompt.zsh
diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index 08c9b22..0bc51ad 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -222,6 +222,45 @@ __git_ps1_show_upstream ()
}
+# Helper function that is meant to be called from __git_ps1. It
+# builds up a gitstring injecting color codes into the appropriate
+# places.
+__git_ps1_colorize_gitstring ()
+{
+ local c_red='\e[31m'
+ local c_green='\e[32m'
+ local c_lblue='\e[1;34m'
+ local c_clear='\e[0m'
+ local bad_color=$c_red
+ local ok_color=$c_green
+ local branch_color="$c_clear"
+ local flags_color="$c_lblue"
+ local branchstring="$c${b##refs/heads/}"
+
+ if [ $detached = no ]; then
+ branch_color="$ok_color"
+ else
+ branch_color="$bad_color"
+ fi
+
+ # Setting gitstring directly with \[ and \] around colors
+ # is necessary to prevent wrapping issues!
+ gitstring="\[$branch_color\]$branchstring\[$c_clear\]"
+
+ if [ "$w" = "*" ]; then
+ gitstring="$gitstring\[$bad_color\]$w"
+ fi
+ if [ -n "$i" ]; then
+ gitstring="$gitstring\[$ok_color\]$i"
+ fi
+ if [ -n "$s" ]; then
+ gitstring="$gitstring\[$flags_color\]$s"
+ fi
+ if [ -n "$u" ]; then
+ gitstring="$gitstring\[$bad_color\]$u"
+ fi
+ gitstring="$gitstring\[$c_clear\]$r$p"
+}
# __git_ps1 accepts 0 or 1 arguments (i.e., format string)
# when called from PS1 using command substitution
@@ -363,39 +402,7 @@ __git_ps1 ()
if [ $pcmode = yes ]; then
local gitstring=
if [ -n "${GIT_PS1_SHOWCOLORHINTS-}" ]; then
- local c_red='\e[31m'
- local c_green='\e[32m'
- local c_lblue='\e[1;34m'
- local c_clear='\e[0m'
- local bad_color=$c_red
- local ok_color=$c_green
- local branch_color="$c_clear"
- local flags_color="$c_lblue"
- local branchstring="$c${b##refs/heads/}"
-
- if [ $detached = no ]; then
- branch_color="$ok_color"
- else
- branch_color="$bad_color"
- fi
-
- # Setting gitstring directly with \[ and \] around colors
- # is necessary to prevent wrapping issues!
- gitstring="\[$branch_color\]$branchstring\[$c_clear\]"
-
- if [ "$w" = "*" ]; then
- gitstring="$gitstring\[$bad_color\]$w"
- fi
- if [ -n "$i" ]; then
- gitstring="$gitstring\[$ok_color\]$i"
- fi
- if [ -n "$s" ]; then
- gitstring="$gitstring\[$flags_color\]$s"
- fi
- if [ -n "$u" ]; then
- gitstring="$gitstring\[$bad_color\]$u"
- fi
- gitstring="$gitstring\[$c_clear\]$r$p"
+ __git_ps1_colorize_gitstring
else
gitstring="$c${b##refs/heads/}${f:+$f}$r$p"
fi
diff --git a/contrib/completion/git-prompt.zsh b/contrib/completion/git-prompt.zsh
new file mode 100644
index 0000000..dc164dd
--- /dev/null
+++ b/contrib/completion/git-prompt.zsh
@@ -0,0 +1,59 @@
+# git prompt support for zsh: wrapper around git-prompt.sh
+#
+# To enable:
+#
+# 1) Copy this file and git-prompt.sh to ~/.zsh/prompt
+# 2) Add the following lines to your .zshrc:
+#
+# source ~/.zsh/prompt/git-prompt.zsh
+# GIT_PS1_SHOWCOLORHINTS=true
+# precmd () { __git_ps1 "%n|" ":%~$ " "%s" }
+#
+# 3) You can now add the following to ~/.zshrc and expect the
+# characters to be displayed in color:
+#
+# GIT_PS1_DESCRIBE_STYLE=branch
+# GIT_PS1_SHOWUPSTREAM=auto
+# GIT_PS1_SHOWDIRTYSTATE=true
+# GIT_PS1_SHOWUNTRACKEDFILES=true
+
+test -z "$script" && script="$(dirname ${funcsourcetrace[1]%:*})"/git-prompt.sh
+ZSH_VERSION='' . "$script"
+
+autoload colors
+colors
+
+__git_ps1_colorize_gitstring ()
+{
+ local c_red='%F{red}'
+ local c_green='%F{green}'
+ local c_lblue='%F{blue}'
+ local c_clear='%f'
+ local bad_color=$c_red
+ local ok_color=$c_green
+ local branch_color="$c_clear"
+ local flags_color="$c_lblue"
+ local branchstring="$c${b##refs/heads/}"
+
+ if [ $detached = no ]; then
+ branch_color="$ok_color"
+ else
+ branch_color="$bad_color"
+ fi
+
+ gitstring="$branch_color$branchstring$c_clear"
+
+ if [ "$w" = "*" ]; then
+ gitstring="$gitstring$bad_color$w"
+ fi
+ if [ -n "$i" ]; then
+ gitstring="$gitstring$ok_color$i"
+ fi
+ if [ -n "$s" ]; then
+ gitstring="$gitstring$flags_color$s"
+ fi
+ if [ -n "$u" ]; then
+ gitstring="$gitstring$bad_color$u"
+ fi
+ gitstring="$gitstring$c_clear$r$p"
+}
--
1.8.3.rc1.52.g4537cf1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH 2/2] git-prompt.zsh: introduce thin ZSH wrapper
2013-05-11 16:25 ` [PATCH 2/2] git-prompt.zsh: introduce thin ZSH wrapper Ramkumar Ramachandra
@ 2013-05-11 21:26 ` Felipe Contreras
2013-05-11 22:18 ` [PATCH v2] git-prompt.sh: colorize ZSH prompt Ramkumar Ramachandra
0 siblings, 1 reply; 16+ messages in thread
From: Felipe Contreras @ 2013-05-11 21:26 UTC (permalink / raw)
To: Ramkumar Ramachandra; +Cc: Git List, Junio C Hamano
On Sat, May 11, 2013 at 11:25 AM, Ramkumar Ramachandra
<artagnon@gmail.com> wrote:
> To facilitate a colored prompt in ZSH, write a thin wrapper around
> git-prompt.sh, factoring out and overriding the coloring logic. Since
> ZSH lacks a PROMPT_COMMAND, instruct the user to execute __git_ps1
> inside precmd().
I think this is two logical changes into one.
> --- /dev/null
> +++ b/contrib/completion/git-prompt.zsh
> @@ -0,0 +1,59 @@
> +# git prompt support for zsh: wrapper around git-prompt.sh
> +#
> +# To enable:
> +#
> +# 1) Copy this file and git-prompt.sh to ~/.zsh/prompt
> +# 2) Add the following lines to your .zshrc:
> +#
> +# source ~/.zsh/prompt/git-prompt.zsh
> +# GIT_PS1_SHOWCOLORHINTS=true
> +# precmd () { __git_ps1 "%n|" ":%~$ " "%s" }
> +#
> +# 3) You can now add the following to ~/.zshrc and expect the
> +# characters to be displayed in color:
> +#
> +# GIT_PS1_DESCRIBE_STYLE=branch
> +# GIT_PS1_SHOWUPSTREAM=auto
> +# GIT_PS1_SHOWDIRTYSTATE=true
> +# GIT_PS1_SHOWUNTRACKEDFILES=true
> +
> +test -z "$script" && script="$(dirname ${funcsourcetrace[1]%:*})"/git-prompt.sh
> +ZSH_VERSION='' . "$script"
I've been thinking that this method of loading the script is not the
best; we should probably have a list of locations where distributions
usually put this file. So if we could avoid the creation of of a new
file, that would be great.
> +autoload colors
> +colors
> +
> +__git_ps1_colorize_gitstring ()
> +{
> + local c_red='%F{red}'
> + local c_green='%F{green}'
> + local c_lblue='%F{blue}'
> + local c_clear='%f'
> + local bad_color=$c_red
> + local ok_color=$c_green
> + local branch_color="$c_clear"
> + local flags_color="$c_lblue"
> + local branchstring="$c${b##refs/heads/}"
This is the only real difference with bash colors, no? I think it's
overkill to create a new file, and load the old one, only to override
part of a function. We should probably start with everything in the
same file, and only later if we find it's necessary, split.
> + if [ $detached = no ]; then
> + branch_color="$ok_color"
> + else
> + branch_color="$bad_color"
> + fi
> +
> + gitstring="$branch_color$branchstring$c_clear"
> +
> + if [ "$w" = "*" ]; then
> + gitstring="$gitstring$bad_color$w"
> + fi
> + if [ -n "$i" ]; then
> + gitstring="$gitstring$ok_color$i"
> + fi
> + if [ -n "$s" ]; then
> + gitstring="$gitstring$flags_color$s"
> + fi
> + if [ -n "$u" ]; then
> + gitstring="$gitstring$bad_color$u"
> + fi
> + gitstring="$gitstring$c_clear$r$p"
> +}
> --
--
Felipe Contreras
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH v2] git-prompt.sh: colorize ZSH prompt
2013-05-11 21:26 ` Felipe Contreras
@ 2013-05-11 22:18 ` Ramkumar Ramachandra
2013-05-11 22:29 ` Felipe Contreras
0 siblings, 1 reply; 16+ messages in thread
From: Ramkumar Ramachandra @ 2013-05-11 22:18 UTC (permalink / raw)
To: Git List; +Cc: Felipe Contreras, Junio C Hamano
Add colors suitable for use in the ZSH prompt. Having learnt that the
ZSH equivalent of PROMPT_COMMAND is precmd (), you can now use
GIT_PS1_SHOWCOLORHINTS with ZSH.
Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
You like this more? I don't mind going either way.
contrib/completion/git-prompt.sh | 67 ++++++++++++++++++++++++++++------------
1 file changed, 47 insertions(+), 20 deletions(-)
diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index 08c9b22..26e5bc2 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -20,7 +20,8 @@
# <post>, which are strings you would put in $PS1 before
# and after the status string generated by the git-prompt
# machinery. e.g.
-# PROMPT_COMMAND='__git_ps1 "\u@\h:\w" "\\\$ "'
+# Bash: PROMPT_COMMAND='__git_ps1 "\u@\h:\w" "\\\$ "'
+# ZSH: precmd () { __git_ps1 "%n" ":%~$ " "|%s" }
# will show username, at-sign, host, colon, cwd, then
# various status string, followed by dollar and SP, as
# your prompt.
@@ -363,10 +364,18 @@ __git_ps1 ()
if [ $pcmode = yes ]; then
local gitstring=
if [ -n "${GIT_PS1_SHOWCOLORHINTS-}" ]; then
- local c_red='\e[31m'
- local c_green='\e[32m'
- local c_lblue='\e[1;34m'
- local c_clear='\e[0m'
+ if [[ -n ${ZSH_VERSION-} ]]; then
+ local c_red='%F{red}'
+ local c_green='%F{green}'
+ local c_lblue='%F{blue}'
+ local c_clear='%f'
+ else
+ local c_red='\e[31m'
+ local c_green='\e[32m'
+ local c_lblue='\e[1;34m'
+ local c_clear='\e[0m'
+ fi
+
local bad_color=$c_red
local ok_color=$c_green
local branch_color="$c_clear"
@@ -379,23 +388,41 @@ __git_ps1 ()
branch_color="$bad_color"
fi
- # Setting gitstring directly with \[ and \] around colors
- # is necessary to prevent wrapping issues!
- gitstring="\[$branch_color\]$branchstring\[$c_clear\]"
+ if [[ -n ${ZSH_VERSION-} ]]; then
+ gitstring="$branch_color$branchstring$c_clear"
- if [ "$w" = "*" ]; then
- gitstring="$gitstring\[$bad_color\]$w"
- fi
- if [ -n "$i" ]; then
- gitstring="$gitstring\[$ok_color\]$i"
- fi
- if [ -n "$s" ]; then
- gitstring="$gitstring\[$flags_color\]$s"
- fi
- if [ -n "$u" ]; then
- gitstring="$gitstring\[$bad_color\]$u"
+ if [ "$w" = "*" ]; then
+ gitstring="$gitstring$bad_color$w"
+ fi
+ if [ -n "$i" ]; then
+ gitstring="$gitstring$ok_color$i"
+ fi
+ if [ -n "$s" ]; then
+ gitstring="$gitstring$flags_color$s"
+ fi
+ if [ -n "$u" ]; then
+ gitstring="$gitstring$bad_color$u"
+ fi
+ gitstring="$gitstring$c_clear$r$p"
+ else
+ # Setting gitstring directly with \[ and \] around colors
+ # is necessary to prevent wrapping issues!
+ gitstring="\[$branch_color\]$branchstring\[$c_clear\]"
+
+ if [ "$w" = "*" ]; then
+ gitstring="$gitstring\[$bad_color\]$w"
+ fi
+ if [ -n "$i" ]; then
+ gitstring="$gitstring\[$ok_color\]$i"
+ fi
+ if [ -n "$s" ]; then
+ gitstring="$gitstring\[$flags_color\]$s"
+ fi
+ if [ -n "$u" ]; then
+ gitstring="$gitstring\[$bad_color\]$u"
+ fi
+ gitstring="$gitstring\[$c_clear\]$r$p"
fi
- gitstring="$gitstring\[$c_clear\]$r$p"
else
gitstring="$c${b##refs/heads/}${f:+$f}$r$p"
fi
--
1.8.3.rc1.46.gfc3cab0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH v2] git-prompt.sh: colorize ZSH prompt
2013-05-11 22:18 ` [PATCH v2] git-prompt.sh: colorize ZSH prompt Ramkumar Ramachandra
@ 2013-05-11 22:29 ` Felipe Contreras
2013-05-11 22:40 ` Ramkumar Ramachandra
0 siblings, 1 reply; 16+ messages in thread
From: Felipe Contreras @ 2013-05-11 22:29 UTC (permalink / raw)
To: Ramkumar Ramachandra; +Cc: Git List, Junio C Hamano
On Sat, May 11, 2013 at 5:18 PM, Ramkumar Ramachandra
<artagnon@gmail.com> wrote:
> Add colors suitable for use in the ZSH prompt. Having learnt that the
> ZSH equivalent of PROMPT_COMMAND is precmd (), you can now use
> GIT_PS1_SHOWCOLORHINTS with ZSH.
>
> Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
> ---
> You like this more? I don't mind going either way.
Not really. If we need to avoid the \[\], it makes sense to have a
separate function, but what I meant is that this function should be
initially on the same file, and created in a separate patch.
--
Felipe Contreras
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v2] git-prompt.sh: colorize ZSH prompt
2013-05-11 22:29 ` Felipe Contreras
@ 2013-05-11 22:40 ` Ramkumar Ramachandra
2013-05-11 23:06 ` Felipe Contreras
0 siblings, 1 reply; 16+ messages in thread
From: Ramkumar Ramachandra @ 2013-05-11 22:40 UTC (permalink / raw)
To: Felipe Contreras; +Cc: Git List, Junio C Hamano
Felipe Contreras wrote:
> Not really. If we need to avoid the \[\], it makes sense to have a
> separate function, but what I meant is that this function should be
> initially on the same file, and created in a separate patch.
What are you saying?
1. It makes sense to have a separate function specifically for ZSH,
but it should be located in the same physical file (why?)
2. You like the original patch, but would prefer two different parts (a nit)
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v2] git-prompt.sh: colorize ZSH prompt
2013-05-11 22:40 ` Ramkumar Ramachandra
@ 2013-05-11 23:06 ` Felipe Contreras
0 siblings, 0 replies; 16+ messages in thread
From: Felipe Contreras @ 2013-05-11 23:06 UTC (permalink / raw)
To: Ramkumar Ramachandra; +Cc: Git List, Junio C Hamano
On Sat, May 11, 2013 at 5:40 PM, Ramkumar Ramachandra
<artagnon@gmail.com> wrote:
> Felipe Contreras wrote:
>> Not really. If we need to avoid the \[\], it makes sense to have a
>> separate function, but what I meant is that this function should be
>> initially on the same file, and created in a separate patch.
>
> What are you saying?
>
> 1. It makes sense to have a separate function specifically for ZSH,
> but it should be located in the same physical file (why?)
This is what I mean:
commit 4726a5f76ec7d96c34863d6640488e2183cc8f00
Author: Ramkumar Ramachandra <artagnon@gmail.com>
Date: Sat May 11 21:55:13 2013 +0530
prompt: split code into __git_ps1_colorize_gitstring()
Will be useful for reorganizations.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index eaf5c36..1187292 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -222,6 +222,45 @@ __git_ps1_show_upstream ()
}
+__git_ps1_colorize_gitstring ()
+{
+ local c_red='\e[31m'
+ local c_green='\e[32m'
+ local c_lblue='\e[1;34m'
+ local c_clear='\e[0m'
+ local bad_color=$c_red
+ local ok_color=$c_green
+ local branch_color="$c_clear"
+ local flags_color="$c_lblue"
+ local branchstring="$c${b##refs/heads/}"
+
+ if [ $detached = no ]; then
+ branch_color="$ok_color"
+ else
+ branch_color="$bad_color"
+ fi
+
+ # Setting gitstring directly with \[ and \] around colors
+ # is necessary to prevent wrapping issues!
+ gitstring="\[$branch_color\]$branchstring\[$c_clear\]"
+
+ if [ -n "$w$i$s$u$r$p" ]; then
+ gitstring="$gitstring "
+ fi
+ if [ "$w" = "*" ]; then
+ gitstring="$gitstring\[$bad_color\]$w"
+ fi
+ if [ -n "$i" ]; then
+ gitstring="$gitstring\[$ok_color\]$i"
+ fi
+ if [ -n "$s" ]; then
+ gitstring="$gitstring\[$flags_color\]$s"
+ fi
+ if [ -n "$u" ]; then
+ gitstring="$gitstring\[$bad_color\]$u"
+ fi
+ gitstring="$gitstring\[$c_clear\]$r$p"
+}
# __git_ps1 accepts 0 or 1 arguments (i.e., format string)
# when called from PS1 using command substitution
@@ -363,42 +402,7 @@ __git_ps1 ()
if [ $pcmode = yes ]; then
local gitstring=
if [ -n "${GIT_PS1_SHOWCOLORHINTS-}" ]; then
- local c_red='\e[31m'
- local c_green='\e[32m'
- local c_lblue='\e[1;34m'
- local c_clear='\e[0m'
- local bad_color=$c_red
- local ok_color=$c_green
- local branch_color="$c_clear"
- local flags_color="$c_lblue"
- local branchstring="$c${b##refs/heads/}"
-
- if [ $detached = no ]; then
- branch_color="$ok_color"
- else
- branch_color="$bad_color"
- fi
-
- # Setting gitstring directly with \[ and \] around colors
- # is necessary to prevent wrapping issues!
- gitstring="\[$branch_color\]$branchstring\[$c_clear\]"
-
- if [ -n "$w$i$s$u$r$p" ]; then
- gitstring="$gitstring "
- fi
- if [ "$w" = "*" ]; then
- gitstring="$gitstring\[$bad_color\]$w"
- fi
- if [ -n "$i" ]; then
- gitstring="$gitstring\[$ok_color\]$i"
- fi
- if [ -n "$s" ]; then
- gitstring="$gitstring\[$flags_color\]$s"
- fi
- if [ -n "$u" ]; then
- gitstring="$gitstring\[$bad_color\]$u"
- fi
- gitstring="$gitstring\[$c_clear\]$r$p"
+ __git_ps1_colorize_gitstring
else
gitstring="$c${b##refs/heads/}${f:+ $f}$r$p"
fi
commit 23d89b370ac36401da1d9a98754e222a7a4c93e5
Author: Felipe Contreras <felipe.contreras@gmail.com>
Date: Sat May 11 18:03:39 2013 -0500
prompt: add colorization for zsh
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index 1187292..8946a29 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -224,6 +224,8 @@ __git_ps1_show_upstream ()
__git_ps1_colorize_gitstring ()
{
+ if [[ -z ${ZSH_VERSION-} ]]
+ then
local c_red='\e[31m'
local c_green='\e[32m'
local c_lblue='\e[1;34m'
@@ -260,6 +262,39 @@ __git_ps1_colorize_gitstring ()
gitstring="$gitstring\[$bad_color\]$u"
fi
gitstring="$gitstring\[$c_clear\]$r$p"
+ else
+ local c_red='%F{red}'
+ local c_green='%F{green}'
+ local c_lblue='%F{blue}'
+ local c_clear='%f'
+ local bad_color=$c_red
+ local ok_color=$c_green
+ local branch_color="$c_clear"
+ local flags_color="$c_lblue"
+ local branchstring="$c${b##refs/heads/}"
+
+ if [ $detached = no ]; then
+ branch_color="$ok_color"
+ else
+ branch_color="$bad_color"
+ fi
+
+ gitstring="$branch_color$branchstring$c_clear"
+
+ if [ "$w" = "*" ]; then
+ gitstring="$gitstring$bad_color$w"
+ fi
+ if [ -n "$i" ]; then
+ gitstring="$gitstring$ok_color$i"
+ fi
+ if [ -n "$s" ]; then
+ gitstring="$gitstring$flags_color$s"
+ fi
+ if [ -n "$u" ]; then
+ gitstring="$gitstring$bad_color$u"
+ fi
+ gitstring="$gitstring$c_clear$r$p"
+ fi
}
# __git_ps1 accepts 0 or 1 arguments (i.e., format string)
--
Felipe Contreras
^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH 1/2] git-prompt.sh: strip unnecessary space in prompt string
2013-05-11 16:25 ` [PATCH 1/2] git-prompt.sh: strip unnecessary space in prompt string Ramkumar Ramachandra
@ 2013-05-13 4:57 ` Junio C Hamano
2013-05-13 7:40 ` Ramkumar Ramachandra
0 siblings, 1 reply; 16+ messages in thread
From: Junio C Hamano @ 2013-05-13 4:57 UTC (permalink / raw)
To: Ramkumar Ramachandra; +Cc: Git List
Ramkumar Ramachandra <artagnon@gmail.com> writes:
> Nobody has branch names that end with + or *. Then why put a space
> after the branch name and before [*|+][=|<|>] in the prompt string?
I do not think the space is for disambiguation.
It is like asking why typeset a space after a sentence a tad wider
than a space after each word: grouping related things together, and
separating groups of different kind apart, to make it more readable.
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 1/2] git-prompt.sh: strip unnecessary space in prompt string
2013-05-13 4:57 ` Junio C Hamano
@ 2013-05-13 7:40 ` Ramkumar Ramachandra
2013-05-13 9:17 ` SZEDER Gábor
0 siblings, 1 reply; 16+ messages in thread
From: Ramkumar Ramachandra @ 2013-05-13 7:40 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Git List
Junio C Hamano wrote:
> It is like asking why typeset a space after a sentence a tad wider
> than a space after each word:
Not at all. The prompt has nothing to do with sentences.
> grouping related things together, and
> separating groups of different kind apart, to make it more readable.
You could argue that the colors are not very well thought-out
(branch-name has the same color as +), but I really don't see the
problem otherwise. How is this more readable:
artagnon|master *=:~/src/git$
than:
artagnon|master*=:~/src/git$
(where master is green, * is red, and = is white)?
Looking at what we've done so far, I would argue that we're not
thinking about the usability of the prompt enough: it currently
screams I AM DOING REBASE-i! (and similarly for other operations in
progress). I intend to fix these things in future patches.
Thanks.
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 1/2] git-prompt.sh: strip unnecessary space in prompt string
2013-05-13 7:40 ` Ramkumar Ramachandra
@ 2013-05-13 9:17 ` SZEDER Gábor
2013-05-13 10:13 ` Ramkumar Ramachandra
0 siblings, 1 reply; 16+ messages in thread
From: SZEDER Gábor @ 2013-05-13 9:17 UTC (permalink / raw)
To: Ramkumar Ramachandra; +Cc: Junio C Hamano, Git List
On Mon, May 13, 2013 at 01:10:26PM +0530, Ramkumar Ramachandra wrote:
> Junio C Hamano wrote:
> > grouping related things together, and
> > separating groups of different kind apart, to make it more readable.
>
> You could argue that the colors are not very well thought-out
> (branch-name has the same color as +), but I really don't see the
> problem otherwise. How is this more readable:
>
> artagnon|master *=:~/src/git$
>
> than:
>
> artagnon|master*=:~/src/git$
>
> (where master is green, * is red, and = is white)?
IMHO that's just ugly ;)
Don't forget that others might use a different prompt format and using
colors in the prompt is optional. With the default prompt format and
without colors I find that that space definitely helps readability.
Gábor
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 1/2] git-prompt.sh: strip unnecessary space in prompt string
2013-05-13 9:17 ` SZEDER Gábor
@ 2013-05-13 10:13 ` Ramkumar Ramachandra
2013-05-13 11:05 ` SZEDER Gábor
0 siblings, 1 reply; 16+ messages in thread
From: Ramkumar Ramachandra @ 2013-05-13 10:13 UTC (permalink / raw)
To: SZEDER Gábor; +Cc: Junio C Hamano, Git List
SZEDER Gábor wrote:
> Don't forget that others might use a different prompt format and using
> colors in the prompt is optional. With the default prompt format and
> without colors I find that that space definitely helps readability.
I'm finding it hard to believe that anyone would want to use a colorless prompt.
> IMHO that's just ugly ;)
If we can agree that it's just a matter of taste, we should both be
able to have what we want. Any suggestions on how to make this
configurable?
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 1/2] git-prompt.sh: strip unnecessary space in prompt string
2013-05-13 10:13 ` Ramkumar Ramachandra
@ 2013-05-13 11:05 ` SZEDER Gábor
2013-05-13 11:11 ` SZEDER Gábor
0 siblings, 1 reply; 16+ messages in thread
From: SZEDER Gábor @ 2013-05-13 11:05 UTC (permalink / raw)
To: Ramkumar Ramachandra; +Cc: Junio C Hamano, Git List
On Mon, May 13, 2013 at 03:43:43PM +0530, Ramkumar Ramachandra wrote:
> SZEDER Gábor wrote:
> > Don't forget that others might use a different prompt format and using
> > colors in the prompt is optional. With the default prompt format and
> > without colors I find that that space definitely helps readability.
>
> I'm finding it hard to believe that anyone would want to use a colorless prompt.
Well, back then I was shell-shocked to find that there are people who
want colors in their prompt ;)
> > IMHO that's just ugly ;)
>
> If we can agree that it's just a matter of taste, we should both be
> able to have what we want. Any suggestions on how to make this
> configurable?
The same way we make other things configurable in the prompt: specify
the GIT_PS1_HIDESTATESEPARATOR or something similar variable to strip
that space from the prompt.
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 1/2] git-prompt.sh: strip unnecessary space in prompt string
2013-05-13 11:05 ` SZEDER Gábor
@ 2013-05-13 11:11 ` SZEDER Gábor
2013-05-13 13:58 ` Junio C Hamano
0 siblings, 1 reply; 16+ messages in thread
From: SZEDER Gábor @ 2013-05-13 11:11 UTC (permalink / raw)
To: Ramkumar Ramachandra; +Cc: Junio C Hamano, Git List
On Mon, May 13, 2013 at 01:05:51PM +0200, SZEDER Gábor wrote:
> On Mon, May 13, 2013 at 03:43:43PM +0530, Ramkumar Ramachandra wrote:
> > If we can agree that it's just a matter of taste, we should both be
> > able to have what we want. Any suggestions on how to make this
> > configurable?
>
> The same way we make other things configurable in the prompt: specify
> the GIT_PS1_HIDESTATESEPARATOR or something similar variable to strip
> that space from the prompt.
Or perhaps better yet: use a variable, e.g. GIT_PS1_STATESEPARATOR or
whatever, to specify what should separate the branch name from the
repo state, defaulting to a space to keep the current behavior.
Gábor
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 1/2] git-prompt.sh: strip unnecessary space in prompt string
2013-05-13 11:11 ` SZEDER Gábor
@ 2013-05-13 13:58 ` Junio C Hamano
2013-05-13 14:21 ` Ramkumar Ramachandra
0 siblings, 1 reply; 16+ messages in thread
From: Junio C Hamano @ 2013-05-13 13:58 UTC (permalink / raw)
To: SZEDER Gábor; +Cc: Ramkumar Ramachandra, Git List
SZEDER Gábor <szeder@ira.uka.de> writes:
> On Mon, May 13, 2013 at 01:05:51PM +0200, SZEDER Gábor wrote:
>> On Mon, May 13, 2013 at 03:43:43PM +0530, Ramkumar Ramachandra wrote:
>> > If we can agree that it's just a matter of taste, we should both be
>> > able to have what we want. Any suggestions on how to make this
>> > configurable?
>>
>> The same way we make other things configurable in the prompt: specify
>> the GIT_PS1_HIDESTATESEPARATOR or something similar variable to strip
>> that space from the prompt.
>
> Or perhaps better yet: use a variable, e.g. GIT_PS1_STATESEPARATOR or
> whatever, to specify what should separate the branch name from the
> repo state, defaulting to a space to keep the current behavior.
Why just a single knob for that SP?
If you restructure the code to formulate "gitstring" to call a shell
function to do so, people can override it and come up with whatever
format they want to use, no?
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 1/2] git-prompt.sh: strip unnecessary space in prompt string
2013-05-13 13:58 ` Junio C Hamano
@ 2013-05-13 14:21 ` Ramkumar Ramachandra
0 siblings, 0 replies; 16+ messages in thread
From: Ramkumar Ramachandra @ 2013-05-13 14:21 UTC (permalink / raw)
To: Junio C Hamano; +Cc: SZEDER Gábor, Git List
Junio C Hamano wrote:
> If you restructure the code to formulate "gitstring" to call a shell
> function to do so, people can override it and come up with whatever
> format they want to use, no?
The user would essentially have to implement her own
__git_ps1_colorize_string; a function that takes a lot of arguments
and stitches them together with color. Much too painful for little
gain.
^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2013-05-13 14:22 UTC | newest]
Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-11 16:25 [PATCH 0/2] Colored prompt for zsh Ramkumar Ramachandra
2013-05-11 16:25 ` [PATCH 1/2] git-prompt.sh: strip unnecessary space in prompt string Ramkumar Ramachandra
2013-05-13 4:57 ` Junio C Hamano
2013-05-13 7:40 ` Ramkumar Ramachandra
2013-05-13 9:17 ` SZEDER Gábor
2013-05-13 10:13 ` Ramkumar Ramachandra
2013-05-13 11:05 ` SZEDER Gábor
2013-05-13 11:11 ` SZEDER Gábor
2013-05-13 13:58 ` Junio C Hamano
2013-05-13 14:21 ` Ramkumar Ramachandra
2013-05-11 16:25 ` [PATCH 2/2] git-prompt.zsh: introduce thin ZSH wrapper Ramkumar Ramachandra
2013-05-11 21:26 ` Felipe Contreras
2013-05-11 22:18 ` [PATCH v2] git-prompt.sh: colorize ZSH prompt Ramkumar Ramachandra
2013-05-11 22:29 ` Felipe Contreras
2013-05-11 22:40 ` Ramkumar Ramachandra
2013-05-11 23:06 ` Felipe Contreras
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.