A universal CLI tool to preview uncommitted code changes with rich syntax highlighting — before you commit them.
It works with any language and any Git repository.
Quickly visualize what your next commit will look like — right in your terminal.
- Colored Diff Preview: Additions (green), deletions (red), and context (gray).
- Language-Agnostic: Works for Java, Python, JavaScript, Scala, Go, etc.
- Rich Terminal Output: Powered by Textualize Rich.
- Git-Integrated: Shows all unstaged and staged file changes.
- No Commit Required: Safe to preview changes locally anytime.
- Extensible Design: Add plugins or render to HTML in the future.
Here is a preview of what changed in a Java file:
──────────────────────────────────────────────────────────────
a/src/main/java/com/example/App.java → b/src/main/java/com/example/App.java
@@ -14,6 +14,8 @@
public class App {
public static void main(String[] args) {
- System.out.println("Hello, world!");
+ System.out.println("Hello, Aryant!");
+ System.out.println("Code preview is working");
}
}
──────────────────────────────────────────────────────────────You can install code-preview using pip:
pip install code-previewIf you want to install it from your local folder for development:
git clone https://github.com/Aryant-Tripathi/code-preview.git
cd code-preview
pip install -e .Simply run the command in the root of your Git repository:
code-previewYou can limit the preview to a specific directory or file:
code-preview src/You can also run the tool directly as a Python module:
python -m code_preview.cli- Detects all files with uncommitted changes using GitPython.
- Reads their last committed version (HEAD).
- Compares against your local version using difflib.
- Renders the diff with syntax highlighting via Rich.
- Auto-detect syntax for each file type (
.java,.py,.js, etc.) - Add
--htmlmode for browser-based diff preview - Add
--watchmode for real-time change tracking - Support for non-Git directories (via snapshots)
- VSCode/IntelliJ plugin integration
Interested in contributing? Here's how to set up your environment.
python3 -m venv venv
source venv/bin/activateInstall the project in "editable" mode:
pip install -e .Run the tool using the development entry point:
python -m code_preview.clicode-preview/
├── src/
│ └── code_preview/
│ ├── __init__.py # Package initializer
│ ├── cli.py # Main CLI entry point (argparse)
│ ├── git_utils.py # Git interaction logic
│ ├── diff_renderer.py # Logic for rendering diffs with Rich
│ └── file_utils.py # File reading utilities
├── pyproject.toml # Build configuration (PEP 621)
├── setup.cfg # Package metadata
├── README.md
└── LICENSE
-
Build:
python3 -m build
-
Upload to TestPyPI:
python3 -m twine upload --repository testpypi dist/* -
Test Install:
pip install -i https://test.pypi.org/simple/ code-preview
-
Publish to PyPI:
python3 -m twine upload dist/*
Contributions are welcome! If you find this project useful:
- Star it on GitHub → Aryant-Tripathi/code-preview
- Open issues for feature requests or bugs
- Submit pull requests for enhancements
- Rich for beautiful terminal rendering
- GitPython for Git integration
- Inspired by the need for more readable
git diffpreviews for all developers
Aryant Tripathi
- Software Engineer | Open Source Contributor | DSA Mentor
- Email: aryanttripathi@gmail.com
- GitHub: @Aryant-Tripathi
- LinkedIn: in/aryant-tripathi
This project is licensed under the Apache-2.0 License — see the LICENSE file for details.