Skip to main content

A tool for simplifying repeated command line tasks

Project description

Magic icon Magic

Repository GitHub issues Pipeline status PyPI License Created at Nitor

Magic is a tool for turning repeated command line tasks and long, hard to remember commands into quickly callable simple commands, spells.

Spells provide a simple and managed alternative to manually created aliases or scripts.

🏃 Quick tour

  1. To add spells, run the built-in wizard magic add
  2. Spells are written into the spellbook file (~/.spellbook.json)
  3. Each spell is available as a command under magic, which can be listed with magic --help
  4. A spell can have one or several command names, which are called magic words
    e.g. magic build-app and magic ba
  5. Spells can have arguments passed to them
    e.g. magic say abra kadabra

💻 Installation

Magic is designed for macOS and common Linux distributions using Bash or Zsh. Magic also works on Windows Subsystem for Linux.

Magic requires Python 3.7 or above, and can be installed using pip:

python3 -m pip install tatuarvela-magic

🪄 Usage

$ magic
✨ Magic v3.1.2 © 2021 Tatu Arvela
A tool for simplifying repeated command line tasks

Usage: magic [OPTIONS] COMMAND [ARGS]...

Options:
  -h, --help  Show this message and exit.

Commands:
  add      Add spell to spellbook
  e        Example echo spell with arguments '$a0' and '$a1'
  edit     Open spellbook in editor
  example  Example echo spell with arguments '$a0' and '$a1'

Editing the spellbook is currently done with an external editor (Visual Studio Code by default).

📚 Documentation

Spell options

Spell options can be listed with the -h or --help option.

$ magic example --help
Usage: magic example [OPTIONS]

  Example echo spell with arguments '$a0' and '$a1'

Options:
  -d, --delete  Delete this spell.
  -s, --show    Show details of this spell.
  -h, --help    Show this message and exit.

-d or --delete option can be used to delete a spell.

-s or --show option can be used to show the details of a spell.

Other options are interpreted as arguments for spells.

Spell arguments

Spells can have an array of arguments, which are populated according to their index, starting from 0.

Example:

{
  "description": "Example echo spell with arguments '$a0' and '$a1'",
  "magicWords": [
    "e",
    "example"
  ],
  "commands": [
    "echo $a0",
    "echo $a1"
  ],
  "argumentCount": 2
}
$ magic example cat dog
✨ Example echo spell with arguments 'cat' and 'dog'
cat
dog
✅ 12:30:43 | ⏱ 0:00:00

The arguments can be used in the spell description and commands.

The description arguments are replaced when displaying the spell message.

argumentCount property is automatically inferred from the description and commands.

Excessive usage of arguments is considered to be an anti-pattern, it is recommended to create separate spells instead.

Advanced usage: Empty arguments

Argument are handled as an ordered array. If necessary, it is possible to make an argument an empty string: ''.

Messages

Message

Magic can print the description of a spell, filled with the provided arguments

✨ Example echo spell with arguments 'cat' and 'dog'

showMessage property defaults to true.

Success message

Magic can show a success message which reports the starting time and duration of a spell. This may be useful for longer operations.

✅ 23:46:43 | ⏱ 0:00:00

showSuccessMessage property defaults to true.

⚙️ Development

Development instructions and notes can be found in DEVELOPMENT.md

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

tatuarvela-magic-3.1.2.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

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

tatuarvela_magic-3.1.2-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file tatuarvela-magic-3.1.2.tar.gz.

File metadata

  • Download URL: tatuarvela-magic-3.1.2.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.9.9 Linux/5.11.0-1025-azure

File hashes

Hashes for tatuarvela-magic-3.1.2.tar.gz
Algorithm Hash digest
SHA256 9b837d77ca65553d0b0864fe640d8cbc4f9130ad2d231784262963b19ef1c8eb
MD5 bb4f7f908bfdfa2dd8a915d240cb1a75
BLAKE2b-256 19f15b96c0e4dadacdd321aafc3b487d6c4f6a5bc00676b2ffc66bc8100a8c52

See more details on using hashes here.

File details

Details for the file tatuarvela_magic-3.1.2-py3-none-any.whl.

File metadata

  • Download URL: tatuarvela_magic-3.1.2-py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.9.9 Linux/5.11.0-1025-azure

File hashes

Hashes for tatuarvela_magic-3.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 20ebc68d57cbcccb141355cfbd745e375fbcc7ae84c0b32abd5c1033e96a7c6b
MD5 a47e7b805f8d750e49664352a67d1341
BLAKE2b-256 b8350d32d678a8c9111431a5001a57d450ac95b4476877921aaebf831e9d0f88

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