Custom commands can be of two kinds: external to cmsh or internal to cmsh.
external to cmsh
If the custom command is an executable from the main operating system shell (bash usually), you can just run it with a "!". For example, suppose there is a hypothetical bash script called "listusernamesfromexcel", which when it is run provides a daily listing of new users to be added to the cluster. The script could handily be accessed in cmsh with an "!" prefix:
The "!" runs the command it prefixes in a subshell. ("!" on its own opens up the subshell).
Of course, the script, if used frequently, may be aliased in bash (or .bashrc or .bash_profile for permanence) to something shorter for convenience, such as "lunfe", in which case the command is reduced to:
internal to cmsh
- If the "!" character is inconvenient too, the (external) script can be aliased in cmsh.
The current way to do this is to create a file called <command>.cmsh as:
and with the contents of <command>.cmsh being the command.
So in this example, creating a file lunfe.cmsh with !lunfe as its content, then restarting cmsh makes it possible to run the command lunfe without using '!'. That is, as:
- The alias command in cmsh currently works only with cmsh commands, ie it does not work with the ! character which would access the subshell. Within the restrictions of using cmsh commands only, an alias such as the following can be set:
bright52->user]% alias dum device use master
It can be made permanent by adding it to ~/.cm/cmsh/.cmshrc.
The .cmshrc dotfiles can be in these paths, with priority order as follows (ie: shortest path first):
The <command>.cmsh files have corresponding priorities.
If you find yourself looking into doing more extreme stuff, hold on a moment before bruteforcing cmsh into going that way. cmsh is a fine tool, but it isn't a scripting language. It's just a front end for CMDaemon. Expect scripts can get you further with making cmsh do what you want to in a batch mode, but the result is generally not going to be pretty.
Fortunately, there are Python API bindings for CMDaemon. Have a look at those. The manual covers them in an appendix, and probably that will suit your needs.