Home Explore Blog CI



nushell

6th chunk of `blog/2020-08-23-year_of_nushell.md`
f667f5f0394f2c0d831edba7a711e6ccadde7ce1b467bae300000001000008e0
In Nu, a command has the form `<cmd> <arg1> <arg2>`. To the lisp-lovers among you, this should look very familiar. Slap on a pair of parens and you have yourself an s-expression.

You may be wondering - if you choose a cmd-arg-arg form, how do you write something like:

```
where size > 10kb
```

This is where Nu's parser steps up. The parser we use is a type-driven, recursive descent parser. If you look at the signature for the `where` command in the Rust code, you'll see it says:

```rust
Signature::build("where").required(
    "condition",
    SyntaxShape::Math,
    "the condition that must match",
)
```

That is, the `where` command takes a single parameter, a `condition`, which has a SyntaxShape of Math. This shape drives the parser to use different parser logic.

In math mode, we can now parse an expression using operator precedence. The `where` command tells the parser to treat all of the free parameters as a single expression, to parse that expression, and to pass it as the single argument. The canonical form is more precise, though a bit more cumbersome:

```
where { = $it.size > 10kb }
```

You can also see a few other steps thrown in, like the expansion of a short-hand path into the full variable path using `$it`.

## Kebabs and question marks

Being able to use `-` in the names of commands, sometimes called "kebab case", is a handy feature and one we enjoy. In Nu, you can use it whenever you need to pass an identifier. `kebab-case-rules`.

In addition to kebab case, you can use `?` as part of the identifier, allowing names in a Ruby-style. We use it in the command `empty?`.

## Code growth

Nushell currently sits at just over 55k lines of code, built from almost 1300 merged pull requests.



_Growth in code size with each version_

# Surprises?

It's funny, when you start working on a shell it's easy to think "it'll be like a REPL". In fact, it's closer to creating an interactive IDE for the terminal. As people came to Nu from other shells, including shells like fish, there was a strong assumption that completions would be stellar, that it will integrate well with existing workflows, and it will support configuring the prompt, the keybindings, and more.

Title: Nu's Command Parsing, Naming Conventions, Code Growth, and User Expectations
Summary
Nu uses a type-driven parser that allows it to interpret commands like `where size > 10kb` by treating the condition as a single mathematical expression. It supports kebab-case and Ruby-style question mark identifiers. The Nushell project has grown to over 55k lines of code through numerous pull requests. Users expect features like excellent tab completion and integration with existing workflows, similar to an interactive IDE.