Command: Aliases from Config
loading alias commands from a config file
Define alias commands in config file
You can also define alias commands in config file, just like what git
cli app to do.
Sample cmdr-tests/examples/dyncmd-cfg
The example app dyncmd-cfg
in hedzr/cmdr-tests shows how to add alias commands.
The notable point is OnEvaluateSubCommandsFromConfigPath()
, which will load alias command from a special section in the config files.
If nothing specified, dottedPath app.alias
would be applied. This means section [alias]
in a config file will be read.
The feature is inspired from git
cli app and its [alias]
section inside $HOME/.gitconfig
.
Details
In alias
section, each key and value is mapped into a subcmd. The value string is the action of the subcmd, which is a shell script. The prefix of the value string has special purpose:
>
: redirect to another command, with dottedPath form.!
: invoke a gui app or a program. For example,"! say hello"
will play voice with texthello
(only worked for macOS);"! bash -c "ls /"
can invokels
in bash env.(no prefix)
: invoke a shell script within standard shell env.
Alias list for dyncmd-cfg
app
In the directory ./ci/etc/dyncmd-cfg
, there is the config files for dyncmd-cfg
, with standard layout. The [alias]
section is defined inside dyncmd-cfg.toml
.
The alias commands will be attached to jump
command.
Run
The result is,
It shows everything is okay.
Implements
The key method OnEvaluateSubCommandsFromConfig("alias")
is used for enabling alias commands.
额外的话题
How is this guide?
Last updated on