Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add real Nushell syntax highlighting support #1078

Merged
merged 9 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
chore: Update docs
  • Loading branch information
hustcer committed Oct 2, 2023
commit 468ceef456d82a7f8ef136150da9bb385d40947e
2 changes: 1 addition & 1 deletion book/3rdpartyprompts.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ $env.PROMPT_INDICATOR = $"(ansi y)$> (ansi reset)"

Here's an example config section for Starship:

```
```nu
$env.STARSHIP_SHELL = "nu"

def create_left_prompt [] {
Expand Down
12 changes: 6 additions & 6 deletions book/aliases.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ Aliases in Nushell offer a way of doing a simple replacement of command calls (b

For example, let's create an alias called `ll` which will expand to `ls -l`.

```
```nu
> alias ll = ls -l
```

We can now call this alias:

```
```nu
> 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:

```
```nu
> ll -a
```

Expand All @@ -31,7 +31,7 @@ Your useable aliases can be seen in `scope aliases` and `help aliases`.
To make your aliases persistent they must be added to your _config.nu_ file by running `config nu` to open an editor and inserting them, and then restarting nushell.
e.g. with the above `ll` alias, you can add `alias ll = ls -l` anywhere in _config.nu_

```nushell
```nu
$env.config = {
# main configuration
}
Expand All @@ -46,15 +46,15 @@ alias ll = ls -l
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 `^`.

```
```nu
def uuidgen [] { ^uuidgen | tr A-F a-f }
```

See more in the [custom commands](custom_commands.md) section of this book.

Or a more idiomatic example with nushell internal commands

```
```nu
def lsg [] { ls | sort-by type name -i | grid -c | str trim }
```

Expand Down
2 changes: 1 addition & 1 deletion book/coloring_and_theming.md
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ If you don't like the default `PROMPT_INDICATOR` you could change it like this.

If you're using `starship`, you'll most likely want to show the right prompt on the last line of the prompt, just like zsh or fish. You could modify the `config.nu` file, just set `render_right_prompt_on_last_line` to true:

```
```nu
config {
render_right_prompt_on_last_line = true
...
Expand Down
6 changes: 3 additions & 3 deletions book/command_signature.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

nu commands contain a signature section, take [`str distance`](/commands/docs/str_distance.md) as example, the signature is like this:

```
```nu
Signatures(Cell paths are supported):
<string> | str distance <string> -> <int>
```

The first type name before `|` describes the type of input pipeline. The command name is followed by the required argument type(s) for the command. The output type is `int` and given after `->`.

`(Cell paths are supported)` indicates that you can provide cell paths for `str distance` to apply an operation at the given cell path(s) in a nested structure or table, and replace the column or field with the result, like: `ls | str distance 'nushell' 'name'`

Here is another one example, [`str join`](/commands/docs/str_join.md):

```
```nu
Signatures:
list<string> | str join <string?> -> <string>
```
Expand Down
16 changes: 8 additions & 8 deletions book/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Nushell uses a configuration system that loads and runs two Nushell script files

You can check where Nushell is reading these config files from by calling `$nu.env-path` and `$nu.config-path`.

```
```nu
> $nu.env-path
/Users/FirstNameLastName/Library/Application Support/nushell/env.nu
```
Expand All @@ -24,15 +24,15 @@ You can browse the default files for default values of environment variables and

Nushell's main settings are kept in the `config` environment variable as a record. This record can be created using:

```
```nu
$env.config = {
...
}
```

You can also shadow `$env.config` and update it:

```
```nu
$env.config = ($env.config | upsert <field name> <field value>)
```

Expand All @@ -42,7 +42,7 @@ By convention, this variable is defined in the `config.nu` file.

You can set environment variables for the duration of a Nushell session using the `$env.<var> = <val>` structure inside the `env.nu` file. For example:

```
```nu
$env.FOO = 'BAR'
```

Expand Down Expand Up @@ -96,7 +96,7 @@ This will print out `$env.<var> = <val>` lines, one for each environment variabl

Next, on some distros you'll also need to ensure Nu is in the /etc/shells list:

```
```sh
> cat /etc/shells
# /etc/shells: valid login shells
/bin/sh
Expand Down Expand Up @@ -124,7 +124,7 @@ Some tools (e.g. Emacs) rely on an [`open`](/commands/docs/open.md) command to o
As Nushell has its own [`open`](/commands/docs/open.md) command which has different semantics and shadows `/usr/bin/open`, these tools will error out when trying to use it.
One way to work around this is to define a custom command for Nushell's [`open`](/commands/docs/open.md) and create an alias for the system's [`open`](/commands/docs/open.md) in your `config.nu` file like this:

```
```nu
def nuopen [arg, --raw (-r)] { if $raw { open -r $arg } else { open $arg } }
alias open = ^open
```
Expand All @@ -136,7 +136,7 @@ For more about escape and `^` see the [chapter about escapes](escaping.md).

In Nushell, [the PATH environment variable](<https://en.wikipedia.org/wiki/PATH_(variable)>) (Path on Windows) is a list of paths. To append a new path to it, you can use `$env.<var> = <val>` and [`append`](/commands/docs/append.html) in `env.nu`:

```
```nu
$env.PATH = ($env.PATH | split row (char esep) | append '/some/path')
```

Expand All @@ -148,7 +148,7 @@ Note the `split row (char esep)` step. We need to add it because in `env.nu`, th

[Homebrew](https://brew.sh/) is a popular package manager that often requires PATH configuration. To add it to your Nushell PATH:

```
```nu
# macOS ARM64 (Apple Silicon)
$env.PATH = ($env.PATH | split row (char esep) | prepend '/opt/homebrew/bin')

Expand Down
8 changes: 4 additions & 4 deletions book/creating_errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ You can use the [`error make`](/commands/docs/error_make.md) command to create y

First, you can take the span of where the argument is coming from:

```
```nu
let span = (metadata $x).span;
```

Next, you can create an error using the [`error make`](/commands/docs/error_make.md) command. This command takes in a record that describes the error to create:

```
```nu
error make {msg: "this is fishy", label: {text: "fish right here", start: $span.start, end: $span.end } }
```

Together with your custom command, it might look like this:

```
```nu
def my-command [x] {
let span = (metadata $x).span;
error make {
Expand All @@ -37,7 +37,7 @@ def my-command [x] {

When called with a value, we'll now see an error message returned:

```
```nu
> my-command 100

Error:
Expand Down
Loading
Loading