nushell/docs/commands/alias.md
Jörn Zaefferer 4ef15b5f80
docs/alias: simplify the 'persistent' section, using --save (#2285)
All the workarounds using `config` aren't necessary anymore. Only `config path` is still of interest.
2020-08-01 08:11:26 -04:00

1.5 KiB

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 the alias
  • The parameters as a space-separated list ([a b ...]), can be empty ([])
  • The body of the alias as a {...} block

Flags

  • -s, --save: Save the alias to your config (see config path to edit them later)

Examples

Define a custom myecho command as an alias:

> alias myecho [msg] { echo $msg }
> myecho "hello world"
hello world

Since the parameters are well defined, calling the command with the wrong number of parameters will fail properly:

> myecho hello world
error: myecho unexpected world
- shell:1:18
1 | myecho hello world
  |              ^^^^^ unexpected argument (try myecho -h)

The suggested help command works!

> myecho -h

Usage:
  > myecho ($msg) {flags}

parameters:
  ($msg)

flags:
  -h, --help: Display this help message

Persistent aliases

Aliases are most useful when they are persistent. For that, use the --save flag:

> alias --save myecho [msg] { echo $msg }

This will store the alias in your config, under the startup key. To edit the saved alias, run it again with the same name, or edit your config file directly. You can find the location of the file using config path.

For example, to edit your config file in vi, run:

> vi $(config path)