A beautiful, feature-rich file comparison tool with syntax highlighting and multiple viewing modes
Features • Installation • Usage • Examples • Documentation
|
|
python diff_plus.py old_file.php new_file.php --stats╭──────────────────────────────────────────────────────╮
│ Diff Statistics: old_file.php ↔ new_file.php │
╰──────────────────────────────────────────────────────╯
╭─────────────────── Statistics ───────────────────────╮
│ 📄 File A Lines │ 70 │
│ 📄 File B Lines │ 143 │
│ ➕ Additions │ 31 │
│ ➖ Deletions │ 1 │
│ 🔄 Modifications │ 74 │
│ 📊 Total Changes │ 106 │
│ ✨ Similarity │ 41.3% │
│ 💾 File A Size │ 1.6KB │
│ 💾 File B Size │ 4.1KB │
╰──────────────────────────────────────────────────────╯
Change Distribution:
+ ██████████████ 31
- 1
~ ██████████████████████████████████ 74
Perfect for reviewing code changes with syntax highlighting:
python diff_plus.py old.py new.py -s -n -l pythonClassic diff format with beautiful colors:
python diff_plus.py config_v1.json config_v2.json- Python 3.7 or higher
- pip package manager
pip install rich# Clone or download diff_plus.py
git clone https://github.com/LvL23HT/diff_plus.git
cd diff_plus
chmod +x diff_plus.py# Simple comparison
python diff_plus.py file1.txt file2.txt
# Side-by-side view
python diff_plus.py file1.py file2.py -s
# Show statistics
python diff_plus.py old.js new.js --statspython diff_plus.py old_code.php new_code.php -s -npython diff_plus.py config1.yaml config2.yaml -w# Compare current file with last commit
git show HEAD:src/app.py > /tmp/old_app.py
python diff_plus.py /tmp/old_app.py src/app.py -s -n# Side-by-side with word-level diff
python diff_plus.py feature-old.js feature-new.js -s --word-diff# See what changed after refactoring
python diff_plus.py before_refactor.py after_refactor.py --stats# Ignore whitespace differences
python diff_plus.py production.conf staging.conf -w# Compare .env files (ignore case)
python diff_plus.py .env.development .env.production --ignore-case# Inline view for markdown files
python diff_plus.py README_v1.md README_v2.md -i -npositional arguments:
a First file to compare
b Second file to compare
View Modes (mutually exclusive):
-s, --side Side-by-side view
-i, --inline Inline/compact view
--stats Show statistics only
Syntax Highlighting:
-l LANG, --lang LANG Language (auto-detected if not specified)
Supported: python, php, javascript, java,
cpp, go, rust, html, css, sql, json, etc.
Display Options:
-n, --line-numbers Show line numbers
-c N, --context N Number of context lines (default: 3)
Processing Options:
-w, --ignore-whitespace Ignore whitespace differences
--ignore-case Ignore case differences
--word-diff Word-level diff (side-by-side only)
Output Options:
--no-color Disable colored output
-q, --quiet Quiet mode (exit code only)
-h, --help Show help message
| Category | Languages |
|---|---|
| Web | HTML, CSS, SCSS, JavaScript, TypeScript, PHP |
| Systems | C, C++, Rust, Go |
| Application | Python, Java, C#, Ruby, Swift, Kotlin |
| Data | JSON, YAML, XML, SQL |
| Shell | Bash, Shell Script |
| Docs | Markdown |
Auto-detection works based on file extension
| Code | Meaning |
|---|---|
0 |
Files are identical |
1 |
Files differ |
2 |
Error reading files |
#!/bin/bash
if python diff_plus.py file1.txt file2.txt -q; then
echo "✓ Files match - deploying..."
./deploy.sh
else
echo "✗ Files differ - review needed"
exit 1
fipython diff_plus.py src/old_api.py src/new_api.py \
-s \ # Side-by-side view
-n \ # Show line numbers
-l python \ # Force Python syntax
--word-diff # Highlight word changespython diff_plus.py large_log_1.txt large_log_2.txt -c 0
# Shows only changed lines, no contextpython diff_plus.py Config.ini config.ini --ignore-case -w
# Ignores case and whitespace# Get similarity score for automation
python diff_plus.py old.js new.js --stats | grep Similarity# Compare multiple file pairs
for file in *.php; do
if [ -f "backup/$file" ]; then
echo "Checking $file..."
python diff_plus.py "backup/$file" "$file" -q || echo " ↳ Changed"
fi
done- Parser: Python
difflib.SequenceMatcher - Rendering: Rich library for terminal output
- Encoding: Multi-fallback (UTF-8, Latin-1, CP1252, ISO-8859-1)
- Memory: Line-by-line streaming
- Speed: Optimized for files up to 10MB
- Complexity: O(n*m) where n,m are file line counts
- 🟢 Green - Additions
- 🔴 Red - Deletions
- 🟡 Yellow - Modifications
- 🔵 Cyan - Headers/Metadata
- ⚪ Dim - Line numbers
Contributions are welcome! Here are some ideas:
- Add directory comparison mode
- Export to HTML/PDF
- Git integration
- Custom color themes
- Search within diff
- Bookmark changes
MIT License - feel free to use in your projects!
- Built with Rich - Amazing terminal formatting
- Inspired by classic
diff,git diff, and modern diff tools
Found a bug? Have a feature request?
- Open an issue
- Submit a pull request
- Share your use case!
Made with ❤️ for developers who love beautiful diffs
⭐ Star this repo if you find it useful!
