Skip to main content

Terminal Extensions

A lightweight Python library for extending your terminal environment with custom hooks. This library allows you to easily add custom functionality to your terminal by writing simple Python functions.

Features

  • Simple decorator-based API for registering hooks
  • Support for both prefix-specific and global hooks
  • Automatic loading of hooks from a .hooks directory
  • Minimal overhead and easy integration

Installation

pip install terminal-extensions

Quick Start

  1. Create a .hooks directory in your project
  2. Add Python files with your hooks:
from terminal_extensions import terminal_hook

# Hook that runs for all commands
@terminal_hook()
def log_commands(command: str) -> bool:
    print(f"Executing: {command}")
    return True  # Continue processing other hooks

# Hook that only runs for commands starting with "git"
@terminal_hook("git")
def git_helper(command: str) -> bool:
    if command == "git status":
        print("Nice job checking in!")
    return True
  1. Run the terminal extensions:
terminal-ext

Writing Hooks

Hook Types

  1. Global Hooks - Run for every command:
@terminal_hook()
def my_hook(command: str) -> bool:
    # Process any command
    return True
  1. Prefix Hooks - Run only for commands with specific prefixes:
@terminal_hook("docker")
def docker_hook(command: str) -> bool:
    # Process only docker commands
    return True

Hook Return Values

  • Return True to continue processing other hooks and execute the command
  • Return False to stop processing and prevent command execution

Hook Organization

Place your hooks in .py files within the .hooks directory:

your_project/
├── .hooks/
│   ├── git_hooks.py
│   ├── docker_hooks.py
│   └── general_hooks.py
└── ...

Examples

Command Logging

@terminal_hook()
def log_commands(command: str) -> bool:
    with open("command_history.log", "a") as f:
        f.write(f"{command}\n")
    return True

Security Check

@terminal_hook("rm")
def confirm_delete(command: str) -> bool:
    response = input("Are you sure you want to delete? [y/N] ")
    return response.lower() == 'y'

Command Enhancement

@terminal_hook("git")
def git_shortcuts(command: str) -> bool:
    if command == "git st":
        print("Expanding to git status...")
        return "git status"
    return True

Configuration

The library automatically looks for hooks in the .hooks directory of your current working directory.

Error Handling

Hooks are executed in a safe environment. If a hook raises an exception:

  • The error is logged to stderr
  • Processing continues with the next hook
  • The original command is still executed (unless explicitly prevented)

Contributing

See CONTRIBUTORS.md for guidelines on contributing to this project.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Metadata

Release files for terminal-extensions 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for terminal-extensions 0.1.0
File Size Uploaded Provenance Actions
terminal_extensions-0.1.0.tar.gz 4.3 kB Without provenance Details for terminal_extensions-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for terminal-extensions 0.1.0
File Interpreter ABI Platform Actions
terminal_extensions-0.1.0-py3-none-any.whl Python 3 none any Details for terminal_extensions-0.1.0-py3-none-any.whl

Total release size: 9.1 kB

Release files / terminal_extensions-0.1.0.tar.gz

Download URL terminal_extensions-0.1.0.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
3732c8d4e89d98accb4cd4fb0d9c225ce03eefab3080f8ff467b700d75cfce0f
BLAKE2b-256 checksum
How to use checksums
946e7fa2e7bf8a227ee2340899fad56a916fd206b5113d3faa7dab8ad7ba05d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release files / terminal_extensions-0.1.0-py3-none-any.whl

Download URL terminal_extensions-0.1.0-py3-none-any.whl
Size 4.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3a852e9a2dc6a4d362b9df92330bd32f01a5677f857d26dc145cc92943c5e7f4
BLAKE2b-256 checksum
How to use checksums
ac1514d20083ad41c45a5871b752fc4b9f00eb3bfffdbd5023e60661f8d4a990
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Security for terminal-extensions 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page