Thread (2 messages) flat view 2 messages, 2 authors, 2016-06-15

Re: [PATCH] Add __git_ps1_pc to use as PROMPT_COMMAND

From: Simon Oosthoek <hidden>
Date: 2016-06-15 22:54:55

On 02/10/12 19:01, Junio C Hamano wrote:
If your goal is to use PROMPT_COMMAND and not PS1, then yes between
the two definitions of PROMPT_COMMAND above, the latter may look
simpler.  But that does not explain why you want to prefer it over
PS1 in the first place, which was the central point of my question
that still has not been answered.

Even more confused...
The specific answer to your question is that without using
PROMPT_COMMAND it doesn't seem to be possible to use colors based on the
state of the git tree. The reason being that in order to prevent
wrapping problems on the command line (specifically going up/down the
history list in bash or line wrapping on a long command). 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.

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.

In my current version (which I haven't had time to properly send out,
sorry!) it can do both using the same __git_ps1 function. But only color
in the PROMPT_COMMAND mode for the reason laid out above.

Having said that, I think there's another benefit to using
PROMPT_COMMAND; I think it is more elegant to use a function via
PROMPT_COMMAND (now that I know of it), than using a function via
command substitution inside the PS1.

I guess your (and my) confusion is more caused by unfamiliarity with
this feature of bash than it being used. Is that correct?

*desperately trying to get out of confused mode*

Cheers

Simon
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help