A less verbose system for defining reusable parameterized commands than shell functions, yet more powerful than shell aliases.
- Commands that support parameterization unlike traditional shell aliases
- Automatic help text to echo the expected or missing parameter names. One must manually design this behavior into traditional shell functions.
-
Theoretically slower than leveraging the native shell aliases/functions; a separate process is spawned for each stackable call.
The difference, however, is not to be perceived: the solution is built in shell, which leverages fast C routines and system calls.
-
Configuration file (optional)
The only parameters relevant to the executable are:
DEBUG=false PARAM_CHAR='!!' SELF_REF='%self%'PARAM_CHAR is the parameter prefix.
SELF_REF is the prefix that precedes any internally defined command invocation.
To change these values, paste the above lines in a config file, either
$HOME/.exec-cmd.rcor one defined by the$EXEC_CMD_CFGenvironment variable. -
The commands
exec-cmdreads all definitions from either$HOME/commandsor$EXEC_CMD_DIR/commandsif you've defined the$EXEC_CMD_DIRenvironment variable.The same applies to the
commands_helpoptional help text. -
Place
exec-cmdwithin your environment path.
See the example commands file for sample usage. This is the most straightforward way to get accustomed to the syntax.
Each command is defined as follows:
<name>[,<alias1>,<alias2>,...] <command>
Make sure not to leave any space between the command names and the optional comma-separated aliases.
A command may include parameters, these prefixed with '!!' by default.
As you invoke a command, exec-cmd checks for all included parameters and outputs a message with any missing ones and their names.
To call an existing command/alias, include the tag %self% (reconfigurable in $SELF_REF) followed by the existing command/alias name.
Define your own optional command help text in commands_help. See the default file for examples.
To execute a command, simply provide a command to the executable along with the required parameters:
$ exec-cmd test 1 2 3
param1: 1, param2: 2, param3: 3
Execute with -h to view the other available options, or -h <command> to reference the defined help text.
To ease the command line entry, you may configure the simple one-word shell autocompletion for your defined commands.
Assuming you've placed the executable within your path, include the following in your ~/.bashrc: or similar:
if [ -f ~/bin/exec-cmd ]; then
ec_opts=$(exec-cmd -c)
complete -W "$ec_opts" exec-cmd ec
fi