Skip to main content

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.

Python 3.9+ License: MIT

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 uv handles 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 key
  • MY_GITHUB_PAT: GitHub Personal Access Token with Gist permissions

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

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

Acknowledgments

Development

To install development dependencies:

pip install -e '.[dev,syntax]'

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

script_magic-1.1.3.tar.gz (311.8 kB view details)

Uploaded Source

Built Distribution

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

script_magic-1.1.3-py3-none-any.whl (39.5 kB view details)

Uploaded Python 3

File details

Details for the file script_magic-1.1.3.tar.gz.

File metadata

  • Download URL: script_magic-1.1.3.tar.gz
  • Upload date:
  • Size: 311.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.14

File hashes

Hashes for script_magic-1.1.3.tar.gz
Algorithm Hash digest
SHA256 7a44d29e7f1c2c35f1eb773c62292cbaf9d6901ca01f412b9866b2b277146b33
MD5 4129dce252b57210231ae58eca17050c
BLAKE2b-256 c3f52e6a80fa6f58138bfb757df07266b756935db10b98e42284ed2563b0aaf1

See more details on using hashes here.

File details

Details for the file script_magic-1.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for script_magic-1.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4bcb6e7bfafa2116f80f931d7c4ec427d8bd36c513e3eed77004201c5509ee42
MD5 72765d002c413d002c38e0634ed3511a
BLAKE2b-256 fcd4b14b3108a5bdedb81304bcf4a5be57447ab3baee5668f47b2c8855723e2f

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