Skip to main content

A command-line alias substitution tool

Project description

AliasMate

AliasMate is a command-line tool that allows you to execute commands based on configuration files containing aliases. It simplifies complex commands by providing a readable and configurable way to use application aliases and arguments.

Features

  • Supports JSON and YAML configuration files.
  • Alias translation: You can define aliases for commands and their arguments in the config file.
  • Multiple arguments: Supports multiple arguments after the alias.
  • Combines application name, alias, and extra arguments into a single command.
  • Error handling: Exits with the external command's status code.

Installation

pip install aliasmate

or

git clone https://github.com/maslovw/aliasmate.git
cd aliasmate
pip install .

Usage

Configuration File

The configuration file can be in either JSON or YAML format. It defines the application to be executed and the aliases for the command arguments.

Here’s an example config.json file:

{
  "application": "mount",
  "alias": {
    "read only": "-o ro",
    "read write": "-o rw",
    "no execute": "-o noexec",
    "user mount": "-o user",
    "bind": "--bind",
    "verbose": "-v",
    "all": "-a",
    "remount": "-o remount",
    "loop": "-o loop"
  }
  "aliasmate": {
    "verbose": true
  }
}

Read more here Configuration File Format

Example Command

$ alias mountmate="aliasmate -c mount_aliases.json --"
$ sudo mountmate read only /dev/sdb1 /mnt/usb

This command will execute:

mount -o ro /dev/sdb1 /mnt/usb

It is possible to pass arguments to aliasmate with second -- group of arguments:

$ sudo mountmate read only /dev/sdb1 /mnt/usb -- --verbose
Command for execution:
mount -o ro /dev/sdb1 /mnt/usb

Another example

{
  "application": "tar",
  "alias": {
    "create": "-c",
    "extract": "-x",
    "gzip": "-z",
    "bzip2": "-j",
    "file": "-f",
    "verbose": "-v",
    "list": "-t",
    "xz": "-J"
  }
}
$ alias tarmate="aliasmate -c tar_aliases.json --"

$ tarmate create gzip file archive.tar.gz directory/
$ tarmate extract bzip2 verbose file archive.tar.bz2
$ tarmate list xz file 'archive.tar.xz'

Arguments

  • -c, --config <FILE>: Specifies the configuration file (JSON or YAML).
  • -s, --show-alias: print currently used configuration and resulting command, without execution
  • -v, --verbose: print resulting command and execute it
  • Additional arguments (after --) are passed directly to the application.
  • 2nd Additional arguments (after 2nd --) are passed directly to the aliasmate(append to first arguments).

Example Usage:

It is intended to use alias (or .bat for windows) for this tool

# create shell alias in .bashrc for example
alias mount="aliasmate -c ~/.config/aliasmate/mount.json --"

# call aliasmate with mount.json
mount myserver readwrite -t nfs
# this command will be translated into
# mount /media/myserver -o rw -t nfs

Shell completion

ZSH completion

add completion/aliasmate_completion.zsh to your .completion.zsh


Contributing

Contributions are welcome! Feel free to submit issues and pull requests to improve the tool.


Author

Developed by Slava Maslov.


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

aliasmate-0.1.5.tar.gz (17.7 kB view details)

Uploaded Source

Built Distribution

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

aliasmate-0.1.5-py3-none-any.whl (18.2 kB view details)

Uploaded Python 3

File details

Details for the file aliasmate-0.1.5.tar.gz.

File metadata

  • Download URL: aliasmate-0.1.5.tar.gz
  • Upload date:
  • Size: 17.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for aliasmate-0.1.5.tar.gz
Algorithm Hash digest
SHA256 4133e7f96bb585391042e623186411afd93932a10cd9665201ff5a8480b99806
MD5 40a59eea9dae4e7468373ae4278d55a9
BLAKE2b-256 f0ef277abe1ac624e9b29834121ea1ebc8067f94648098d075b1b61666dd4b4b

See more details on using hashes here.

File details

Details for the file aliasmate-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: aliasmate-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 18.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for aliasmate-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 b5fc594d62332fd988f1e54468e0e5ad2c6d0af2cf7fb7dc66c8636929aef8e5
MD5 05f81b907e534c788d7b7f68553fdae1
BLAKE2b-256 832e0a60602b5bc3644dc6fb3858320f9c53f64c866b82d534bd105275be77e8

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