git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Add colors to the prompt for status indicators

From
Kevin Ballard <kevin@sb.org>
Date
Nov 15, 2010, 22:52 UTC
Message-ID
<19363118-D147-4946-8973-B5DDA4B00985@sb.org>
In-Reply-To
<4CE04B82.1040804@pileofstuff.org>
On Nov 14, 2010, at 12:50 PM, Andrew Sayers wrote:
Show 6 quoted lines
> 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)'\]>'

If $(foo) were to emit some actual printable characters, won't this make bash ignore them when calculating line lengths?

> 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 :)

I don't think there is any way around this, besides patching bash to be intelligent and determine which PS1 characters are printable itself without relying on \[ and \].

-Kevin Ballard
Previous: Andrew SayersNext: Kevin Ballard
Message 4 of 9 in “Add colors to the prompt for status indicators”
  1. Sebastien DoucheOct 31, 2010
  2. Kevin BallardOct 31, 2010
  3. Andrew SayersNov 14, 2010
  4. Kevin BallardNov 15, 2010
  5. Kevin BallardNov 15, 2010
  6. Sebastien DoucheNov 16, 2010
  7. Kevin BallardNov 16, 2010
  8. Michael J GruberNov 16, 2010
  9. Kevin BallardNov 16, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.