Git and Mercurial console output customization
22 Jan 2012Recently with a lot of help from guys from Polidea, we have created few useful output customization for our version control systems(for those who use terminal). So let's start with mercurial, here is part of the .hgrc file (Mercurial.ini on Windows, however some commands might not work):
# extension for paging mercurial output
[pager]
pager = LESS='FSRX' less
attend = annotate, cat, diff, export, glog, log, qdiff, hist
# extension do display log in graphical way
[extensions]
graphlog =
pager =
# alias for pretty printing mercurial log
[alias]
hist = glog --template "
33[31m{node|short}
33[0m
33[1;34m<{author|person}>
33[0m
33[32m({date|age})
33[0m \n\t\t{desc}\n"
We first enable and configure pager extension which basically allows you to scroll through the command output, it works pretty much like hg <your command> | less. Then we enable graphlog extension, that makes hg log to print nicely formated graph of branches, merges, commits, etc. Finally to additionally color log output we do some magic, and define our own hg log with custom template. Final result of running hg hist looks like this:
The same can be done for git. Here is equivalent .gitconfig (thanks to Wojciech Erbetowski for this):
[alias]
hist = log --pretty=format:'%Cred%h%Creset %C(bold blue)<%an>%Creset%C(yellow)%d%Creset %Cgreen(%cr)%Creset%n%w(80,8,8)%s' --graph