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 © 2022 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.3.tar.gz (11.3 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.3-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tatuarvela-magic-3.1.3.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.9.10 Linux/5.11.0-1028-azure

File hashes

Hashes for tatuarvela-magic-3.1.3.tar.gz
Algorithm Hash digest
SHA256 91ce00c73d88b48f7951f6843f16b459519698d49dd743451a9c995feaa22f61
MD5 c439c2a13ee140d7152081d9ecfce22e
BLAKE2b-256 01b0ff6855ab34ba53d4ccb593ad96ee08a65c5141949f52724d2ee9f2dccf30

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for tatuarvela_magic-3.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b97881cb7b2307c5a9fdfe5187e586650ee0104a7cba36a2872c92fba8c42ad8
MD5 d2c50826f14529e6b2b486ae13053994
BLAKE2b-256 69e332ac59c479c22c54171948e80b754f6e6084a38b3b0178c3803f432d17dc

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