From: Junio C Hamano Date: Tue, 02 Oct 2012 20:18:18 GMT Subject: Re: [PATCH] Add __git_ps1_pc to use as PROMPT_COMMAND Message-ID: <7v8vbo7hmd.fsf@alter.siamese.dyndns.org> In-Reply-To: <506B4598.1020206@xs4all.nl> Simon Oosthoek 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.