Skip to main content

A universal CLI tool to preview uncommitted code changes with rich syntax highlighting — before you commit them.

Project description

Code Preview

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.


Features

  • 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.

Example Output

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");
     }
 }
──────────────────────────────────────────────────────────────

Installation

From PyPI (Recommended)

You can install code-preview using pip:

pip install code-preview

From Source

If 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 .

Usage

Preview All Unstaged Changes

Simply run the command in the root of your Git repository:

code-preview

Preview Changes in a Specific Folder

You can limit the preview to a specific directory or file:

code-preview src/

Run Directly Without Installation

You can also run the tool directly as a Python module:

python -m code_preview.cli

How It Works

  1. Detects all files with uncommitted changes using GitPython.
  2. Reads their last committed version (HEAD).
  3. Compares against your local version using difflib.
  4. Renders the diff with syntax highlighting via Rich.

Roadmap

  • Auto-detect syntax for each file type (.java, .py, .js, etc.)
  • Add --html mode for browser-based diff preview
  • Add --watch mode for real-time change tracking
  • Support for non-Git directories (via snapshots)
  • VSCode/IntelliJ plugin integration

Development

Interested in contributing? Here's how to set up your environment.

Setup Virtual Environment

python3 -m venv venv
source venv/bin/activate

Install Dependencies

Install the project in "editable" mode:

pip install -e .

Run Locally

Run the tool using the development entry point:

python -m code_preview.cli

Project Structure

code-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

Publishing (For Maintainers)

  1. Build:

    python3 -m build
    
  2. Upload to TestPyPI:

    python3 -m twine upload --repository testpypi dist/*
    
  3. Test Install:

    pip install -i https://test.pypi.org/simple/ code-preview
    
  4. Publish to PyPI:

    python3 -m twine upload dist/*
    

Contributing

Contributions are welcome! If you find this project useful:


Acknowledgements

  • Rich for beautiful terminal rendering
  • GitPython for Git integration
  • Inspired by the need for more readable git diff previews for all developers

Author

Aryant Tripathi


License

This project is licensed under the Apache-2.0 License — see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

code_preview-1.0.0.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

code_preview-1.0.0-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file code_preview-1.0.0.tar.gz.

File metadata

  • Download URL: code_preview-1.0.0.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for code_preview-1.0.0.tar.gz
Algorithm Hash digest
SHA256 35898517fbcb1e1c15d1a33a18ef8da47540289a9b185101c5a718a3319f59b3
MD5 5c06662c006761f83ff94ea8def9ca2d
BLAKE2b-256 77bee032ddef98f9e64066755ea92bd97fcbca31501e53b0f4affa188840ebd3

See more details on using hashes here.

File details

Details for the file code_preview-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: code_preview-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for code_preview-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7f9ddce15e8cf7441149362c37d5280ea574ca4698b40d01fa131ed442161b9f
MD5 3f1d2e1291d4d531ed6d71d3af24408f
BLAKE2b-256 400f15fe8bdcc485a04460fc2a61b29604892008ef558738d4fc5e4cd0f9041d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page