Command-line script utility toolkit that simplifies common scripting tasks with AI-powered script generation, GitHub Gist integration for cross-device synchronization, and automatic dependency management. Create, run, and manage scripts with natural language prompts.
Project description
Script Magic ๐ช
Command-line script utility toolkit that simplifies common scripting tasks.
Features
- ๐ค AI-Powered Script Generation: Create Python scripts from natural language prompts using OpenAI's GPT models
- โ๏ธ GitHub Gist Integration: Store and manage scripts in GitHub Gists for easy sharing and versioning
- ๐ Simple Script Management: Run, update, and manage your scripts with easy commands
- ๐ฆ Automatic Dependency Management: Script execution with
uvhandles dependencies automatically - ๐ Interactive Mode: Refine generated scripts interactively before saving
- ๐ Cross-Device Synchronization: Automatically find and sync your script inventory across devices using GitHub Gists
- ๐ Smart Gist Detection: Automatically finds your existing script mappings on GitHub
- ๐ Multi-Environment Support: Works seamlessly across different machines with the same GitHub account
- ๐๏ธ Syntax Highlighting: Built-in code editor with syntax highlighting (requires optional dependencies)
Installation
pip install script-magic
Prerequisites
- Python 3.9+
- uv for Python package management and script execution
- GitHub account with a Personal Access Token
- OpenAI API key
Quick Install
# Clone the repository
git clone https://github.com/yourusername/script-magic.git
cd script-magic
# Install with uv
uv venv
uv pip install -e .
# Set up your environment variables
export OPENAI_API_KEY="your-openai-api-key"
export MY_GITHUB_PAT="your-github-personal-access-token"
Optional Dependencies
For enhanced features such as syntax highlighting in the editor:
pip install 'script-magic[syntax]'
Usage
# Import the library
from script_magic import some_function
# Use the command-line tool
sm --help
Creating Scripts
Generate a new script from a natural language prompt:
sm create hello-world "Create a script that prints 'Hello, World!' with timestamp"
Generate with interactive preview:
sm create fibonacci --preview "Generate a script to print the first 10 Fibonacci numbers"
Running Scripts
Run a script that has been previously created:
sm run hello-world
Pass parameters to the script:
sm run hello-world --name="John"
Force refresh from GitHub before running:
sm run hello-world --refresh
Run a script in a new terminal window:
sm run visualize-data --in-terminal
The --in-terminal (-t) option will run the script in a new terminal window that remains open until closed by the user.
This is particularly useful for scripts with interactive elements or those that produce visual output.
Listing Scripts
View all scripts in your inventory:
sm list
Show detailed information about your scripts:
sm list --verbose
Pull the latest scripts from GitHub before listing:
sm list --pull
Push your local script inventory to GitHub while listing:
sm list --push
Syncing Scripts
Sync your local inventory to GitHub:
sm sync
Pull the latest mapping from GitHub:
sm pull
Deleting Scripts
Remove a script from both local inventory and GitHub Gists:
sm delete script-name
Force deletion without confirmation:
sm delete script-name --force
Editing Scripts
Edit a script with syntax highlighting (if dependencies are installed):
script-magic edit myscript
GitHub Integration
Script Magic automatically handles GitHub synchronization:
- First-time users: Script Magic creates a new private Gist to store your script inventory
- Existing users: Script Magic finds your existing script inventory Gists automatically
- Multiple devices: Script Magic detects existing mappings and asks which version to keep
Configuration
Script Magic stores configuration in the ~/.sm directory:
~/.sm/mapping.json: Maps script names to GitHub Gist IDs~/.sm/gist_id.txt: Stores the ID of the GitHub Gist containing your mapping file~/.sm/logs/: Log files for debugging
Structure
script-magic/
โโโ src/
โ โโโ script_magic/
โ โโโ __init__.py # CLI entry point with command registration
โ โโโ create.py # Script creation command
โ โโโ run.py # Script execution command
โ โโโ list.py # Script listing command
โ โโโ delete.py # Script deletion command
โ โโโ github_integration.py # GitHub Gist API integration
โ โโโ github_gist_finder.py # Finds existing mapping Gists
โ โโโ pydantic_ai_integration.py # AI script generation
โ โโโ mapping_manager.py # Script mapping management
โ โโโ mapping_setup.py # Initializes mapping with GitHub sync
โ โโโ logger.py # Logging configuration
โ โโโ rich_output.py # Terminal output formatting
Environment Variables
OPENAI_API_KEY: Your OpenAI API keyMY_GITHUB_PAT: GitHub Personal Access Token with Gist permissions
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- PydanticAI for AI integration
- Click for the CLI interface
- PyGitHub for GitHub API integration
- Rich for beautiful terminal output
Development
To install development dependencies:
pip install -e '.[dev,syntax]'
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file script_magic-1.1.0.tar.gz.
File metadata
- Download URL: script_magic-1.1.0.tar.gz
- Upload date:
- Size: 300.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
836d2eb67499d28327b6a0cb8d2dc11c4c0ff0682117a78196ca3e266e7e41d1
|
|
| MD5 |
ae64f1ec1932c8bdcbd5b411bc03f774
|
|
| BLAKE2b-256 |
73f4785de1c8b46460cfb4d053ad2d37e3d75a5d574f6bc2112fd6f00dd38a69
|
File details
Details for the file script_magic-1.1.0-py3-none-any.whl.
File metadata
- Download URL: script_magic-1.1.0-py3-none-any.whl
- Upload date:
- Size: 40.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b95f37ca5355c9dcc6c7293cf7daa3a3762bbc1aca531363ce429307030d5eb
|
|
| MD5 |
77f4324990a6bab2c7cae255c13260ce
|
|
| BLAKE2b-256 |
59fdea26ca3ad064ffa8ea1ef1a09b16223bd7b55137e765349ea4b1fe43e081
|