completion: prompt: use generic colors
commit7ee1af8cb8b97385fc4e603bc024d877def5adb4
authorFelipe Contreras <felipe.contreras@gmail.com>
Tue, 28 Feb 2023 14:59:34 +0000 (28 08:59 -0600)
committerJunio C Hamano <gitster@pobox.com>
Thu, 16 Mar 2023 22:58:22 +0000 (16 15:58 -0700)
tree4ab6c0ee06ad2b74f870d4d8eb42aba379da886e
parent73876f4861cd3d187a4682290ab75c9dccadbc56
completion: prompt: use generic colors

When the prompt command mode was introduced in 1bfc51ac81 (Allow
__git_ps1 to be used in PROMPT_COMMAND, 2012-10-10), the assumption was
that it was necessary in order to properly add colors to PS1 in bash,
but this wasn't true.

It's true that the \[ \] markers add the information needed to properly
calculate the width of the prompt, and they have to be added directly to
PS1, a function returning them doesn't work.

But that is because bash coverts the \[ \] markers in PS1 to \001 \002,
which is what readline ultimately needs in order to calculate the width.

We don't need bash to do this conversion, we can use \001 \002
ourselves, and then the prompt command mode is not necessary to display
colors.

This is what functions returning colors are supposed to do [1].

[1] http://mywiki.wooledge.org/BashFAQ/053

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Tested-by: Joakim Petersen <joak-pet@online.no>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
contrib/completion/git-prompt.sh
t/t9903-bash-prompt.sh