Script Runner is a command-line tool that helps you manage and run Python and shell scripts with their associated interpreters and virtual environments. It automatically detects script types, virtual environments for Python scripts, and allows you to create aliases for your scripts, making them easier to run from anywhere.
- Register Python and shell scripts with easy-to-remember aliases
- Automatic script type detection (Python vs shell) based on file extension and shebang
- Automatic virtual environment detection for Python scripts
- Support for various shell types (bash, zsh, sh, fish)
- Run scripts using their associated interpreter or virtual environment
- List all registered scripts with type information
- Remove scripts from the registry
- Prune non-existent scripts automatically
- Cross-platform support (Windows and Unix-like systems)
- Backward compatibility with existing Python-only configurations
pip install script_runner- Register a script:
# Python script
script_runner add path/to/your/script.py -a myscript
# Shell script
script_runner add path/to/your/script.sh -a myshell- Run the script using its alias:
script_runner run myscript [args...]
script_runner run myshell [args...]-
add: Register a Python or shell scriptscript_runner add PATH [-a ALIAS] [-i INTERPRETER_PATH]
PATH: Path to the Python or shell script-a, --alias: Custom alias for the script (defaults to script filename)-i, --interpreter: Specific interpreter to use (auto-detected if not specified)
-
run: Execute a registered scriptscript_runner run ALIAS [ARGS...]
ALIAS: The script's aliasARGS: Optional arguments to pass to the script
-
list: Display all registered scriptsscript_runner list
-
remove: Delete a script from the registryscript_runner remove ALIAS
-
prune: Remove all non-existent scripts from the registryscript_runner prune
Script Runner stores its configuration in ~/.config/script_runner/scripts.json. This file contains the mapping between aliases and their corresponding scripts, along with the Python executable path for each script.
Script Runner automatically detects whether a script is a Python script or a shell script using the following methods:
- File Extension:
.pyfiles are detected as Python,.sh,.bash,.zsh,.fishfiles are detected as shell scripts - Shebang Line: For files without extensions, the shebang line is analyzed:
#!/usr/bin/env python3,#!/usr/bin/python→ Python script#!/bin/bash,#!/usr/bin/env zsh→ Shell script
- Executable Files: Files that are executable but don't match the above patterns default to shell scripts
Script Runner automatically detects virtual environments by looking for pyvenv.cfg files in parent directories (up to 5 levels by default). It will use the Python executable from the nearest virtual environment found. If no virtual environment is detected, it will use the system Python that was used to install Script Runner.
- Python 3.8 or higher
- Click 8.0 or higher
The tool can be invoked using either script_runner or the shorter alias sr:
sr add script.py
sr run myscriptTo set up the development environment:
- Clone the repository
- Create a virtual environment
- Install development dependencies
- Run tests with pytest
The project uses pytest for testing. Test files are available in the project root and cover core functionality like virtual environment detection and script registration.
This project is licensed under the MIT License. This means you can:
- Use it commercially
- Modify it
- Distribute it
- Use it privately
- Use it for any purpose
No warranties are provided and the author is not liable for any issues.
This is a personal utility project with minimal maintenance. While you're welcome to:
- Fork the repository
- Use it as you see fit
- Create your own version
Please note that I may not actively review pull requests or issues. Feel free to fork and modify the project to suit your needs.