Re: [PATCH] Add __git_ps1_pc to use as PROMPT_COMMAND
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Oct 2, 2012, 20:18 UTC
- Message-ID
- <7v8vbo7hmd.fsf@alter.siamese.dyndns.org>
- In-Reply-To
- <506B4598.1020206@xs4all.nl>
Simon Oosthoek <s.oosthoek@xs4all.nl> writes:
> ... This is > prevented (and quite the norm in static PS1 strings) by enclosing the > terminal code for color inside \[ and \] so bash doesn't count these and > what is in between them in the length of the prompt string.
Ah, OK, and these \[ things \] behave like other magics like \h and \W in PS1 in that PS1='\h $(echo_bs_w)' will not work as expected with
echo_bs_w () {
printf "%s" "\\W"
}hence cannot be used in __git_ps1 function that is called as $(command substitution).
That was what I was missing.
> The only way to get the colors in without messing up normal functioning > of the prompt is to use PROMPT_COMMAND to set PS1, with colors based > dynamically on the state of the tree.
OK. Thanks for explanation.