[prev in list] [next in list] [prev in thread] [next in thread] 

List:       git
Subject:    Re: Add colors to the prompt for status indicators
From:       Kevin Ballard <kevin () sb ! org>
Date:       2010-10-31 6:26:21
Message-ID: 334DB5BC-BE36-4D83-B358-3982DBA38EA1 () sb ! org
[Download RAW message or body]

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:

> 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

--
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
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic