* Re: [PATCH] git-prompt: make colors available in custom prompts
[not found] <1461301201-92142-1-git-send-email-andrew@schwartzmeyer.com>
@ 2016-05-02 6:40 ` Simon Oosthoek
2016-05-02 7:15 ` Andreas Schwab
0 siblings, 1 reply; 2+ messages in thread
From: Simon Oosthoek @ 2016-05-02 6:40 UTC (permalink / raw)
To: Andrew Schwartzmeyer, git; +Cc: erdavila
Hi Andrew
sorry, I only noticed your request this morning...
On 22/04/16 07:00, Andrew Schwartzmeyer wrote:
> This was disabled in the original implementation, probably because it
> does not work if the __git_ps1 function is single-quoted. However, if
> you double-quote per the updated documentation, you can have colors in
> your custom Git prompt function, no problem.
>
> Signed-off-by: Andrew Schwartzmeyer <andrew@schwartzmeyer.com>
> ---
> contrib/completion/git-prompt.sh | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
> index f18aedc73..ffe79168c 100644
> --- a/contrib/completion/git-prompt.sh
> +++ b/contrib/completion/git-prompt.sh
> @@ -12,8 +12,8 @@
> # source ~/.git-prompt.sh
> # 3a) Change your PS1 to call __git_ps1 as
> # command-substitution:
> -# Bash: PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
> -# ZSH: setopt PROMPT_SUBST ; PS1='[%n@%m %c$(__git_ps1 " (%s)")]\$ '
> +# Bash: PS1="[\u@\h \W$(__git_ps1 ' (%s)')]\$ "
> +# ZSH: setopt PROMPT_SUBST ; PS1="[%n@%m %c$(__git_ps1 ' (%s)')]\$ "
I haven't tested this at all, but when using double quotes, you need to
at least check all the escapings, like \$ should probably be: \\\$ when
used in double quotes.
> # the optional argument will be used as format string.
> # 3b) Alternatively, for a slightly faster prompt, __git_ps1 can
> # be used for PROMPT_COMMAND in Bash or for precmd() in Zsh
> @@ -82,8 +82,9 @@
> #
> # If you would like a colored hint about the current dirty state, set
> # GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on
> -# the colored output of "git status -sb" and are available only when
> -# using __git_ps1 for PROMPT_COMMAND or precmd.
> +# the colored output of "git status -sb". If you are using your own
> +# PROMPT_COMMAND function, you must use double-quotes when calling
> +# __git_ps1, e.g. PS1="$(__git_ps1 '%s ')".
> #
> # If you would like __git_ps1 to do nothing in the case when the current
> # directory is set up to be ignored by git, then set
> @@ -499,8 +500,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
>
>
The original reason for not using colors in command substitution mode
was that the prompt string length was not calculated correctly by bash
and it messed up the commandline with very long commands (relative to
the terminal width), when browsing the command history.
However I think I've seen this effect even with the new code, but I've
never dug into this.
Cheers
Simon
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] git-prompt: make colors available in custom prompts
2016-05-02 6:40 ` [PATCH] git-prompt: make colors available in custom prompts Simon Oosthoek
@ 2016-05-02 7:15 ` Andreas Schwab
0 siblings, 0 replies; 2+ messages in thread
From: Andreas Schwab @ 2016-05-02 7:15 UTC (permalink / raw)
To: Simon Oosthoek; +Cc: Andrew Schwartzmeyer, git, erdavila
Simon Oosthoek <s.oosthoek@xs4all.nl> writes:
> Hi Andrew
>
> sorry, I only noticed your request this morning...
>
> On 22/04/16 07:00, Andrew Schwartzmeyer wrote:
>> diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
>> index f18aedc73..ffe79168c 100644
>> --- a/contrib/completion/git-prompt.sh
>> +++ b/contrib/completion/git-prompt.sh
>> @@ -12,8 +12,8 @@
>> # source ~/.git-prompt.sh
>> # 3a) Change your PS1 to call __git_ps1 as
>> # command-substitution:
>> -# Bash: PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
>> -# ZSH: setopt PROMPT_SUBST ; PS1='[%n@%m %c$(__git_ps1 " (%s)")]\$ '
>> +# Bash: PS1="[\u@\h \W$(__git_ps1 ' (%s)')]\$ "
>> +# ZSH: setopt PROMPT_SUBST ; PS1="[%n@%m %c$(__git_ps1 ' (%s)')]\$ "
>
> I haven't tested this at all, but when using double quotes, you need to at
> least check all the escapings, like \$ should probably be: \\\$ when used
> in double quotes.
By using double quotes the command subsititution is expanded when PS1 is
set, which makes it pretty useless.
> The original reason for not using colors in command substitution mode was
> that the prompt string length was not calculated correctly by bash and it
> messed up the commandline with very long commands (relative to the
> terminal width), when browsing the command history.
If you want to include control characters in the prompt that don't
contribute to the length you have to enclose them in \[ \]. The problem
is that \[ \] are processed before embedded command substitutions are
expanded, thus they cannot produce such control characters.
Andreas.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-05-02 7:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <1461301201-92142-1-git-send-email-andrew@schwartzmeyer.com>
2016-05-02 6:40 ` [PATCH] git-prompt: make colors available in custom prompts Simon Oosthoek
2016-05-02 7:15 ` Andreas Schwab
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).