Skip to main content

Tool for managing custom commands from a central location

Project description

DISCLAIMER (WORK IN PROGRESS): As of May 2020 this project is work in progress. The alpha release is planned for June.

It IS designed to

  • make a clear overview of custom-made commands
  • provide a common user interface for the commands
  • provide a clear way to setup commands which work well with this tool

It IS NOT designed to

  • provide standard functions or libraries to be used in the custom-made commands
  • check correctness or analyse the commands

TODOs

  • refine the structure of modules
  • fix over-escaping, e.g. in 'proot' test command
  • improve search (not only one whole regex)
  • help for arguments
  • completion for arguments
  • think of possible project configuration variables
  • fix optional parameter load order
  • release to pypi and get it tested by somebody else
  • (seems hard) copy the command into command line instead of executing it

Installation

For stable release, run

pip3 install shcmdmgr

Basic usage

Use cmd -s (or cmd --save) to catalogue a command. For example lsb_release -a.

$ lsb_release -a
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04 LTS
Release:	20.04
Codename:	focal

$ cmd --save
The command to be saved: lsb_release -a   % note that this was pre-filled from history
Alias: sysversion
Short description: Shows the system version

Run the command either by invoking the alias

$ cmd sysversion
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04 LTS
Release:	20.04
Codename:	focal

or use search cmd -f (or cmd --find) to find and run the command.

$ cmd --find
========================================
query $ system                            % items matching the regex are displayed
--- 1 ------------------------------
cmd: do-release-upgrade
des: Upgrades the system to the newest released version
--- 2 ------------------------------
cmd: lsb_release -a
des: Shows the system version
========================================
query $ 2                                 % choose the command by entering its number
run command: lsb_release -a
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04 LTS
Release:	20.04
Codename:	focal

To edit the command catalogue run cmd --edit (or cmd -e) which runs $EDITOR ./<script_location>/commands.json command or open and edit the catalogue file manually.

$ cmd --edit
% The "$EDITOR" opens the content similar to the following
[
    {
        "command": "lsb_release -a",
        "description": "Show the version number of the system",
        "alias": "sysversion",
        "creation_time": "2020-04-11 00:24:27"
    },
    {
        "command": "do-release-upgrade",
        "description": "Upgrades the system to the newest released version",
        "alias": "sysupgrade",
        "creation_time": "2020-04-11 00:25:08"
    }
]

Completion

Completion is supported in bash and zsh shells, and must be enabled explicitly. Installing the completion is the matter of adding file-source to the RC file.

The correct command can be emited by invoking --completion <shell> command. So you can use the following for bash or zsh respectively.

cmd --completion bash >> ~/.bashrc
cmd --completion zsh >> ~/.zshrc

Advanced (work in progress)

Installation

To get the latest (non-stable) development version run the following.

pip3 install git+https://github.com/vaclavblazej/shell-command-manager.git

For development setup you may fork the repository, clone it, and create a symlink.

git clone git@github.com:vaclavblazej/shell-command-manager.git
ln -s "$PWD/shell-command-manager/bin/cmd.sh" ~/bin/cmd

Parts

We manage custom scripts, their help, and completion.

  • execution
  • help
  • completion

One function for all three because they have too much in common. Flags used to determine what we want to return.

All three variants are delegated lower (into arguments) and in the lowest level, we return (or do) the wanted result. In execution, we perform the task. In help and completion, we set the result into the relevant location.

Execution

The custom script should be an executable file.

Help

Help is invoked by calling script --help <arguments> where arguments are in the precise form as they would have been without the --help argument. It prints a string to standard output which describes what our current command does, and if there are any expected arguments.

Completion

Completion is invoked by calling script --complete <arguments> and prints out the list of words which are sensible arguments in the next places. The last argument is considered as argument prefix and is used to filter out possible words. If no filtering is wanted, the last argument should be empty-string.

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

shcmdmgr-0.1.1.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

shcmdmgr-0.1.1-py3-none-any.whl (28.5 kB view details)

Uploaded Python 3

File details

Details for the file shcmdmgr-0.1.1.tar.gz.

File metadata

  • Download URL: shcmdmgr-0.1.1.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

File hashes

Hashes for shcmdmgr-0.1.1.tar.gz
Algorithm Hash digest
SHA256 23879366e1907f950a8c86b9f0caaba9f8f664309200194bdb8afc820a1c67a3
MD5 71db68c7d0becfc3a70eed050905dd52
BLAKE2b-256 55c4c0295d5aeb1d8eac5b4dd221c396fa39744c392507ed9dd28ac1d26165f5

See more details on using hashes here.

File details

Details for the file shcmdmgr-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: shcmdmgr-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 28.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

File hashes

Hashes for shcmdmgr-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d9915ac2cb03ea685c06a182d1e38f04a508b5db243504488d5449ecf80b706c
MD5 1f3d68669af14eff07210b4d6c6a2d23
BLAKE2b-256 25aef2a088b706a698778684ec05f11c70be654a656fc4d78462030b18db5e13

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page