🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis β†’
Socket
Book a DemoInstallSign in
Socket

code-preview

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

code-preview

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

pipPyPI
Version
1.0.0
Maintainers
1

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

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

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

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)

  • 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/*
    

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.

Keywords

git

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts