Re: Add colors to the prompt for status indicators

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Sorry for the delayed response to this one - I'm afraid it's the usual
work excuse :)

Non-printing characters need to be surrounded by \[ and \] for bash to
calculate line lengths correctly.  So far as I can tell, this has to be
in PS1 itself - bash doesn't recognise it if it's included in a script.

To see the problem, do this:

OLD_PS1="$PS1"
PS1="\033[0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0m>"

Then hold down any key - you should see some weird line-wrapping
behaviour a little way before the edge of your terminal.  To get your
old terminal back:

PS1="$OLD_PS1"

To see what happens when the "\[" characters are embedded in a script:

foo() {
 echo -e "\[\033[;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0m\]"
}
PS1='$(foo)>'

The "\[" and "\]" are represented literally in your terminal, and the
line-wrapping still occurs.

It's possible to work around this for a whole script:

foo() {
 echo -e "\033[;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0m"
}
PS1='\[$(foo)'\]>'

As a fan of colourful prompts, I'd be very happy if you found a way
around this for parts of a script.  But as a fan of fast prompts, I'd
prefer not to call __git_ps1 more than once :)

	- Andrew
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]