Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions book/aliases.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ alias ll = ls -l
# some other config and script loading
```

## Piping in Aliases
## Piping / Multiple commands in Aliases

Note that `alias uuidgen = uuidgen | tr A-F a-f` (to make uuidgen on mac behave like linux) won't work.
Note aliases currently do not support including multiple commands. So for example `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 `^`.

```nu
Expand All @@ -60,6 +60,30 @@ def lsg [] { ls | sort-by type name -i | grid -c | str trim }

displaying all listed files and folders in a grid.

Similarly trying to chain multiple commands also will not work. In this example the aim is have `make_calls` print both "call1" and "call2".

```nu
alias make_calls = print call1; print call2

#output:
#call2
```

It output "call2" right away because the ";" ended the alias command instead of being included in it. If we try testing the alias we only get "call1" output as seen below:

```nu
make_calls

#output:
#call1
```

To implement the desired functionality a custom command would again be needed.

```nu
def make_calls [] { print call1; print call2 }
```

## Replacing Existing Commands Using Aliases

::: warning Caution!
Expand Down