Vardens Archangel
Vardens Archangel

Reputation: 375

Color git commiter name

I'm working on a project with few people, it's my first time using git, and I found enjoyable coloring git output. For example:

 git log --graph --format='%C(yellow bold)%h%Creset %C(white bold)%s%Creset%n     %C(magenta    bold)%cr%Creset   %C(green bold)%an%Creset'

I'd like now to color my name as blue bold, and other authors as green bold. Is it possible? One more thing: I'm working with windows git bash.

Upvotes: 0

Views: 135

Answers (2)

patthoyts
patthoyts

Reputation: 33193

If you take the example git-log script in the git/compat/examples folder and modify it to process each revision one at a time you can inspect the author and change things. This is significantly slower than normal git lot however. Here is my version:

#!/bin/bash
#

USAGE='[--max-count=<n>] [<since>..<limit>] [--pretty=<format>] [git-rev-list options]'
SUBDIRECTORY_OK='Yes'
. git-sh-setup

revs=$(git-rev-parse --revs-only --no-flags --default HEAD "$@") || exit
[ "$revs" ] || {
        die "No HEAD ref"
}

for rev in $(git-rev-list $(git-rev-parse --default HEAD "$@"))
do
    an=$(git log -1 --pretty=format:%an $rev)
    case $an in
        *Thoyts) color=blue ;;
        *)       color=green ;;
    esac
    git log -1 --decorate --pretty=format:"%C(yellow bold)%h%Creset %C(white bold)%<(70,trunc)%s%Creset%n    %C(magenta bold)%cr%Creset    %C(${color} bold)%an%Creset" $rev
done

Running this on the git-gui repository seems to work ok. I truncated the subject a bit (the %<(70,trunc) part.

Upvotes: 2

torek
torek

Reputation: 487755

Not directly within git. Those %C(name) directives will let you set an author name to blue or green bold just fine, but you can't test a string somehow and then color it based on the result.

You could annotate the author name some other way (so that you can tell, in some automated fashion, exactly which part of the git log output is the author-name) and then post-process the git log output with a separate program that colors one name, or a few particular names, one color, and all others some other color. Then make a git alias (e.g., git logx) that invokes the shell to run git log ... | your-recoloring-program | less -FRSX or whatever.

Upvotes: 1

Related Questions