Aliases
Aliases in rsh offer a way of doing a simple replacement of command calls (both external and internal commands). This allows you to create a shorthand name for a longer command, including its default arguments.
For example, let's create an alias called
ll
which will expand to ls -l
.
> alias ll = ls -l
We can now call this alias:
> ll
Once we do, it's as if we typed ls -l
. This
also allows us to pass in flags or positional parameters. For
example, we can now also write:
> ll -a
And get the equivalent to having typed ls -l -a
.
List all loaded aliases
Your useable aliases can be seen in
scope aliases
and help aliases
.
Persisting
To make your aliases persistent they must be added to your
config.rsh file by running config rsh
to
open an editor and inserting them, and then restarting rsh. e.g.
with the above ll
alias, you can add
alias ll = ls -l
anywhere in config.rsh
$env.config = {
# main configuration
}
alias ll = ls -l
# some other config and script loading
Piping in aliases
Note that alias uuidgen = uuidgen | tr A-F a-f
(to
make uuidgen on mac behave like linux) won't work. The
solution is to define a command without parameters that calls
the system program uuidgen
via ^
.
def uuidgen [] { ^uuidgen | tr A-F a-f }
See more in the custom commands section of this book.
Or a more idiomatic example with rsh internal commands
def lsg [] { ls | sort-by type name -i | grid -c | str trim }
displaying all listed files and folders in a grid.