| 1 |
Name |
| 2 |
|
| 3 |
colordiff -- a tool to colorize diff output |
| 4 |
|
| 5 |
Synopsis |
| 6 |
|
| 7 |
colordiff [diff options] [colordiff options] {file1} {file2} |
| 8 |
|
| 9 |
Description |
| 10 |
|
| 11 |
colordiff is a wrapper for diff and produces the same output as |
| 12 |
diff but with coloured syntax highlighting at the command line |
| 13 |
to improve readability. The output is similar to how a |
| 14 |
diff-generated patch might appear in Vim or Emacs with the |
| 15 |
appropriate syntax highlighting options enabled. The colour |
| 16 |
schemes can be read from a central configuration file or from a |
| 17 |
local user ~/.colordiffrc file. |
| 18 |
|
| 19 |
colordiff makes use of ANSI colours and as such will only work |
| 20 |
when ANSI colours can be used - typical examples are xterms and |
| 21 |
Eterms, as well as console sessions. |
| 22 |
|
| 23 |
colordiff has been tested on various flavours of Linux and |
| 24 |
under OpenBSD, but should be broadly portable to other systems. |
| 25 |
|
| 26 |
Usage |
| 27 |
|
| 28 |
Use colordiff wherever you would normally use diff, or instead |
| 29 |
pipe output to colordiff: |
| 30 |
|
| 31 |
For example: |
| 32 |
$ colordiff file1 file2 |
| 33 |
$ diff -u file1 file2 | colordiff |
| 34 |
|
| 35 |
You can pipe the output to 'less', using the '-R' option (some |
| 36 |
systems or terminal types may get better results using '-r' |
| 37 |
instead), which keeps the colour escape sequences, otherwise |
| 38 |
displayed incorrectly or discarded by 'less': |
| 39 |
$ diff -u file1 file2 | colordiff | less -R |
| 40 |
|
| 41 |
If you want to force disable colour escape sequences (for |
| 42 |
example pipe the output to patch), you can use option |
| 43 |
'--color=no' to do so: |
| 44 |
$ diff -u file1 file2 | colordiff --color=no | patch -p0 -d another-work |
| 45 |
ing-dir |
| 46 |
|
| 47 |
If you have wdiff installed, colordiff will correctly colourise |
| 48 |
the added and removed text, provided that the '-n' option is |
| 49 |
given to wdiff: |
| 50 |
$ wdiff -n file1 file2 | colordiff |
| 51 |
|
| 52 |
You may find it useful to make diff automatically call |
| 53 |
colordiff. Add the following line to ~/.bashrc (or equivalent): |
| 54 |
alias diff=colordiff |
| 55 |
|
| 56 |
Any options passed to colordiff are passed through to diff |
| 57 |
except for the colordiff-specific option 'difftype', e.g. |
| 58 |
colordiff --difftype=debdiff file1 file2 |
| 59 |
|
| 60 |
Valid values for 'difftype' are: diff, diffc, diffu, diffy, |
| 61 |
wdiff, debdiff; these correspond to plain diffs, context diffs, |
| 62 |
unified diffs, side-by-side diffs, wdiff output and debdiff |
| 63 |
output respectively. Use these overrides when colordiff is not |
| 64 |
able to determine the diff-type automatically. |
| 65 |
|
| 66 |
Alternatively, a construct such as 'cvs diff SOMETHING | |
| 67 |
colordiff' can be included in ~/.bashrc as follows: |
| 68 |
function cvsdiff () { cvs diff $@ | colordiff; } |
| 69 |
|
| 70 |
Or, combining the idea above using 'less': |
| 71 |
function cvsdiff () { cvs diff $@ | colordiff |less -R; } |
| 72 |
|
| 73 |
Note that the function name, cvsdiff, can be customized. |
| 74 |
|
| 75 |
By default colordiff returns the exit code of the underlying |
| 76 |
diff invocation (if there is one), but there are some |
| 77 |
circumstances where it is useful to force colordiff's exit code |
| 78 |
to be zero: to do this use the option '--fakeexitcode': |
| 79 |
colordiff --fakeexitcode ... |
| 80 |
|
| 81 |
Options |
| 82 |
|
| 83 |
colordiff will send most options through to diff, but there are |
| 84 |
various colordiff-specific options which can be used: |
| 85 |
|
| 86 |
--help |
| 87 |
Show these colordiff-specific options |
| 88 |
|
| 89 |
--color=(yes|no) |
| 90 |
Force (or suppress) display of colours in output |
| 91 |
|
| 92 |
--color=patches=(yes|no) |
| 93 |
Force (or suppress) inclusion of colour codes in patch |
| 94 |
output |
| 95 |
|
| 96 |
--color-term-output-only |
| 97 |
Force colour to only appear in terminal output |
| 98 |
|
| 99 |
--difftype=DIFFTYPE |
| 100 |
Force difftype detection to specified format. DIFFTYPE |
| 101 |
can be: diff, diffc, diffu, diffy, debdiff, wdiff |
| 102 |
|
| 103 |
--(no)banner |
| 104 |
Show (or suppress) the colordiff banner |
| 105 |
|
| 106 |
Files |
| 107 |
|
| 108 |
/etc/colordiffrc |
| 109 |
Central configuration file. User-specific settings can |
| 110 |
be enabled by copying this file to ~/.colordiffrc and |
| 111 |
making the appropriate changes. |
| 112 |
|
| 113 |
colordiffrc-lightbg |
| 114 |
Alternate configuration template for use with terminals |
| 115 |
having light backgrounds. Copy this to /etc/colordiffrc |
| 116 |
or ~/.colordiffrc and customize. |
| 117 |
|
| 118 |
colordiffrc-gitdiff |
| 119 |
Alternate configuration template for use with terminals |
| 120 |
having dark backgrounds, with colour defaults set to |
| 121 |
match the output of 'git diff'. Copy this to |
| 122 |
/etc/colordiffrc or ~/.colordiffrc and customize. |
| 123 |
|
| 124 |
Bugs |
| 125 |
|
| 126 |
Bug reports and suggestions/patches to <[email protected]> |
| 127 |
please. |