Donnerstag, 17. Mai 2012

Colorful svn diff

How to get a colorful svn diff?

First install the program colordiff.

aptitude install colordiff

Now SVN must be told to use colordiff, so edit your ~/.subversion/config and add the line

diff-cmd = colordiff

in the [helpers] section (usually there is a commented template you can use). Now the output of

svn diff

will be a colorful representation of your changes.

However, this creates one problem when piped to less, because it shows the escape characters with caret notation. Therefore the command line parameter -R is used to display ANSI color escape sequences as colors. Set the environment variable LESS with this option.

export LESS="-R"

One more improvement: less wraps the lines at screen width which is often not desired. Therefore use the switch -s to get a line-by-line output. For a permanent setting, put

export LESS="-sR"

to ~/.bashrc or system wide to /etc/bash.bashrc.

One more tip: A recursive search in an SVN working copy with grep also reveals occurences in the internal "backup" files. Therefore the following alias excludes the .svn subdirectory (and backup files of your editor and compiled Python files).

alias rsgrep='rgrep --exclude-dir=.svn --exclude=*~ --exclude=*.pyc'


Philipp9494 hat gesagt…

This is a 'pretty' hint, Hansi :)
I've tested this on Arch Linux (the package is also named 'colordiff' - so you can also install it with 'pacman -S colordiff')

But, I've a little question.
Is 'rgrep' the same as 'grep -r'?
Because I don't have this alias on my system.


Johann Glaser hat gesagt…

Thanks Philipp for the info!

Regarding "rgrep", yes, this is a little Debian extension I got used to. :-)

$ which rgrep
$ cat /usr/bin/rgrep

exec grep -r "$@"


Simple, but useful. You could also add it as an alias:

alias rgrep='grep -r'