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 wrapping repeated command line tasks into simple scripts.

  • A set of commands is saved as a spell
  • Spells are written into the spellbook file (~/.spellbook.json)
  • Each spell can be called with one or several magic words
    e.g. magic build-app and magic ba
  • Spells can have arguments passed to them
    e.g. magic say abra kadabra
  • The execution time of spells is reported by default

Installation

Magic is designed for macOS and common Linux distributions using Bash or Zsh. Windows is not supported.

Magic requires Python 3.9, and can be installed using pip:

python3 -m pip install tatuarvela-magic

See also: Development installation

Usage

$ magic --help
✨ Magic v3.0.0, © 2021 Tatu Arvela
A tool for simplifying repeated command line tasks

Usage:
    magic [-s | --show] <spell> [<args>...]
    magic [-d | --delete] <spell>
    magic -a | --add
    magic -e | --edit
    magic -l | --list
    magic -h | --help
    magic -v | --version

Options:
    -s --show       show spell details
    -d --delete     delete spell from spellbook
    -a --add        add spell to spellbook
    -e --edit       edit spellbook
    -l --list       list spells in spellbook
    -h --help       show help
    -v --version    show version

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

Spell arguments

Spells can have an array of arguments, which are populated according to their index. Excessive usage is considered an anti-pattern.

Example:

{
  "description": "Test echo spell with arguments '$a0' and '$a1'",
  "magicWords": [
    "t",
    "test"
  ],
  "commands": [
    "echo $a0",
    "echo $a1"
  ],
  "argumentCount": 2
}
$ magic test cat dog
✨ Test echo spell with arguments 'cat' and 'dog'
cat
dog
✅ 23:46:43 | ⏱ 0:00:00

Advanced usage: Empty arguments

Argument are handled as an array, so arguments can not be empty. As a work-around they may be substituted with an empty string: ''.

Advanced usage: Spell options

It is possible to provide options (--option) as arguments to spells. This is not intended usage, but may be useful to some. This requires a little work-around, as docopt stops the execution if it detects unknown options. You can provide the options your spell requires by adding a space and quotes ' --option'.

Development

Development installation

  • Supported operating systems: macOS (untested on Linux)
  • Requirements: Python 3, Poetry
  1. Clone the Git repository somewhere and navigate to it on the command line

    git clone https://github.com/TatuArvela/Magic.git
    cd Magic
    
  2. Install magic and its dependencies to a virtual env

    poetry install
    
  3. Verify that magic works

    poetry run magic
    
  4. Register magic to your PATH

    python -m write_path
    

When developing the tool, you should use the magic module directly with python -m magic.

After successful changes, you need to run poetry install again to update the version in your PATH.

Code quality tools

Magic uses isort, black and flake8 as its code quality tools. They are executed automatically with pre-commit and can also be executed with the included lint script:

python -m lint

TODO

For 3.X.X releases

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.0.0.tar.gz (10.8 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.0.0-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tatuarvela-magic-3.0.0.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.6 CPython/3.9.4 Linux/5.4.0-1046-azure

File hashes

Hashes for tatuarvela-magic-3.0.0.tar.gz
Algorithm Hash digest
SHA256 434013283d9cc961036acfcec9c2ec62aa542a785dc0814c46d341553da65913
MD5 640764fd0b575943930d7bc8059bcc34
BLAKE2b-256 15f0968ece19e21390744964bf9367a3d71a7b74f825aa5821c4df1bfaf4da20

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tatuarvela_magic-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.6 CPython/3.9.4 Linux/5.4.0-1046-azure

File hashes

Hashes for tatuarvela_magic-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ca0cb788e3c9987c963a7237c6821043a54289e7194fed85b7e660210b5e68d1
MD5 07c68bc43c5ac609979dcf1cc6d855de
BLAKE2b-256 0a6a9060a9699883006a34fd1f1abcb52c785b1d1808bbdf7faa2a3688ba532f

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