views:

142

answers:

3

Instead of running "svn diff", "hg diff" and so on .. can we write a single command that calls svn/hg/git accordingly? Can the diff output be made pretty?

edit: command-line tools (not GUI) preferred.

+2  A: 

Typing "svn diff" or "hg diff" is no fun if you had to type it again just to page the output with less. Further, when it is likely that your text editor does syntax highlighting .. there is no reason why the diff output in the terminal should not also be highlighted with appropriate colors.

alt text

You will need colordiff which can be installed via apt or macports.

The following bash function will enable one to type just `dif' under the working directory of the VCS of your choice (no need to specify whether it is hg or svn).

function dif {
   if [ -d .hg ]; then
       VC='hg'
   elif [ -d .svn ]; then
       VC='svn'
   else
       echo "cannot find VC type"
       return 1
   fi
   $VC diff $1 | colordiff | less -R
}

It should be easy to add support for other VCS tools (git, cvs, etc..)

Additionally if you have UVC installed (as per Ryan Wilcox's answer), the above script can be simplified as:

function dif {
   uvc diff $1 | colordiff | less -R
}
Sridhar Ratnakumar
you can collapse your `test` and `if` statements: `if [ -d .hg ]; then` also you should balance out your `if` by using `if...elif...else` (or use a `case` statement).
Dennis Williamson
Thx, I modified the code.
Sridhar Ratnakumar
+2  A: 

There are also a number of "wrap all the common VCS commands into one utility" projects. pyvcs and UVC are two that come to mind. Maybe these would do what you want?

RyanWilcox
`pyvcs` package does not seem to install any scripts; is it only providing an abstract API?
Sridhar Ratnakumar
Woh, but I guess you are right. My bad.
RyanWilcox
Thank you for the UVC reference, I have updated my script to use UVC.
Sridhar Ratnakumar
A: 

Try Diffuse. It will figure out the appropriate version control system and display diffs with nice syntax highlighting.

Derrick Moser