First pass at updating all documentation formatting and cleaning up output of examples (#2031)

This commit is contained in:
Joseph T. Lyons
2020-06-23 14:21:47 -04:00
committed by GitHub
parent d095cb91e4
commit 053bd926ec
81 changed files with 1069 additions and 679 deletions

View File

@@ -1,9 +1,11 @@
# alias
This command allows you to define shortcuts for other common commands. By default, they only apply to the current session. To persist them, add `--save`.
Syntax: `alias {flags} <name> [<parameters>] {<body>}`
The command expects three parameters:
* the name of alias
* the parameters as a space-separated list (`[a b ...]`), can be empty (`[]`)
* the body of the alias as a `{...}` block
@@ -15,6 +17,7 @@ The command expects three parameters:
## Examples
Define a custom `myecho` command as an alias:
```shell
> alias myecho [msg] { echo $msg }
> myecho "hello world"
@@ -22,6 +25,7 @@ hello world
```
Since the parameters are well defined, calling the command with the wrong number of parameters will fail properly:
```shell
> myecho hello world
error: myecho unexpected world
@@ -31,6 +35,7 @@ error: myecho unexpected world
```
The suggested help command works!
```shell
> myecho -h
@@ -47,22 +52,29 @@ flags:
## Persistent aliases
Aliases are most useful when they are persistent. For that, add them to your startup config:
```
```shell
> config --set [startup ["alias myecho [msg] { echo $msg }"]]
```
This is fine for the first alias, but since it overwrites the startup config, you need a different approach for additional aliases.
To add a 2nd alias:
```shell
> config --get startup | append "alias s [] { git status -sb }" | config --set_into startup
```
config --get startup | append "alias s [] { git status -sb }" | config --set_into startup
```
This first reads the `startup` config (a table of strings), then appends another alias, then sets the `startup` config with the output of the pipeline.
To make this process easier, you could define another alias:
```
```shell
> alias addalias [alias-string] { config --get startup | append $alias-string | config --set_into startup }
```
Then use that to add more aliases:
```
addalias "alias s [] { git status -sb }"
```shell
> addalias "alias s [] { git status -sb }"
```