diffcolor (DiffColor.py)
Winston C. Yang
winston at cs dot wisc dot edu
This file was last modified on 2010-01-15.
diffcolor’s license is the GNU General Public License version 3, or any later version.
diffcolor colors and line-wraps the output of Python's difflib module. (Python is a programming language.) A screenshot:
The screenshot shows the differences between two files.
•.The names of the files are on the first two lines of output, along with their last modification times.
•. Cyan (light blue) indicates text that is in only file1.
•.Magenta (light purple) indicates text that is in only file2.
•.Yellow indicates text that is conflicting in both files.
•.Consecutive different lines are grouped into “diff sets.” For example, diff set 5 contains lines 233—235 in file1, and lines 239—241 in file2.
SYSTEM REQUIREMENTS
•.diffcolor requires a command-line environment, like Unix. On Mac OS X, open the Terminal application.
•. diffcolor requires Python 3.1.1 or higher, which you can download at python.org. Type "python3". If you get an error message, you might not have it installed.
•.Even if you are using older versions of Python, you may still be able to use diffcolor. If you install Python 3.1.1, the installation program might create a directory for Python3.1.1 and not touch your old Python directories.
EXAMPLE USAGE
You can create an alias “diffcolor” for “python3 DiffColor.py”. See a later section for how to create an alias.
Example: (No alias) Find the differences between two files called file1 and file2. You might have to specify paths to python3, DiffColor.py, file1, or file2.
python3 DiffColor.py file1 file2
Example. The previous example with an alias.
diffcolor file1 file2
Example. Show more text per line. If the output looks unusual, widen your window.
diffcolor --columns=150 file1 file2
Example. Make each tab be 4 spaces. Note that tabs are underlined in the output.
diffcolor --tab=4 file1 file2
Example. Show help.
diffcolor --help
CREATE AN ALIAS FOR DIFFCOLOR
Instead of typing
python3 DiffColor.py
you can create an alias “diffcolor” as follows.
Type
echo $0
If the output is "-bash", you are using the Bourne-Again Shell.
If the output is "-tcsh", you are using the TENEX (operating system) C Shell.
If your shell is different, you might have to change the following directions.
If you are using bash, add the following line to the bash resource configuration file .bashrc, which may be in your home directory. Type cd or cd ~/ to go to your home directory. You may have to specify paths to python3 or DiffColor.py.
alias diffcolor="python3 DiffColor.py"
If you are using tcsh, add the following line to your .cshrc.local file or a similar file:
alias diffcolor "python3 DiffColor.py"
Save the .bashrc file, or .cshrc.local, or similar file.
Exit your text editor.
On the command line, in your home directory, type
source .bashrc
or
source .cshrc.local