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 LiteLLM and Instructor, supporting various models like OpenAI, Anthropic, and others.
  • โ˜๏ธ GitHub Gist Integration: Store and manage scripts in GitHub Gists for easy sharing and versioning.
  • ๐Ÿ”„ Simple Script Management: Run, update, edit, list, and delete your scripts with simple commands.
  • ๐Ÿ“ฆ Automatic Dependency Management: Script execution with uv handles dependencies automatically, based on PEP 723 metadata.
  • ๐Ÿš€ Interactive Mode: Refine generated scripts interactively before saving.
  • ๐Ÿ–‹๏ธ Built-in Code Editor: Edit scripts directly in your terminal with a Textual-based editor, featuring syntax highlighting and AI-powered editing capabilities.
  • ๐Ÿ”„ Cross-Device Synchronization: Automatically 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.
  • ๐Ÿ“ PEP 723 Metadata: Generated scripts include PEP 723 metadata for dependency and runtime information.
  • โœจ Enhanced Editing with AI: Edit existing scripts using natural language instructions, powered by AI.
  • ๐ŸŽ›๏ธ Configurable Models: Choose different AI models for script generation and editing.

Installation

Script Magic now uses uv for package management. Install uv first:

curl -LsSf https://astral.sh/uv/install.sh | sh

Then, install Script Magic:

pip install script-magic

Or, for the latest version directly from GitHub:

uv pip install git+https://github.com/yourusername/script-magic.git

Replace yourusername with the actual username.

Quick Install and Tool Install (Recommended)

# Clone the repository (Optional, but useful for development/contributing)
git clone https://github.com/yourusername/script-magic.git
cd script-magic

# Install with uv (ensures correct environment)
uv venv
uv pip install -e .

# Install as a tool using uv, forcing Python 3.13:
uv tool install --force --python 3.13 script-magic@latest

# Set up your environment variables
export OPENAI_API_KEY="your-openai-api-key" # Or your LiteLLM provider key
export MY_GITHUB_PAT="your-github-personal-access-token"

Important: The uv tool install command creates a separate, isolated environment for Script Magic. This helps avoid dependency conflicts. You must use uv run to execute scripts that have dependencies installed via PEP 723.

Usage

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 a timestamp."

Generate with interactive preview:

sm create fibonacci --preview "Generate a script to print the first 10 Fibonacci numbers."

Specify a different AI model:

sm create list-files --model "anthropic/claude-3-opus" "List files in a directory."

Running Scripts

Run a script that has been previously created:

sm run hello-world

Pass parameters to the script (Script Magic intelligently separates its own options from the script's arguments):

sm run hello-world --name="John"

Script Magic will automatically use uv run to execute the script in the correct environment, handling any dependencies.

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 runs the script in a new terminal window. This is useful for scripts with interactive elements or those producing visual output.

Listing Scripts

View all scripts in your inventory:

sm list

Show detailed information:

sm list --verbose

Pull the latest scripts from GitHub before listing:

sm list --pull

Push local changes to Github before listing:

sm list --push

Syncing Scripts

Push your local inventory and scripts to GitHub:

sm push

Pull the latest scripts and mapping from GitHub:

sm pull

Deleting Scripts

Remove a script:

sm delete script-name

Force deletion without confirmation:

sm delete script-name --force

Editing Scripts

Edit a script using the built-in Textual editor:

sm edit myscript

Use AI to modify the script during editing (Ctrl+P within the editor):

  1. Press Ctrl+P in the editor.
  2. Enter instructions like "Add a function to calculate the average."
  3. The AI will modify the script based on your instructions.

Specify a different model for AI-assisted editing:

sm edit myscript --model "anthropic/claude-3-opus"

GitHub Integration

Script Magic automatically handles GitHub synchronization:

  • First-time users: Creates a new private Gist to store your script inventory.
  • Existing users: Finds your existing script inventory Gists automatically.
  • Multiple devices: 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 Gist containing your mapping file.
  • ~/.sm/logs/: Log files for debugging.
  • ~/.sm/scripts/: Local copies of your scripts.

Structure

script-magic/
โ”œโ”€โ”€ src/
โ”‚   โ””โ”€โ”€ script_magic/
โ”‚       โ”œโ”€โ”€ __init__.py                # CLI entry point & command registration.
โ”‚       โ”œโ”€โ”€ ai_integration.py          # AI script generation and editing.
โ”‚       โ”œโ”€โ”€ create.py                  # `create` command implementation.
โ”‚       โ”œโ”€โ”€ delete.py                  # `delete` command implementation.
โ”‚       โ”œโ”€โ”€ edit.py                    # `edit` command implementation (Textual TUI).
โ”‚       โ”œโ”€โ”€ github_gist_finder.py      # Finds existing mapping Gists.
โ”‚       โ”œโ”€โ”€ github_integration.py      # GitHub Gist API interaction.
โ”‚       โ”œโ”€โ”€ list.py                    # `list` command implementation.
โ”‚       โ”œโ”€โ”€ logger.py                  # Logging setup.
โ”‚       โ”œโ”€โ”€ mapping_manager.py         # Manages the script mapping (local & GitHub).
โ”‚       โ”œโ”€โ”€ mapping_setup.py           # Initializes mapping with GitHub sync.
โ”‚       โ”œโ”€โ”€ pep723.py                  # PEP 723 metadata parsing and updating.
โ”‚       โ”œโ”€โ”€ rich_output.py             # Rich-based console output utilities.
โ”‚       โ””โ”€โ”€ run.py                     # `run` command implementation.
โ”œโ”€โ”€ README.md
โ””โ”€โ”€ ...

Environment Variables

  • OPENAI_API_KEY: Your OpenAI API key (or key for your chosen LiteLLM provider).
  • MY_GITHUB_PAT: GitHub Personal Access Token with gist scope.

Contributing

Contributions are welcome! Please 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:

uv 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.4.0.tar.gz (244.0 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.4.0-py3-none-any.whl (41.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for script_magic-1.4.0.tar.gz
Algorithm Hash digest
SHA256 ffe35282f6a5e4e35f0d30b90e8f057abcfc1e2ef0b0757b9f18664ef9cdea2c
MD5 1a2883021be5d86b09ae9932b42097f7
BLAKE2b-256 6dc046ef7e1fb4b3b934d916ccd43154239d26d931d4677bac005518def0a1ca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for script_magic-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 853ed7217f8aa335331e4ba76696dad04146d9c68ac04cf23b52b7c8892fb791
MD5 bec69486e56d97e6ead16dc6a6bf15d1
BLAKE2b-256 1b0144dc58f02a4b70457d4e46811398bbd58ccf4ef4ba695d7b7e915ce60e43

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