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
Oct 31, 2010, 06:26 UTC
Message-ID
<334DB5BC-BE36-4D83-B358-3982DBA38EA1@sb.org>
In-Reply-To
<AANLkTi=ZdR4_reQgxL+xRaFE=SaqBYAWTrEuGEbLGynt@mail.gmail.com>
You could write a shell function that takes a string as an argument and inserts the appropriate color codes based on string substitution, and then just pass the results of __git_ps1 to that function.
Something like the following might work:
function __my_git_colorize_ps1 () {
    echo "$1" | while read -N 1 char; do
        case "$char" in
            \*) echo -n $'\e[34m*\e[m';;
            +) echo -n $'\e[31m+\e[m';;
            $) echo -n $'\e[32m$\e[m';;
            %) echo -n $'\e[1;34m%\e[m';;
            \<|\>) echo -n $'\e[31m'"$char"$'\e[m';;
            *) echo -n "$char";;
        esac
    done
}
-Kevin Ballard
On Oct 30, 2010, at 9:14 PM, Sebastien Douche wrote:
Show 18 quoted lines
> Hi,
> the prompt (git-completion.bash) bundled with git is the most
> "advanced" I found on the web. But I would add colors for "status".
> Example show: * (unstaged) in blue, + (staged in red), $ (stashed) in
> green, % (untracked) in bold blue and < > <> (upstream indicator) in
> red.
> 
> How make this?
> 
> Cheers
> 
> -- 
> Sebastien Douche <sdouche@gmail.com>
> Twitter: http://bit.ly/afkrK (agile, lean, python, git, open source)
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous: Sebastien DoucheNext: Andrew Sayers
Message 2 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.