Skip to content

Anuar-boop/diff-tool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

diff-tool

A Python file and directory diff tool with colored output, multiple view modes, and patch support. Zero dependencies.

Features

  • Compare two files line-by-line with colored output (red for removed, green for added)
  • Word-level diff for fine-grained changes
  • Side-by-side view
  • Directory diff (list changed, added, and removed files)
  • Unified diff format
  • Ignore whitespace and case options
  • Binary file detection
  • Summary statistics (lines added, removed, changed)
  • Output as patch file
  • Apply patch files
  • Respects NO_COLOR environment variable

Installation

git clone https://github.com/Anuar-boop/diff-tool.git
cd diff-tool
chmod +x diff_tool.py

# Optional: add to PATH
sudo ln -s "$(pwd)/diff_tool.py" /usr/local/bin/diff-tool

Usage

Compare Files

# Unified diff (default)
python3 diff_tool.py file1.txt file2.txt

# Side-by-side view
python3 diff_tool.py --side-by-side file1.txt file2.txt

# Word-level diff
python3 diff_tool.py --word file1.txt file2.txt

# Ignore whitespace
python3 diff_tool.py -b file1.txt file2.txt

# Ignore case
python3 diff_tool.py -i file1.txt file2.txt

# Custom terminal width for side-by-side
python3 diff_tool.py -y -W 160 file1.txt file2.txt

Compare Directories

# List changed, added, and removed files
python3 diff_tool.py dir1/ dir2/

Patch Files

# Create a patch
python3 diff_tool.py --patch changes.patch original.txt modified.txt

# Apply a patch
python3 diff_tool.py --apply changes.patch

# Apply to a specific file
python3 diff_tool.py --apply changes.patch target.txt

# Reverse a patch
python3 diff_tool.py --apply changes.patch -R

Options

Option Description
-y, --side-by-side Side-by-side view
-w, --word Word-level diff
-b, --ignore-whitespace Ignore whitespace differences
-i, --ignore-case Case-insensitive comparison
-W, --width N Terminal width for side-by-side (default: 120)
-p, --patch FILE Output diff as patch file
-a, --apply PATCH Apply a patch file
-R, --reverse Reverse patch when applying
--version Show version

Output Examples

Unified Diff

--- file1.txt
+++ file2.txt
@@ -1,4 +1,4 @@
 line one
-line two
+line TWO (modified)
 line three
-line four
+line five (new)

Directory Diff

Only in dir1/:
  - old_file.txt

Only in dir2/:
  + new_file.txt

Changed:
  ~ config.json

---
  1 removed, 1 added, 1 changed, 5 identical

Requirements

  • Python 3.6+
  • No external dependencies

License

MIT

About

Python file and directory diff tool with colored output, multiple view modes, and patch support

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages