Re: Add colors to the prompt for status indicators

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

 



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@xxxxxxxxx>
> 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@xxxxxxxxxxxxxxx
> 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@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]