335 Commits
Author SHA1 Message Date
Piepmatz b9d514df7b Replace old Playground usages with the new one (#18915)
## Description

This PR replaces all the `Playground::setup` calls with the new injected
`Playground`.

Most of the changes are done via [this
script](https://tangled.org/cptpiepmatz.de/nushell_playground_asr) which
uses the rust-analyzer internals to replace code via the AST.

All the test should behave exactly the same as before but they don't
need to manually set up a playground anymore. Also this removes quite a
lot of lines, which is nice.

## User-facing changes (Release notes)

n/a

---

<sub>Stack created with <a
href="https://github.com/github/gh-stack">GitHub Stacks CLI</a> • <a
href="https://gh.io/stacks-feedback">Give Feedback 💬</a></sub>
2026-11-19 14:29:12 +01:00
Luc PerkinsandClaude Opus 5.5 836bb49df3 Make error output for missing environment variables more specific (#19529)
## Description

Fixes #8543 by changing the error output for a missing environment
variable to be more developer friendly.

Currently:

```
  Error: nu::shell::column_not_found

    × Cannot find column 'UNSET_VAR'
     ╭─[entry #1:1:1]
   1 │ $env.UNSET_VAR
     · ────┬───
     ·     ├── column 'UNSET_VAR' is missing in one or more values
     ·     ╰── value originates here
     ╰────
    help: If some rows have this column, try using 'UNSET_VAR?' for optional
          access, or pre-fill using the `default` command
```

Proposed:

```
  Error: nu::shell::env_variable_not_found

    x Environment variable 'UNSET_VAR' not found
     ,-[source:1:1]
   1 | $env.UNSET_VAR
     : ^^^^|^^^
     :     `-- environment variable not found
     `----
    help: use `$env.UNSET_VAR?` to get `null` if it isn't set, or `$env.UNSET_VAR? | default
          <value>` to fall back to a default
```

## User-facing changes (Release notes)

Accessing an unset environment variable, like `$env.UNSET_VAR`, now
raises a `nu::shell::env_variable_not_found` error rather than the more
generic `nu::shell::column_not_found` error, and suggests using a
construction like `$env.UNSET_VAR?` for optional access.

## Additional notes

N/A

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 18:59:34 -06:00
Yossi Eliaz 2e6a1dc684 tests: shorten background job sleeps that stall macOS CI (#19451)
## Description

On macOS, `chained_background_processes_end_with_nu` sometimes waits for
the full `^sleep 120` when shutdown races with `^true; ^sleep …` instead
of killing the process. In [run
42012499261](https://github.com/nushell/nushell/actions/runs/42012499261)
that one test took ~121s and pushed MacOS Test from ~100s to 220s.

Keep the sleep longer than the 30s leak-detection timeout so the pipe
assertion still catches real leaks, but cut the worst-case stall from
two minutes to 45 seconds. Same checks, same cases, same assertions.

Stacks independently of nushell/nushell#19445.

## Timing

| Run | MacOS Test | `chained_background_processes_end_with_nu` |
| --- | --- | --- |
|
[42012499261](https://github.com/nushell/nushell/actions/runs/42012499261)
(stall) | 220s | ~121s |
|
[41987589536](https://github.com/nushell/nushell/actions/runs/41987589536)
(typical) | 100s | ~0.9s |

After this lands on upstream CI, the intermittent stall should top out
near 45s instead of 120s.

## User-facing changes (Release notes)

n/a
2026-11-12 06:14:10 -06:00
Darren Schroeder 622be20336 Stop script arguments from running as code (#19486)
## Description

`nu script.nu <args>` and `nu -c <commands> <args>` turn the arguments
into the source text `main <args>` and parse it. `escape_for_script_arg`
quotes the arguments that would parse as something other than a plain
word, but it missed three shapes, so they ran as code.

### Before and after

Script: `def main [--x, ...args] { $args | to json --raw }`. Main is
a4819256a.

| `nu test.nu ...` | main | this PR |
|---|---|---|
| `a 'b c'` | `["a","b c"]` | `["a","b c"]` |
| `'--x;print INJECTED'` | prints `INJECTED` | `["--x;print INJECTED"]`
|
| `'--x;print INJECTED=1'` | prints `INJECTED=1` | `["--x;print
INJECTED=1"]` |
| `'--help;print INJECTED'` | prints `INJECTED` | `["--help;print
INJECTED"]` |
| `'o>' out.txt` | writes `[]` to `out.txt` | `["o>","out.txt"]` |
| `'out+err>' out.txt` | writes `[]` to `out.txt` |
`["out+err>","out.txt"]` |
| `'e>>' out.txt` | creates empty `out.txt` | `["e>>","out.txt"]` |
| `'...$env.PATH'` (`PATH=/usr/bin:/bin`) | `["/usr/bin","/bin"]` |
`["...$env.PATH"]` |
| `'0..$nu.pid'` | `["0..248"]` | `["0..$nu.pid"]` |
| `'='` | `parse_mismatch`: expected right hand side of assignment |
`["="]` |
| `'&&'` | `shell_andand` | `["&&"]` |
| `'a)'` | `unbalanced_delimiter` | `["a)"]` |
| `--x b` | `["b"]` | `["b"]` |

Script: `def main [p: path] { $p | to json --raw }`.

| `nu test.nu ...` | main | this PR |
|---|---|---|
| `...` | `"../.."` | `"../.."` |
| `'~/a$b'` | `"/Users/me/a$b"` | `"/Users/me/a$b"` |

Script: `def main [g: glob] { ls $g | get name | sort | to json --raw
}`, in a directory holding `a$1.txt`, `a$2.txt`, `a)1.txt` and
`a)2.txt`.

| `nu test.nu ...` | main | this PR |
|---|---|---|
| `'a$*.txt'` | `["a$1.txt","a$2.txt"]` | `["a$1.txt","a$2.txt"]` |
| `'a)*.txt'` | `unbalanced_delimiter` | `["a)1.txt","a)2.txt"]` |


## User-facing changes (Release notes)

- Fixed `nu script.nu <args>` and `nu -c <commands> <args>` running some
arguments as code. An argument such as `--help;print hi`, a redirection
such as `o> file`, or a variable read such as `...$env.PATH` or
`0..$nu.pid` now reaches `main` as a string.
- Script arguments `=`, `&&`, and arguments containing `)` no longer
fail to parse.


## Additional notes

- Closes #19484. 
- Related: #9939, which asks for binding arguments without re-parsing
them. This PR keeps the re-parse and only quotes more.
- The DAP launch's entry call uses the same function, so it gets the
same fix.
2026-11-12 06:09:32 -06:00
Darren Schroeder 4a9a350f82 Fix the nu-conformance open questions A1, P1, H1 and R1, and two source bugs (#19415)
## Description

conformance bug bash 2

Fixes the four bugs from the newest [nu-conformance open
questions](https://github.com/Fikoko/nu-conformance/blob/master/open-questions.md)
(A1, P1, H1, R1), and two `source` bugs found while fixing them: a
second `source` of a file left its names undefined when the first
`source` was in a scope that had ended, and a `let` from a sourced file
couldn't be read inside a closure.

### Before and after this PR

| Case | Before | After |
| --- | --- | --- |
| `def f [] { 1 }; do { hide f }; f` | `nu::shell::external_command` |
`1` |
| `def f [] { 1 }; def g [] { hide f }; f` |
`nu::shell::external_command` | `1` |
| `run h.nu \| ignore; helper` (h.nu: `def helper [] { 'h' }; 'ran'`) |
`h` | `nu::shell::external_command` |
| `run v.nu \| ignore; $v` (v.nu: `let v = 5; ...`) |
`nu::shell::variable_not_found` (runtime) |
`nu::parser::variable_not_found` |
| `nu outer.nu` (outer.nu: `run d.nu 21`, d.nu: `def main [x: int] { $x
* 2 }`) | `42`, then `nu::parser::missing_positional` | `42` |
| `run intro.nu` (its `main` calls `help helper` and `which helper`) |
`["My helper", custom]` | `["My helper", custom]` |
| `alias q = echo 1 \| str length; q \| to nuon` | `[1, "\|", str,
length]` | `nu::parser::cant_alias_expression` at `\|` |
| `alias q = echo 1 o> x.txt; q \| to nuon` | `[1, o>, "x.txt"]` |
`nu::parser::cant_alias_expression` at `o>` |
| `do { source zz.nu }; source zz.nu; zzhelper` (zz.nu: `def zzhelper []
{ 'zz' }`) | `nu::shell::external_command` | `zz` |
| `do { source zzlet.nu }; source zzlet.nu; $zzlet` (zzlet.nu: `let
zzlet = 'let'`) | `nu::parser::variable_not_found` | `let` |
| `source zz.nu; hide zzhelper; source zz.nu; zzhelper` |
`nu::shell::external_command` | `zz` |
| `do { source zzlet.nu; $zzlet }` | `nu::shell::variable_not_found` |
`let` |
| `do { source m.nu; $zzmut }` (m.nu: `mut zzmut = 'mut'`) |
`nu::parser::expected_keyword` (capture of mutable variable) | `mut` |
| `nu bom.nu` (BOM, then `1 + 1`) | `nu::shell::external_command`,
Command `1` not found | `2` |
| `use bommod.nu; bommod` (BOM, then `export def main [] { "hi" }`) |
`nu::parser::expected_keyword` | `hi` |
| `nu --config bomcfg.nu -c '$env.FOO'` (BOM, then `$env.FOO = 1`) |
`nu::parser::assignment_requires_variable` | `1` |


## User-facing changes (Release notes)

- `hide` inside a block (`do { }`, `if`, a command body) now hides the
name only in that block.
- `source` of a file sourced before in a block that has ended, such as
`do { source x.nu }; source x.nu`, now defines the file's commands and
variables again.
- A variable from a sourced file can now be used inside a closure, as in
`do { source x.nu; $x }`.
- `run` keeps a script's commands, including `main`, and its variables
inside the script. Previously they stayed defined in the caller after
`run`, and a `main` from `run` ran a second time when the calling script
ended.
- A pipe or redirection in an alias is now a parse error. Previously
`alias q = ls | length` passed `|` and `length` to `ls` as arguments.
Use `def` for a pipeline.
- Scripts, modules and config files that start with a UTF-8 byte-order
mark now run.

## Additional notes
2026-11-02 15:45:33 -06:00
Darren Schroeder 1116afb2ee Add from dotenv and to dotenv, and have load-env and with-env convert what they set (#19391)
## Description

This PR adds `from dotenv` and `to dotenv`, teaches `open` and `save` to
recognize .env files by name, and makes `load-env` and `with-env`
convert the variables they set, so `open .env | load-env` leaves `PATH`
a list. `--no-convert` sets the values as given.

```text
open .env | load-env
  open      .env, .env.local, prod.env  ->  from dotenv  ->  record of strings
  load-env  converts each value with ENV_CONVERSIONS, PATH -> list, then sets them all
  with-env  converts the same way (and so does `FOO=bar cmd`)

$record | save .env
  save      .env, .env.local, prod.env  ->  to dotenv    ->  KEY=value lines
```

- `from dotenv` reads `KEY=value` lines with an optional `export`,
unquoted, single-quoted or double-quoted values (quoted ones can span
lines), `#` comments, and `${NAME}`, `$NAME`, `${NAME:-word}`,
`${NAME-word}`, `${NAME:+word}`, `${NAME+word}` in unquoted and
double-quoted values. A name takes an earlier key of the file, or else
the environment variable, as python-dotenv and Docker Compose do. Bare
`$NAME` expands as in Docker Compose, Ruby's dotenv and Node's
dotenv-expand (python-dotenv expands only `${NAME}`). A bare name is
letters, digits and `_`, as in Compose, so `$HOST.local` reads HOST;
`$5`, a lone `$` and `$(command)` stay as written, and no command runs.
Single quotes and `\$` keep a `$`. Names ignore case as in `$env`: `a=2`
after `A=1` sets `A` again. A name inside `${}` follows the key rules,
so a key holding `-` can't be referenced (`${MY-VAR}` is MY with the
default `VAR`). In double quotes, a default word reads the same `\`
escapes as the rest of the value. A line that isn't an assignment gets a
help line saying a shell script, such as an autoenv `.env` file, isn't
.env text.
- `to dotenv` writes each value as an external command would see it, so
a `PATH` list is joined with the path separator and `to_string`
conversions apply, and `null` is written empty. Plain values stay bare,
others are single-quoted, and values with a `'` or a line break are
double-quoted with escapes (`\$` before a name or `{`), so `from dotenv`
reads back the same record. Records, closures and names `from dotenv`
can't read are errors that name the key.
- `open` treats `.env`, `.env.*` and `*.env` as dotenv when the file is
UTF-8 text; a binary `.env.gpg` still opens as raw data. A real
extension keeps its own format, so `.env.json` still opens as JSON, and
`open --raw .env` still gives text.
- `save` writes a record to such a file with `to dotenv`; other values
are written as before. It now matches the extension in any case, as
`open` does, so `save out.JSON` writes JSON.
- `load-env` and `with-env` convert each string they set with that
variable's `from_string` closure before setting any, so a failed
conversion sets nothing. A conversion without `from_string` is skipped.
A string `PATH` (or `Path`) becomes a list, and PATH is checked only
when the record holds it. A record holding `ENV_CONVERSIONS` is set
first and then converts every variable, as assigning it does, so a
failed conversion there leaves the record set. Variables the record
doesn't name aren't touched. `FOO=bar cmd` is `with-env` underneath, so
it converts too. `--no-convert` sets the values as given, as both
commands did before.

## User-facing changes (Release notes)

- Added `from dotenv` and `to dotenv` for .env files. `open .env` (also
`.env.local`, `prod.env` and the like) returns a record, and saving a
record to such a file writes .env text: `open .env | load-env`.
- `load-env`, `with-env` and `FOO=bar cmd` now apply
`$env.ENV_CONVERSIONS` to the variables they set, and a string `PATH`
becomes a list. The `$env.ENV_CONVERSIONS = $env.ENV_CONVERSIONS` line
after `load-env` is no longer needed. Pass `--no-convert` to set the
values as given.
- `save` matches a file's extension in any case, so `save data.JSON`
writes JSON.
- A text file named like `.env` that isn't `KEY=value` lines, such as an
autoenv shell script, now fails to open with a parse error. Use `open
--raw .env` to read it as text.

## Additional notes
<!--
Optional.

Examples:
- fixes #123
- closes #456
- related #789

Anything else reviewers should know.
Remove this section if not needed.
-->
2026-10-31 12:00:06 -05:00
Darren Schroeder 168db974ba Remove deprecations older than six months (#19382)
## Description

This removes everything deprecated in 0.112 or earlier (April 2026 or
before), along with the stubs left from the 2023 removals. It also
removes `ast::Call::positional_nth` and `positional_len`, which were
deprecated in 0.113 and have no in-tree users. Everything else
deprecated in 0.113 or later stays: `watch` with a closure, `str
upcase`/`str downcase`, `ShellError::Return`, `tui label --title`, and
`update cells --columns`.

Commands and flags are deleted outright instead of being turned into
stubs. Most removed names still lead to their replacement through
existing search terms: `filter` suggests `where`, `benchmark` suggests
`timeit`, `fetch` suggests `http get`, and `post` suggests `http post`.

`default $closure` keeps its current behavior. The deprecation warning
promised that closures passed by variable would become lazy, but making
that change would be a new break. So the promise goes away instead: a
closure literal (`default { ... }`) is evaluated lazily, and a closure
passed directly as `$var` is the default value itself. The help text now
says this.

`CustomValue::is_iterable()` is no longer deprecated. Its deprecation
note promised a replacement that was never built, and the SQLite query
builder still depends on it.

## User-facing changes (Release notes)

- Removed `--ignore-errors (-i)` from `get`, `select`, and `reject`. Use
`--optional (-o)`.
- Removed `get --sensitive (-s)`. Cell paths are case-sensitive by
default. Add `!` after a member to make it case-insensitive.
- Removed `filter`. Use `where`, which takes the same closures,
including one stored in a variable.
- Removed the `positional` option from custom completer results. Use
`completion_algorithm: substring` instead. A completer that still
returns `positional: false` now gets prefix matching.
- `default` no longer warns when its closure is passed directly as
`$var`. That closure is used as the default value, while a closure
literal is still evaluated lazily.
- Deleted the `date format` and `let-env` stubs and the removal hints
for `fetch`, `post`, and `benchmark`. All of these were removed in 2023.
`let-env FOO = 1` now fails with "Assignment operations require a
variable", and `date format '%Y'` with "Extra positional argument". Use
`$env.FOO = 1` and `format date`.
- Nushell no longer converts a pre-0.93 `plugin.nu` into
`plugin.msgpackz`. A setup that has only `plugin.nu` starts with no
plugins. Register them again with `plugin add`.

### Breaking changes for plugin authors

- `ShellError::GenericError` is removed. Use
`ShellError::Generic(GenericError)`.
- `PipelineData::metadata()` is removed. Use `metadata_ref()`,
`metadata_mut()`, or `take_metadata()`.
- `EngineState::current_work_dir()` and `StateWorkingSet::get_cwd()` are
removed. Use `EngineState::cwd()` or `cwd_as_string()`.
- `ast::Call::positional_nth()` and `positional_len()` are removed. Use
`positional_iter()`.
- The unused `ShellError::DeprecationWarning` is removed.
- `CustomValue::is_iterable()` is no longer deprecated.

## Additional notes
<!--
Optional.

Examples:
- fixes #123
- closes #456
- related #789

Anything else reviewers should know.
Remove this section if not needed.
-->
2026-10-31 07:58:34 -05:00
Darren Schroeder 16e5c2c7c9 Fix try hanging under pipefail, and keep an external's stderr through finally and o> (#19349)
## Description

This follows #19339, which lets `try { ^ext } catch {..} | complete`
pass the external on with its stderr. Three cases around it still
failed.

### Fixed:

| Command | Before | After |
| --- | --- | --- |
| `try { $BIG } \| str length` | hangs | `300002` |
| `try { $BIG } catch { 'c' } \| str length` | hangs | `300002` |
| `try { $BIG \| lines } \| length` | hangs | `1` |
| `try { ^yes } \| lines \| first 3` | hangs | `[y, y, y]` |
| `try { $OUTERR } finally {\|v\| print ($v \| describe) } \| complete`
| `string`, then `Complete only works with external commands` |
`string`, then `{stdout: "out\n", stderr: "err\n", exit_code: 0}` |
| `try { $OUTERR } finally { print fin } \| save -f --stderr e.txt
o.txt` | `e.txt` empty, `err` printed | `o.txt` holds `out`, `e.txt`
holds `err` |
| `try { $OUTERR } catch {} finally { .. } \| ignore --stderr` | prints
`err` | prints nothing on stderr |
| `$OUTERR o> o.txt \| complete` | `Complete only works with external
commands` | `{stderr: "err\n", exit_code: 0}`, `o.txt` holds `out` |
| `$OUTERR o> o.txt \| ignore` | stderr dropped | `err` |
| `try { $FAILERR } catch {\|e\| print $'caught ($e.exit_code)' } \|
ignore` | `caught 3` | `boom` on stderr, `caught 3` |
| `do { try { $FAILERR } catch {} \| ignore } e> e.txt` | `e.txt` empty
| `e.txt` holds `boom` |

### Changed:

| Command | Before | After |
| --- | --- | --- |
| `try { ^sh -c 'echo hi; exit 3' \| lines } \| length` | `0` | `1` |
| `try { ^sh -c 'echo hi; exit 3' } \| lines` | `null` | `[hi]` |
| `try { ^sh -c 'exit 3' } \| complete` | `Complete only works with
external commands` | `{stdout: "", stderr: "", exit_code: 3}` |
| `try { ^false } \| describe` | `nothing` | `byte stream` |
| `try { ^false }; print after` | `after` | `after` |
| `try { ^sh -c 'echo a; exit 3' \| lines \| each {\|x\| print $'side
($x)'; $x } } catch { 'caught' }` | `caught` | `side a`, `caught` |
| `try { ^sh -c 'echo notnum; exit 3' \| lines \| each { into int } }
catch {\|e\| $e.msg }` | `External command had a non-zero exit code` |
`Can't convert to int.` |



## User-facing changes (Release notes)

- Fixed `try { ^external } | ...` hanging with pipefail on once the
external wrote more than 64KB, with or without `catch`.
- A `try` without `catch` or `finally` no longer waits for an external
whose output goes on to the next command, and ignores that external's
failure, as with pipefail off. So `try { ^cmd | lines } | first 3` stays
lazy and `try { ^cmd } | complete` gets the exit code. Before, a failure
replaced the output with `null`.
- With `catch`, the commands after a failing external inside the `try`
now run on its output before `catch` does. They already did when one of
them read the whole stream, like `length` or `save`, and they do the
same without the `try`. To check the external's exit code before later
commands run, put `collect` after it: `try { ^cmd | collect | lines |
each { ... } } catch { ... }`.
- `try { ^external } finally { ... } | complete` now gets the external's
stdout, stderr and exit code, and so do `save --stderr`, `tee --stderr`
and `ignore --stderr`. `finally {|v| ... }` still gets the stdout as a
value.
- Fixed `^external o> file | complete` failing with "Complete only works
with external commands". `complete` gets the stderr and exit code while
stdout goes to the file. `save --stderr` and `tee --stderr` capture the
stderr, and `ignore` shows it instead of dropping it.
- When `catch` takes over from a failed external whose stderr was going
to `complete`, `ignore`, `save` or `tee`, that stderr now shows up
instead of being dropped. `ignore --stderr` shows it too, since it only
gets the `catch` output.
 
## Additional notes

Closes #19335
2026-10-28 06:42:11 -05:00
berce f3cc93329c fix(try): drain a piped stderr before collecting an external (#19339)
## Description

`ignore`, `save`, `complete` and `tee` ask for an external's stdout and
stderr on their own pipes (`PipeSeparate`), so an external at the end of
a `try` block that is piped into one of them gets a stderr pipe too. A
`try` with `catch` or `finally` then collects the block's output with
`try-collect`, and `collect` calls `into_value` on the child stream.
`ChildProcess::into_bytes` refuses a child that still has a stderr pipe
("internal error: stderr should not exist"), so the error went to
`catch` even though the external exited 0.

A value can't carry a separate stderr, so `try-collect` now leaves such
a child as a stream instead of turning it into a value:

- `ChildProcess::buffer_output` reads stdout and stderr to the end
(stderr on its own thread, with the reader that `wait_with_output`
already used, now shared as `collect_pipes`), waits for the child,
checks its exit status the way `into_bytes` does, and puts the output
back so it can still be read. `do` already rebuilds a finished child
from buffers in a similar way.
- `try_collect` in `eval_ir.rs` does this for a child with a stderr pipe
and passes it on, so the command after the `try` gets stdout, stderr and
the exit status as if there were no `try`. Failing externals still error
inside the `try`, so `catch` still runs for them. Everything else still
goes through `collect`.
- The pipes are read before the pipefail exit check. Waiting for the
exit first hung on a child that filled its stderr pipe.
- `finally` gets a copy of the result, and only a value can be copied.
So at `begin-finally`, a child passed on like this becomes its stdout,
and its stderr goes to the block's stderr, the same as for `let x =
^external`.

`into_bytes` keeps its check: a caller that wants a value can't keep
stderr.

## User-facing changes (Release notes)

Fixed `try { ^external } catch { ... } | ignore` (also with `save
--stderr`, `complete`, `tee --stderr`, and inside `do` or a custom
command) running the `catch` block with "internal error: stderr should
not exist" when the external succeeded. The external's stderr now
reaches the next command the same way it does without the `try`.

With `finally`, the `try` doesn't fail that way anymore either, but the
result is still turned into a value so `finally` can see it. The next
command gets the external's stdout as a value and its stderr is printed,
like for `let x = ^external`. So `save --stderr` after `try ... finally`
gets an empty stderr, and `complete` still says it only works with
external commands.

## Additional notes

Fixes #19335

Tests in `tests/shell/mod.rs`:
- `try_catch_keeps_a_piped_stderr_of_a_successful_external` runs `try {
X } catch { print caught } | C` and `X | C` and checks that stdout and
stderr match. `C` is each of `ignore`, `ignore --stdout`, `ignore
--stderr`, `complete`, and `save --stderr`. `X` is either a short
stdout+stderr external or one that writes 200KB to stderr.
- `try_catch_piped_into_ignore_catches_only_a_failing_external` covers
the same inside a `def`, `finally` with and without `catch`, and a
failing external that is still caught.

On main, 8 of the 14 cases fail, the 5 with 200KB of stderr hang until
killed, and only the failing-external case passes.

- `cargo test --test tests`: 2421 passed
- `cargo test -p nu-protocol -p nu-engine -p nu-cmd-lang`, `cargo test
-p nu-command -- complete ignore save tee try_`: passed
- `cargo fmt --all -- --check`, `cargo clippy -p nu-engine -p
nu-protocol -p nu-cmd-lang --all-targets --no-deps -- -D warnings`, and
`cargo check -p nu-engine --no-default-features` with `-D warnings`:
clean (toolchain 1.99.1)

More than 64KB of stdout with no stderr pipe still hangs with pipefail
on, as on 0.116.2; that path isn't touched here.
2026-10-25 15:05:35 -05:00
Manish d1064f1ae1 fix(print): surface external failures instead of masking exit code (#19227) (#19260)
## Description

Fixes #19227. `print` ignored failures of external commands because it
called `ignore_error(true)` on the child's byte streams, so a pipeline
such as a failing external command piped into `print` exited with 0
while the same failure from an internal command exited with 1. This
removes the suppression so non-zero exits propagate. Tests were added to
`pipefail_feature` (`fail 30 | print`, `print --raw`, `print -e`) plus
`pipefail_print_keeps_output_before_failure` and
`pipefail_print_stderr_keeps_output_before_failure`, which check that
output still reaches stdout / stderr before the failure exit code.

`^cmd | print <args>` still drops the piped input without waiting on the
child, so with pipefail off it still exits 0, the same as `| ignore`.

Tests run: `cargo test --test tests -- pipefail_feature`, `cargo clippy
--tests`, `cargo fmt --all -- --check`.

## User-facing changes (Release notes)

Fixed an issue where `print` hid the failure of an external command: a
failing external command piped into `print` now makes the pipeline fail
with its non-zero exit code instead of exiting with 0. This is a
behavior change for scripts that relied on the old result, for example
`^grep pat file | print` with no match now errors, and `do -i { ^false }
| print` now fails like `do -i { ^false } | collect` already does.

## Additional notes

fixes #19227
2026-10-21 14:20:16 -05:00
qodelicious 2deff7fc5b fix(cli): show the script name instead of main in errors about a script's arguments (#19282)
## Description
`nu script.nu` runs the script's `main` by evaluating `main <args>`, so
an error about the arguments showed `main` in the source snippet, even
though the usage line already uses the script name:

```
Error: nu::parser::missing_positional

  × Missing required positional argument.
   ╭─[<commandline>:1:5]
 1 │ main
   ·     ▲
   ·     ╰── missing foo
   ╰────
  help: Usage: script.nu <foo> . Use `--help` for more information.
```

`evaluate_file` already adds the script name to the overlay as another
name for `main` (and `script.nu foo` for `main foo`), so the call can
use it. This now builds the command line as `script.nu <args>` when that
parses as a call to the script's renamed `main` (checked with a single
probe parse), and falls back to `main <args>` otherwise. The snippet
then shows `script.nu`:

```
   ╭─[<commandline>:1:10]
 1 │ script.nu
   ·          ▲
   ·          ╰── missing foo
   ╰────
  help: Usage: script.nu <foo> . Use `--help` for more information.
```

The script name is only used when it parses as a command. Scripts named
after a parser keyword (`for`, `source`, `use`, `module`, `alias`, ...)
always call `main` directly, and names that parse as something else,
such as `10kb`, `true`, `it's.nu` or `a #b.nu`, still show `main`. Names
with a space (`my script.nu`) use the script name. Scripts without a
`main` aren't affected.

Tests added in `tests/shell/mod.rs`:
- `main_script_missing_argument_uses_script_name`
- `main_script_subcommand_missing_argument_uses_script_name`
- `main_script_with_space_in_name_uses_script_name`
- `main_script_named_like_a_parser_keyword_still_runs`
- `main_script_named_like_a_value_still_runs` (checks the fallback to
`main`)
- `script_without_main_is_unaffected`

## User-facing changes (Release notes)
- Errors about the arguments passed to a script's `main` (such as a
missing positional argument) now show the script name instead of `main`,
when the script name parses as a command. Other names (for example
`10kb` or `it's.nu`) still show `main`.

## Additional notes
Fixes #10191

Tests + formatting:
- `cargo fmt --all -- --check`
- `cargo clippy -p nu-config -p nu-cmd-lang -p nu-command -p nu-cli -p
nu-explore --all-targets -- -D warnings -D clippy::unwrap_used`
- `cargo clippy -p nu -p nu-cli --all-targets -- -D warnings -D
clippy::unwrap_used`
- `cargo test --test tests -- shell::`
- `cargo test -p nu-cli --lib eval_file`

The script name is only used when the call resolves to main, so names
like 10kb, it's.nu or main;… still show main.
2026-10-19 06:18:24 -05:00
Darren Schroeder 973c590918 Fix the bugs found by the nu-conformance open questions (#19271)
## Description

The [nu-conformance](https://github.com/Fikoko/nu-conformance) suite
(#19206) recorded 35 behaviors as open questions. This PR fixes the ones
that are bugs, plus five that needed a decision (T2, T4, T8, T12 and
T13). The IDs are the question IDs in that repo's
[`open-questions.md`](https://github.com/Fikoko/nu-conformance/blob/master/open-questions.md).

### Before and after

| | Code | main | branch |
|---|---|---|---|
| S2 | `"\xFF"` | error `nu::parser::parse_mismatch`: expected any shape
| error `nu::parser::error`: invalid UTF-8 from `\x` escapes in string |
| S3 | `r#'abc` | error `nu::parser::unexpected_eof`: expected closing
'# | error `nu::parser::unclosed_delimiter`: expected `'#` here |
| T1 | `inf == 1` | `true` | `false` |
| T1 | `inf > 1` | `false` | `true` |
| T1 | `[1.0 inf] \| math max` | `1.0` | `inf` |
| T2 | `let x = 5; -$x` | `-$x` | `-5` |
| T2 | `let x = 5; 1 + -$x` | error
`nu::parser::operator_incompatible_types`: string | `-4` |
| T2 | `let x = 5sec; -$x` | `-$x` | `-5sec` |
| T2 | `-(2 + 3) \| describe` | `string` | `int` |
| T2 | `-(1)px` | `-1px` | `-1px` |
| T3 | `-0x10` | `-0x10` | `-16` |
| T3 | `+0b11` | error `nu::shell::external_command`: Command `+0b11`
not found | `3` |
| T4 | `9223372036854775808` | `9223372036854775808.0` | error
`nu::parser::error`: number too large (add `.0` for a float) in int |
| T4 | `9223372036854775808.0` | `9223372036854775808.0` |
`9223372036854775808.0` |
| T6 | `[INF Nan Infinity] \| to nuon` | `[inf, NaN, inf]` | `["INF",
"Nan", "Infinity"]` |
| T6 | `[inf nan NaN] \| to nuon` | `[inf, NaN, NaN]` | `[inf, NaN,
NaN]` |
| T7 | `9223372036854775808ns` | `15250wk 1day 23hr 47min 16sec 854ms
775µs 807ns` | error `nu::parser::literal_too_large`: duration too large
|
| T7 | `8EiB` | `9.2 EB` | error `nu::parser::literal_too_large`:
filesize too large |
| T8 | `[2023-02-29] \| to nuon` | `["2023-02-29"]` | error
`nu::parser::error`: not a valid date in datetime |
| T8 | `[2023-02-29.log] \| to nuon` | `["2023-02-29.log"]` |
`["2023-02-29.log"]` |
| T10 | `+5sec` | error `nu::shell::external_command`: Command `+5sec`
not found | `5sec` |
| T11 | `[1 2]] \| to nuon` | `[1, "2]"]` | error
`nu::parser::unbalanced_delimiter`: unexpected `]` (unbalanced with `[`)
|
| T12 | `{true: 1, null: 2} \| to nuon` | error
`nu::parser::parse_mismatch_with_full_string_msg`: expected string |
`{"true": 1, "null": 2}` |
| T12 | `[[1 2]; [3 4]] \| to nuon` | error `nu::parser::error`: must be
a string | `[["1", "2"]; [3, 4]]` |
| T13 | `print before; {a: 1, a: 2}` | error
`nu::shell::column_defined_twice`: field first defined here | error
`nu::parser::column_defined_twice`: field redefined here |
| O1 | `not "a" == "b"` | error `nu::shell::cant_convert`: can't convert
string to boolean | `true` |
| O1 | `let x = 1; not $x == 2` | error `nu::shell::cant_convert`: can't
convert int to boolean | `true` |
| O3 | `(-9223372036854775808) mod -1` | error
`nu::shell::operator_overflow`: modulo operation overflowed | `0` |
| O4 | `1 in [1.0]` | error `nu::parser::operator_incompatible_types`:
list<float> | `true` |
| D1 | `const x = 1; unlet $x; $x` | `1` | error
`nu::compile::invalid_literal`: constants cannot be deleted |
| D2 | `unlet $in` | `nothing` | error `nu::compile::invalid_literal`:
'$in' is a built-in variable and cannot be deleted |
| D3 | `mut x = 0; [1 2 3] \| where {\|v\| $x += 1; true } \| ignore;
$x` | `0` | error `nu::parser::expected_keyword`: capture of mutable
variable |
| F2 | `while false { } \| describe` | `nothing` | error
`nu::parser::unexpected_keyword`: not allowed in pipeline |
| F3 | `if 1 { }` | error `nu::shell::cant_convert`: can't convert int
to boolean | error `nu::shell::type_mismatch`: expected bool |
| F4 | `2.0 in 1.0..2.0` | `false` | `true` |
| F4 | `2.0 in 1.0..<2.0` | `true` | `false` |
| C1 | `def f [...r, a] { {r: $r, a: $a} }; f 1 2 3 \| to nuon` | `{r:
[2, 3], a: 1}` | error `nu::parser::positional_after_rest`: parameter a
after the rest parameter |
| C2 | `def f [a, a] { $a }; f 1 2` | `2` | error
`nu::parser::duplicate_parameter`: `a` uses a name that is already taken
|
| C2 | `def f [--x, --x] { $x }; f --x` | `false` | error
`nu::parser::duplicate_parameter`: `--x` uses a name that is already
taken |
| C2 | `def f [--help] { 'mine' }; f --help \| lines \| first` |
`Usage:` | error `nu::parser::error`: every command already has `--help`
|

C3, a script that calls two deprecated commands:

```nushell
$ nu two_deprecated.nu    # main
Warning: nu::parser::deprecated
   : `-- g is deprecated and will be removed in a future release.
```
```nushell
$ nu two_deprecated.nu    # branch
Warning: nu::parser::deprecated
   : `-- g is deprecated and will be removed in a future release.
Warning: nu::parser::deprecated
   : `-- k is deprecated and will be removed in a future release.
```
## User-facing changes (Release notes)

### Breaking changes

- `not` now has the precedence `help operators` lists: `not $a == $b`
means `not ($a == $b)`. Before, `not` applied to the next value only.
- `-$x` and `-(expr)` negate their value, also as a flag's value or an
argument after `--`. Before, `-$x` was the string `"-$x"` and `-(2 + 3)`
the string `"-5"`. Arguments to external commands are unchanged.
- An integer literal too large for 64 bits, such as
`9223372036854775808`, is an error. Add `.0` to write a float.
- Filesize and duration literals that don't fit are a parse error
(`nu::parser::literal_too_large`) instead of saturating to the largest
value.
- A word written like a date that isn't a valid date, such as
`2023-02-29`, is an error.
- `INF`, `Nan`, `Infinity` and other spellings of special floats are
strings. Use `inf`, `nan` or `NaN`. `from nuon` reads them the same way.
- A record or table literal that names a field twice is a parse error.
- `[1 2]]` is an error instead of `[1, "2]"]`.
- In a custom command, repeated parameter or flag names, repeated short
flags, a parameter after `...rest`, and a `--help` flag are errors.
- `while` and `loop` can't be piped, like `for`.
- `unlet` errors on constants and on `$in`.
- Assigning to a `mut` variable inside a `where` condition is an error;
the assignment never took effect.

### Fixes

- `inf` compares as larger than every finite number, and `[1.0 inf] |
math max` is `inf`.
- `2.0 in 1.0..2.0` is `true`, and `2.0 in 1.0..<2.0` is `false`.
- `-0x10`, `+0b11`, `+5sec` and `+1kB` are numbers.
- `1 in [1.0]` is `true`.
- `{true: 1}` and `[[1 2]; [3 4]]` parse, with the keys `"true"`, `"1"`
and `"2"`.
- `(-9223372036854775808) mod -1` is `0`.
- `if 1 { }` reports the same type mismatch as `while 1 { }`, and an
`if` or `while` condition that fails while it runs reports its own
error.
- `9223372036854775807ns` and `9223372036854775807b` are exact, and
integer filesize and duration literals no longer lose precision.
- A script or `nu -c` command shows every parse warning once, not only
the first.
- Clearer errors for invalid UTF-8 from `\x` escapes and for unclosed
raw strings.

## Additional notes
2026-10-17 14:54:47 -05:00
pickx 7b893cbad5 roundup of fixes for {hide,load,with}-env (#19098)
## Description
this is a roundup of fixes meant to address the following issues:
1. `$env.config`
- `load-env { config: {} }` and `hide-env config` can make `$env.config`
inaccessible. with the way nushell works, the config isn't gone, and a
simple `$env.config = {}` will fix this. but (imo) it's still weird.
- it can also give the impression that `load-env` is able to set
`$env.config`, which it couldn't.
    - therefore, I changed it so `hide-env` can't touch `config`.
- meanwhile, `load-env` and `with-env` (including the shorthand syntax
`FOO=bar command`) can now change `config`, which triggers a proper
config reload
2. automatic env vars
- automatic env vars like `PWD` are not supposed to be changed through
`load-env` and `hide-env`. a guard was implemented in `load-env` but not
`hide-env`. now both handle this.
- we had several manual impls of finding automatic env vars. changed to
use a shared impl.
- some env var-detecting logic still has the assumption that env vars
are case sensitive outside Windows, but `load-env` and `hide-env` don't
work like that. so although `load-env` tried to guard against changing
e.g. `$env.PWD` it would happily change `$env.PwD` so can still mess up
the environment.

## User-facing changes (Release notes)
Changes have been made around the interaction of `load-env`, `hide-env`
and `with-env` with some environment variables which are managed by
nushell.

Specifically:
* `load-env`, `hide-env` and `with-env` can no longer change `$env.PWD`,
regardless of casing (for example, `Pwd` is also rejected).
* `hide-env` can no longer hide `$env.FILE_PWD` or `$env.CURRENT_FILE`.
this was previously allowed.
* `load-env` and `with-env`, including the syntax `FOO=bar command`, can
now set `$env.config`.
* `hide-env` can no longer hide `$env.config`.
2026-10-17 07:13:58 -05:00
Darren Schroeder 6112446c3c fix(help): drop hidden subcommands and fix multi-line, backticked, and script alias entries (#19261)
## Description

Follow-up to #19253, which lists an alias in `help <command>` under its
own name, right after the subcommand it runs. Four cases are still wrong
on main:

- A hidden custom subcommand is still listed. #19253 only dropped hidden
aliases.
- An alias written over several lines splits its entry across lines.
- With color on, backticks inside an alias's expansion confuse the
highlighter. The inner backticks disappear and the outer ones stay.
- A script's `alias mb = main bar` is missing from `script.nu --help`,
though `mb` works inside the script.

With this PR, `help` leaves out a hidden subcommand of any kind, joins
an alias's expansion onto one line and highlights it as a whole, and
lists a script alias of a `main` subcommand right after that subcommand.

Each example shows the Subcommands section of `help`. Before is main at
776da6de4 (which includes #19253), after is this branch. Color is
stripped.

A hidden custom subcommand was still listed. You can't call it, so it's
left out now.

```nushell
def foo [] {}; def "foo bar" [] {}; def "foo qux" [] {}; hide "foo qux"; help foo
```

Before:

```nushell
Subcommands:
  foo bar (custom) -
  foo qux (custom) -
```

After:

```nushell
Subcommands:
  foo bar (custom) -
```

An alias written over several lines split its entry across lines. The
entry joins them now.

```nushell
def foo [] {}; def "foo bar" [x] {}
alias fm = foo bar (
  'a'
)
help foo
```

Before:

```nushell
Subcommands:
  foo bar (custom) -
  fm (alias) - Alias for `foo bar (
  'a'
)`
```

After:

```nushell
Subcommands:
  foo bar (custom) -
  fm (alias) - Alias for foo bar ( 'a' )
```

Backticks inside the expansion lost their place. The highlighter dropped
the inner pair and kept the outer one.

```nushell
def foo [] {}; def "foo bar" [x] {}; alias fq = foo bar `x y`; help foo
```

Before:

```nushell
Subcommands:
  foo bar (custom) -
  fq (alias) - Alias for `foo bar x y`
```

After:

```nushell
Subcommands:
  foo bar (custom) -
  fq (alias) - Alias for foo bar `x y`
```

A script alias of a `main` subcommand was missing from the script's
help.

```nushell
# script.nu
def "main bar" [] {}
alias mb = main bar
alias "main baz" = main bar
def main [] {}
```

```nushell
nu script.nu --help
```

Before:

```nushell
Subcommands:
  script.nu bar (custom) -
  script.nu baz (alias) - Alias for main bar
```

After:

```nushell
Subcommands:
  script.nu bar (custom) -
  mb (alias) - Alias for main bar
  script.nu baz (alias) - Alias for main bar
```

The other cases #19253 fixed print the same on main and this branch:
`fb` after `foo bar`, `st` after `str trim` (with or without a doc
comment), `spam fb` and `foo baz` from a module, and a top-level `alias
"foo baz" = foo bar`.


## User-facing changes (Release notes)

`help <command>` no longer lists hidden subcommands. An alias of a
subcommand written over several lines, or containing backticks, now
shows on one line with its full expansion. A script's `alias mb = main
bar` now appears in `script.nu --help`, right after `script.nu bar`.

## Additional notes
<!--
Optional.

Examples:
- fixes #123
- closes #456
- related #789

Anything else reviewers should know.
Remove this section if not needed.
-->
2026-10-16 07:47:22 -05:00
赤坂理子 356e7bc02f Preserve REPL background jobs on Ctrl-C and clean up jobs on non-REPL exit (#19163)
## Summary

- Addresses #18989 by preserving REPL background and frozen jobs during
foreground `Ctrl-C`, while non-REPL commands and scripts clean up jobs
even when an interruption is caught
- Determine execution mode once (REPL, command, script, server) without
conflating `-i` with an interactive REPL; explicit `exit` in `-i -c` or
`-i` script preserves requested exit code, while REPL retains first-exit
warning and second-exit cleanup
- Serialize OS process creation and PID registration against `ThreadJob`
shutdown under the PID lock to eliminate an orphan-process race
- Clear cloned `is_repl` flag in background job engine clones so `exit`
terminates their closure instead of warning and continuing
- Centralize forced cleanup and lock-poison recovery, completing
non-REPL cleanup before publishing interrupts while preserving early
signal-handler initialization
- Windows combines `CREATE_NEW_PROCESS_GROUP` and `CREATE_NO_WINDOW`
inside `ForegroundChild` without an extra exported preparation helper;
new process groups isolate `Ctrl-C` but `Ctrl+Break` is NOT isolated
- Cross-platform lifecycle tests use Nu as the child, bounded handshakes
and Windows owned process handles opened before child exit to avoid PID
reuse
- Add tests for lock registration, chained spawns, explicit exit, REPL
two exits and background exit; remove fixed 500ms sleep
- Fix minimal-feature plugin-only import warning for `absolute_with`

## Testing

Verified on macOS on top of `ca323a65bdb7c945488b75a5f7bf5d90a8f3bff1`:
- 29 background job regressions, 3 `ThreadJob` tests, and 47 root unit
tests passed
- Shell suite: 320 passed, 6 ignored
- Related crate tests and doctests ran with `--no-fail-fast` for
`nu-protocol`, `nu-engine`, `nu-command`, `nu-system`, `nu-cli`; all
passed except one existing `cp` debug test
- Chained-spawn stress test produced 0/1000 leaks versus 5/50 on
original head; `-i -c "exit 3"` returns 3 without running subsequent
code
- `cargo fmt --all --check` passed
- Clippy passed with `-D warnings` on `--all-targets` for `nu`,
`nu-protocol`, `nu-engine`, `nu-command`, `nu-system`, `nu-cli`
- Minimal-feature check passed for `--bin nu`
- WASM target checks passed for `nu-command`, `nu-engine`,
`nu-protocol`, `nu-system`
- Windows cross-compilation check passed for `nu-engine`, `nu-protocol`,
`nu-system` libraries

## Remaining validation

Open verification limits and pending checks:
- Local `cp` debug test expects `reflink: unsupported` but this macOS
returns `reflink: yes`, confirmed identically on original published head
`ca323a65bdb7c945488b75a5f7bf5d90a8f3bff1`
- `cargo check --no-default-features --all-targets` fails on existing
`nu-plugin-engine` `ServerCommunicationIo::LocalSocket` non-exhaustive
match, reproduced in an isolated original-head source and target tree
- Windows real-console `GenerateConsoleCtrlEvent` integration test is
still missing and `ping -t` reproduction has not been performed;
compile-only Windows checks do not establish runtime behavior, so
Windows review remains open
- Updated GitHub CI validation is pending publication

---------

Signed-off-by: akasakariko <148060537+akasakariko@users.noreply.github.com>
2026-10-16 06:44:50 -05:00
Darren Schroeder 9398108ce7 fix(help): list an alias in a command's subcommands under its own name (#19253)
## Description

`help <command>` lists aliases of the command's subcommands, which makes
`help str` a place to discover `st` after `alias st = str trim`. On main
the entry used the wrong name. It showed the alias under the name of the
command it wraps, so `str trim` appeared twice and `st` appeared
nowhere. A hidden alias stayed listed, and a script alias named like a
`main` subcommand was missing.

With this PR an alias is listed under the name you call it by, right
after the subcommand it runs, and its entry always says what it runs:
``st (alias) - Alias for `str trim` ``.


Each example shows the Subcommands section of `help`. Before is main at
f443a4fbe, after is this branch. Color is stripped; in a terminal the
backticked part of ``Alias for `str trim` `` is shown as highlighted
code.

An alias of a custom subcommand showed up as a second `foo bar`.

```nushell
def foo [] {}; def "foo bar" [] {}; alias fb = foo bar; help foo
```

Before:

```nushell
Subcommands:
  foo bar (alias) - Alias for foo bar
  foo bar (custom) -
```

After:

```nushell
Subcommands:
  foo bar (custom) -
  fb (alias) - Alias for foo bar
```

A hidden alias was still listed. You can't call it, so it's left out
now.

```nushell
def foo [] {}; def "foo bar" [] {}; alias fb = foo bar; hide fb; help foo
```

Before:

```nushell
Subcommands:
  foo bar (alias) - Alias for foo bar
  foo bar (custom) -
```

After:

```nushell
Subcommands:
  foo bar (custom) -
```

Builtins behaved the same way. `str trim` was listed twice.

```nushell
alias st = str trim; help str
```

Before:

```nushell
Subcommands:
  ...
  str trim - Trim whitespace or specific character.
  str trim (alias) - Alias for str trim
  str upcase - Convert text to uppercase.
  ...
```

After:

```nushell
Subcommands:
  ...
  str trim - Trim whitespace or specific character.
  st (alias) - Alias for str trim
  str upcase - Convert text to uppercase.
  ...
```

A doc comment on the alias replaced its description, so the entry no
longer said what the alias runs. The entry now always does. The comment
still shows in `help st`.

```nushell
# trim both ends
alias st = str trim; help str
```

Before:

```nushell
Subcommands:
  ...
  str trim - Trim whitespace or specific character.
  str trim (alias) - trim both ends
  str upcase - Convert text to uppercase.
  ...
```

After:

```nushell
Subcommands:
  ...
  str trim - Trim whitespace or specific character.
  st (alias) - Alias for str trim
  str upcase - Convert text to uppercase.
  ...
```

An alias exported from a module is listed under the name `use` gives it.

```nushell
module spam { export def foo [] {}; export def "foo bar" [] {}; export alias fb = foo bar }
use spam
help spam foo
```

Before:

```nushell
Subcommands:
  foo bar (alias) - Alias for foo bar
  foo bar (custom) -
```

After:

```nushell
Subcommands:
  foo bar (custom) -
  spam fb (alias) - Alias for foo bar
```

A module alias named like a subcommand was listed under the wrapped
command's name, `foo bar`, instead of its own, `foo baz`.

```nushell
module spam { export def foo [] {}; export def "foo bar" [] {}; export alias "foo baz" = foo bar }
use spam
help spam foo
```

Before:

```nushell
Subcommands:
  foo bar (alias) - Alias for foo bar
  foo bar (custom) -
```

After:

```nushell
Subcommands:
  foo bar (custom) -
  foo baz (alias) - Alias for foo bar
```

A script alias named like a `main` subcommand was missing from the
script's help, even though `nu script.nu baz` runs it.

```nushell
# script.nu
def "main bar" [] {}
alias "main baz" = main bar
def main [] {}
```

```nushell
nu script.nu --help
```

Before:

```nushell
Subcommands:
  script.nu bar (custom) -
```

After:

```nushell
Subcommands:
  script.nu bar (custom) -
  script.nu baz (alias) - Alias for main bar
```
## User-facing changes (Release notes)

`help <command>` now lists an alias of one of its subcommands under the
alias's own name, right after the subcommand it runs, with ``Alias for
`...` `` as its description. After `alias st = str trim`, `help str`
shows ``st (alias) - Alias for `str trim` `` below `str trim`, where it
used to show a second `str trim` line. A hidden alias is no longer
listed, and a script's `alias "main baz" = main bar` now appears in
`script.nu --help` as `script.nu baz (alias)`.

## Additional notes
2026-10-16 06:13:14 -05:00
Darren Schroeder c8095a3d10 fix(each): report the closure's error instead of "Eval block failed with pipeline input" (#19252)
## Description


The commands `each`, `par-each`, and `items` wrap an error raised by
their closure in `ShellError::EvalBlockWithInput`. That variant had its
own message, "Eval block failed with pipeline input", its own code,
`nu::shell::eval_block_with_input`, and kept the closure's error in
`#[related]`. So `catch` saw the wrapper's text, and the report printed
the generic wrapper first and the error that mattered second:

```nushell
> try { [1] | each { error make {msg: inner} } } catch {|e| $e.msg }
Eval block failed with pipeline input
> try { for x in [1] { error make {msg: inner} } } catch {|e| $e.msg }
inner
```

The variant now holds an `EvalBlockWithInputError`, a struct with a
hand-written `Diagnostic` impl in
`crates/nu-protocol/src/errors/shell_error/eval_block_with_input.rs`. It
forwards to the wrapped error the same way `ChainedError` does for a
single source, and adds one label.

## User-facing changes (Release notes)

When a closure passed to `each`, `par-each`, or `items` fails, Nushell
now reports the closure's error. The input value it was processing is
shown as an extra `source value` label. `$e.msg` in `catch` is the
closure's message, and the error code is the closure error's code
instead of `nu::shell::eval_block_with_input`.

Before:

```nushell
> [1 2] | each {|x| $x / 0 }
Error: nu::shell::eval_block_with_input

  × Eval block failed with pipeline input
   ╭─[source:1:2]
 1 │ [1 2] | each {|x| $x / 0 }
   ·  ┬
   ·  ╰── source value
   ╰────

Error: nu::shell::division_by_zero

  × Division by zero.
   ╭─[source:1:22]
 1 │ [1 2] | each {|x| $x / 0 }
   ·                      ┬
   ·                      ╰── division by zero
   ╰────
```

After:

```nushell
> [1 2] | each {|x| $x / 0 }
Error: nu::shell::division_by_zero

  × Division by zero.
   ╭─[source:1:2]
 1 │ [1 2] | each {|x| $x / 0 }
   ·  ┬                   ┬
   ·  │                   ╰── division by zero
   ·  ╰── source value
   ╰────
```


## Additional notes

Two fixes for code running inside these closures:

- `exit` works. `[1] | each { exit 4 }` exits with 4, and `try { [1] |
each { exit 4 } } catch { ... }` no longer runs the `catch` block.
- An external's exit code survives. `try { [1] | each { ^sh -c 'exit 42'
} } catch {|e| $e.exit_code }` is `42`, and so is `$env.LAST_EXIT_CODE`.

Scripts that matched the code `nu::shell::eval_block_with_input`, or
read `$e.details.inner.0` to reach the closure's error, should use
`$e.msg` / `$e.details.msg` instead
2026-10-16 06:12:44 -05:00
Darren Schroeder bd30843743 fix(startup): time nushell from main like bash and zsh, fix exec (#19136)
## Description

This PR fixes two problems with `$nu.startup-time` reported on Discord.

1. **It grew after every `exec nu`.** While probably more accurate,
#19049 counted the time before `main` by reading what the kernel records
for the process, but it turned out to be a problem since `exec` replaces
the program but keeps the process, so the time would carry over, getting
larger with each `exec` which made it no longer correct.

2. **It was `-1ns` in many places.** The value started at `-1` and was
only set when the REPL drew its first prompt, or when `-c` commands or a
script started running.
 
So, I did some research to figure out how other shells, namely bash,
zsh, and fish, count startup time.

### How other shells time themselves

None that I checked reads the process creation time. Each starts its
clock inside the shell:

- **bash** sets `shellstart` with `gettimeofday` near the top of `main`
(`shell.c`). That is before option parsing and before it takes control
of the terminal for job control.
- **zsh** 5.9 sets `shtimer` with `gettimeofday` in `setupvals()`, after
`init_io()` has taken control of the terminal. `$SECONDS` counts from
it.
- **fish** has no startup-time value. `--profile-startup` times each
startup command with its own wall clock.

Nushell now does the same as bash: the clock starts on the first line of
`main` with the monotonic `Instant`. It leaves out the time the OS
spends starting the executable, and `exec nu` starts a new count. Like
bash, nushell counts the time an interactive `nu &` waits to be brought
to the foreground before it can take the terminal; zsh doesn't.

## User-facing changes (Release notes)

- `$nu.startup-time` is now measured from the moment Nushell starts
running, the same way bash and zsh time themselves. It no longer
includes the time the operating system spends loading the executable and
its libraries (about 7–9ms on macOS), on all platforms.
- Fixed `$nu.startup-time` growing every time `exec nu` replaced the
current shell on macOS and Linux.
- Fixed `$nu.startup-time` showing `-1ns` in config files, `-e`
commands, `--mcp`, `--lsp`, `--dap` and `--ide-check`. Before startup
finishes, it now shows the startup time so far.
- `--ide-hover`, `--ide-complete`, `--ide-goto-def` and `--ide-ast` now
see `$nu`, so hovering a constant built from it shows its type and
`$nu.` completes its columns.
- Fixed `$nu.is-mcp` being `false` in config files loaded by `nu --mcp`.
- `--log-level perf` no longer prints a "before main" line. Its final
REPL line is now "startup (main to first prompt)", and the
`--mcp`/`--lsp` start lines no longer include the whole session.

## Additional notes

- API changes for embedders:
`EngineState::get_startup_time`/`set_startup_time` are replaced by
`startup_time`, `set_startup_start` and `finish_startup`, and
`nu_cli::evaluate_repl` no longer takes a start time.
2026-10-02 09:25:12 -05:00
user77 cbb333386d Don't print a stray blank line when try with catch or finally collects an external (#18811)
# Description

Fixes #18765. Byte for byte, before:

```
> nu -c "try { ^nu -c 'print hi' } catch {}" | od -c
0000000   h   i  \n  \n
```

and after:

```
0000000   h   i  \n
```

Since 7f69d752, a `try` block followed by `catch` or `finally` collects
the block's output first, so it can tell whether the block failed before
anything starts streaming. If the tried command is an external whose
stdout was not captured (it is inherited at the statement level, or
redirected to a file inside the block), the output has already left the
process by the time the collect runs. The collect then converted that
data-less child stream into an empty string value, and printing the
collected result rendered the empty string as an extra blank line.

The fix is in the shared `collect` helper in `eval_ir.rs`: when the
collected data is a byte stream whose child has no captured stdout, wait
for the child and produce `Empty`, which is exactly what the plain `try
{ }` path produces when it drains the same stream. Waiting keeps the
failure semantics: a non-zero exit still becomes an error, so `catch`
still runs (covered by a test).

Behavior that did not change, verified against an unpatched build:

- Value context still collects and trims the captured output: `let x =
(try { ^cmd } catch {})` still gives the trimmed string.
- `$env.LAST_EXIT_CODE` was not set by the collect path before and still
is not.

Credit where due: neurolag bisected the inconsistency to 7f69d752, and
weirdan showed it is the collection step that differs.

# User-Facing Changes

`try { ^external } catch { }` and `try { ^external } finally { }` no
longer print a stray blank line after the external's output. Collecting
an uncaptured external (for example `try { ^cmd o> file } catch {}` as
the value of an assignment) now produces nothing instead of an empty
string.

# Tests + Formatting

Added `try_catch_inherited_external_output_has_no_extra_blank_line` in
`tests/shell/mod.rs`. It spawns the real `nu` binary and compares raw
stdout bytes for the `catch`, `finally`, and `catch` plus `finally`
cases, plus a failing external to prove `catch` still runs. The `try`
sits in final statement position on purpose: only the final statement's
value is printed, so that is the position where the fabricated empty
string became visible. The test fails on current main with exactly the
extra `\n` and passes with this change.

- `cargo fmt --all -- --check` clean
- `cargo clippy --workspace --all-targets -- -D warnings` clean
- `shell::` suite 255 passed, `commands::try_::` suite 41 passed
(includes the pipefail experimental tests)
- `cargo check -p nu-engine --target wasm32-unknown-unknown
--no-default-features` compiles (the new block is gated on the `os`
feature)

# After Submitting

## Release notes summary - What our users need to know

`try` with a `catch` or `finally` block no longer prints a stray blank
line after an external command's output.
2026-09-02 08:10:22 -05:00
David Bateman 6b6a434f01 fix(env): normalize PATH when refreshing ENV_CONVERSIONS (#18832)
## Description
Refreshing `$env.ENV_CONVERSIONS` already reapplies configured
`from_string` conversions to string environment variables. However, the
built-in `PATH` normalization was only performed during startup, so an
importer such as `load-env` could leave `PATH` as a string after the
refresh.

This change makes the existing `ENV_CONVERSIONS` refresh path also
perform the built-in `PATH` normalization. It also documents the refresh
pattern on `load-env`:

  ```nushell
  direnv export json | from json | default {} | load-env
  $env.ENV_CONVERSIONS = $env.ENV_CONVERSIONS
  ```

Regression tests cover configured conversions on imported values and
platform-specific `PATH` normalization.

## User-facing changes (Release notes)

Refreshing `$env.ENV_CONVERSIONS` now also normalizes `PATH` into its
usual list form. The `load-env` help documents how to refresh
environment conversions after importing string values.

## Additional notes

Closes #18766
2026-09-02 08:08:38 -05:00
Darren Schroeder ef9a8d4c66 fix parsing performance regression (#18948)
## Description
When running this script (below), there was a significant slowdown in
parsing due to changes from #18538. The fix switched `source` /
`source-env` to `parse_fresh`, which never consults the span cache. That
is correct for files that close over outer `let`/`mut`. It is wasteful
for files that do not, which is most library `def` files.

```nushell
# ❯ source nu115-slowdown.nu
# nu version: 0.114.1
# ╭───┬───────┬──────────────────┬──────────────────╮
# │ # │ files │      total       │     per_file     │
# ├───┼───────┼──────────────────┼──────────────────┤
# │ 0 │     1 │ 14ms 705µs 131ns │ 14ms 705µs 131ns │
# │ 1 │    10 │ 15ms 911µs 958ns │  1ms 591µs 195ns │
# │ 2 │    20 │ 19ms 861µs 105ns │       993µs 55ns │
# │ 3 │    33 │ 26ms 750µs 384ns │      810µs 617ns │
# │ 4 │    50 │ 38ms 724µs 925ns │      774µs 498ns │
# │ 5 │    63 │ 51ms 904µs 669ns │      823µs 883ns │
# ╰───┴───────┴──────────────────┴──────────────────╯

# ❯ source nu115-slowdown.nu
# nu version: 0.115.1
# ╭───┬───────┬───────────────────┬──────────────────╮
# │ # │ files │       total       │     per_file     │
# ├───┼───────┼───────────────────┼──────────────────┤
# │ 0 │     1 │  11ms 711µs 291ns │ 11ms 711µs 291ns │
# │ 1 │    10 │  38ms 981µs 814ns │  3ms 898µs 181ns │
# │ 2 │    20 │  82ms 885µs 427ns │  4ms 144µs 271ns │
# │ 3 │    33 │  191ms 51µs 643ns │  5ms 789µs 443ns │
# │ 4 │    50 │ 396ms 705µs 337ns │  7ms 934µs 106ns │
# │ 5 │    63 │ 630ms 736µs 252ns │  10ms 11µs 686ns │
# ╰───┴───────┴───────────────────┴──────────────────╯

let exe = $nu.current-exe
print $"nu version: (version | get version)"

1..300 | each {|i| $"def shared($i) [] { 0 }" } | str join (char nl) | save -f common.nu
1..63  | each {|i| $"def outer($i) [] { 0 }(char nl)source common.nu" | save -f $"f($i).nu" } | ignore

[1 10 20 33 50 63] | each {|n|
  1..$n | each {|i| $"source f($i).nu" } | str join (char nl) | save -f loader.nu
  let t = (timeit { ^$exe --no-config-file -c "source loader.nu; exit" })
  {files: $n, total: $t, per_file: ($t / $n)}
}
```

After this PR `source` / `source-env` go through `parse()` again. A
cached block is reused only when it is safe. Stale captures fall through
and parse fresh. That is the #18515 path. Empty-capture libraries hit
the cache. That is the 0.114 path.

## User-facing changes (Release notes)

### Faster repeated `source` of the same file

0.115 started re-parsing every `source` / `source-env` of a file that
had already been parsed, so configs and libraries that `source` the same
helpers many times got slower as more files were loaded. A 63-file case
that stayed around 50ms in 0.114 grew to hundreds of milliseconds.

After this PR `source` / `source-env` go through `parse()` again. A
cached block is reused only when it is safe. Stale captures fall through
and parse fresh. That is the #18515 path. Empty-capture libraries hit
the cache. That is the 0.114 path.

## Additional notes
Fixes an issue reported on Discord
closes https://github.com/nushell/nushell/issues/18926
2026-09-02 07:44:49 -05:00
Darren Schroeder 15268e32db allow parameters with # to be passed (#18782)
## Description

This PR fixes a bug where `"#00abcd"` couldn't be passed as a parameter
because `#` indicates to nushell that a comment is following.

## User-facing changes (Release notes)

Quotes strings with `"#"` in them like `"#00abcd"` are now allowed to be
passed as parameters.

### Example
A script named test.nu
```nushell
def main [color: string] {
  $"Your color is ($color)"
}
```
Then pass a hex color as a parameter.
```nushell
❯ let myColor = "#000000"
❯ nu test.nu $myColor
Your color is #000000
❯ nu test.nu "#abcdef"
Your color is #abcdef
```

## Additional notes

closes https://github.com/nushell/nushell/issues/18778
2026-08-07 07:02:03 -05:00
Piepmatz e08c27a424 More updated tests (#18768)
<!--
Thanks for contributing to Nushell!

Before submitting, please read the contributing guide:
https://github.com/nushell/nushell/blob/main/CONTRIBUTING.md

This template helps reviewers understand your changes and allows us to
generate high-quality release notes.
-->

## Description
<!--
Explain what this PR does and why.

This section is intentionally flexible:
- Describe the problem
- Explain your approach
- Include technical details if relevant

Good examples:
- "In this PR, I fixed..."
- "In this PR, I added support for..."
- "This change improves X by..."

Write as much or as little as needed for reviewers to understand your
changes.
-->
Well, another batch of updated tests.

## User-facing changes (Release notes)
<!--
This section is used (mostly as-is) for https://www.nushell.sh/blog/

Describe how Nushell behavior changes from a user's perspective.
Do NOT describe internal Rust changes here.

Write in a release note style, for example:
- "Added support for..."
- "Fixed an issue where..."
- "Nushell now supports..."
- "Improved performance of..."

If your changes do NOT affect users (internal refactors, cleanup, etc.),
just write:
- "n/a"
- "nan"
- or similar

This tells us the change should not appear in the changelog.

Tips:
- Focus on observable behavior
- Include examples if helpful
- Keep it concise

You can:
- Write a short paragraph (will appear as a bullet point), OR
- Use headings (###) if your change needs more structure

Avoid writing things like:
- "In this PR, I refactored..."
- "This updates internal code..."

You may leave this blank until the PR is ready.
-->
n/a
2026-08-02 03:52:40 +02:00
Darren Schroeder 30cf02c8e3 The source command no longer breaks variable visibility (#18538)
## Description
This PR fixes a problem when a script or REPL input used `source` to run
a `.nu` file, variables defined before the `source` call could become
invisible inside the sourced file, producing a "variable not found"
error.

Two distinct mechanisms contributed to the bug:

1. Double-parse in `evaluate_file`. The first parse stored blocks from
`source` with one set of `VarId`s. The second prase created _new_
`VarId`s for `let`/`mut` declarations. The `source` results were cached
but referenced the old `VarId`s.

2. Cross-session block caching in the parser -
`find_block_by_span(new_span)` in `parse_captures_compile` was called to
avoid re-parsing files that had already been parsed. This cached data
was stored in the permanent state. In the repl, if `let xxx` was
redeclared (getting a new varid), the cached block was used referencing
the old varid.

## User-facing changes (Release notes)
Fixes the bugs found when a script or REPL input used `source` to run a
`.nu` file, variables defined before the `source` call could become
invisible inside the sourced file, producing a "variable not found"
error.

**Example reproducing the bug** — script file `lll.nu`:

```nushell
let xxx = 'let in script'
source sss.nu
```

Where `sss.nu` contains:

```nushell
print $xxx
```

Running `nu lll.nu` would fail with:

```nushell
Error: nu::shell::variable_not_found

  × Variable not found
   ╭─[sss.nu:1:7]
 1 │ print $xxx
   ·       ──┬─
   ·         ╰── variable not found
   ╰────
```

The same error could also appear in the REPL after re-declaring a
variable:

```nushell
❯ let xxx = 'value 1'
❯ source sss.nu    # OK: prints "value 1"
❯ let xxx = 'value 2'
❯ source sss.nu    # Error: variable not found
```
After this change the last statement above would print `value 2`. See
the tests and the issue to see more variations.

## Additional notes

closes https://github.com/nushell/nushell/issues/18515
2026-07-29 16:53:32 -05:00
Piepmatz c70ebfe228 Update internal commands tests (#18718)
<!--

Thanks for contributing to Nushell!



Before submitting, please read the contributing guide:

https://github.com/nushell/nushell/blob/main/CONTRIBUTING.md



This template helps reviewers understand your changes and allows us to
generate high-quality release notes.

-->



## Description

<!--

Explain what this PR does and why.



This section is intentionally flexible:

- Describe the problem

- Explain your approach

- Include technical details if relevant



Good examples:

- "In this PR, I fixed..."

- "In this PR, I added support for..."

- "This change improves X by..."



Write as much or as little as needed for reviewers to understand your
changes.

-->
This PR updates the internal commands tests. This is, next to #18717,
also a very large file. So it got separated into its own PR too.


## User-facing changes (Release notes)

<!--

This section is used (mostly as-is) for https://www.nushell.sh/blog/



Describe how Nushell behavior changes from a user's perspective.

Do NOT describe internal Rust changes here.



Write in a release note style, for example:

- "Added support for..."

- "Fixed an issue where..."

- "Nushell now supports..."

- "Improved performance of..."



If your changes do NOT affect users (internal refactors, cleanup, etc.),

just write:

- "n/a"

- "nan"

- or similar



This tells us the change should not appear in the changelog.



Tips:

- Focus on observable behavior

- Include examples if helpful

- Keep it concise



You can:

- Write a short paragraph (will appear as a bullet point), OR

- Use headings (###) if your change needs more structure



Avoid writing things like:

- "In this PR, I refactored..."

- "This updates internal code..."



You may leave this blank until the PR is ready.

-->
n/a

---

<sub>Stack created with <a
href="https://github.com/github/gh-stack">GitHub Stacks CLI</a> • <a
href="https://gh.io/stacks-feedback">Give Feedback 💬</a></sub>
2026-07-26 20:08:40 +02:00
Piepmatz 69d6beb8bf Update external commands tests (#18717)
<!--

Thanks for contributing to Nushell!



Before submitting, please read the contributing guide:

https://github.com/nushell/nushell/blob/main/CONTRIBUTING.md



This template helps reviewers understand your changes and allows us to
generate high-quality release notes.

-->



## Description

<!--

Explain what this PR does and why.



This section is intentionally flexible:

- Describe the problem

- Explain your approach

- Include technical details if relevant



Good examples:

- "In this PR, I fixed..."

- "In this PR, I added support for..."

- "This change improves X by..."



Write as much or as little as needed for reviewers to understand your
changes.

-->
This PR updates the external commands tests. This file is pretty large
and therefore separated into its own PR.


## User-facing changes (Release notes)

<!--

This section is used (mostly as-is) for https://www.nushell.sh/blog/



Describe how Nushell behavior changes from a user's perspective.

Do NOT describe internal Rust changes here.



Write in a release note style, for example:

- "Added support for..."

- "Fixed an issue where..."

- "Nushell now supports..."

- "Improved performance of..."



If your changes do NOT affect users (internal refactors, cleanup, etc.),

just write:

- "n/a"

- "nan"

- or similar



This tells us the change should not appear in the changelog.



Tips:

- Focus on observable behavior

- Include examples if helpful

- Keep it concise



You can:

- Write a short paragraph (will appear as a bullet point), OR

- Use headings (###) if your change needs more structure



Avoid writing things like:

- "In this PR, I refactored..."

- "This updates internal code..."



You may leave this blank until the PR is ready.

-->
n/a

---

<sub>Stack created with <a
href="https://github.com/github/gh-stack">GitHub Stacks CLI</a> • <a
href="https://gh.io/stacks-feedback">Give Feedback 💬</a></sub>
2026-07-26 20:08:39 +02:00
Piepmatz 94d06fa302 Refactor most test files that used nu --testbin (#18713)
<!--

Thanks for contributing to Nushell!



Before submitting, please read the contributing guide:

https://github.com/nushell/nushell/blob/main/CONTRIBUTING.md



This template helps reviewers understand your changes and allows us to
generate high-quality release notes.

-->



## Description

<!--

Explain what this PR does and why.



This section is intentionally flexible:

- Describe the problem

- Explain your approach

- Include technical details if relevant



Good examples:

- "In this PR, I fixed..."

- "In this PR, I added support for..."

- "This change improves X by..."



Write as much or as little as needed for reviewers to understand your
changes.

-->
`nu --testbin` is going to be removed by #18719, so this PR starts by
refactoring all tests that call `nu --testbin` in some way. Not only are
these tests refactored but then the whole file. Instead of calling `nu
--testbin`, the relevant `#[deps(TESTBIN_x)]` is annotated on the test
and the test binary is called directly.

The files in this PR are the smaller ones, the larges ones are in
seperate PRs up the stack.


## User-facing changes (Release notes)

<!--

This section is used (mostly as-is) for https://www.nushell.sh/blog/



Describe how Nushell behavior changes from a user's perspective.

Do NOT describe internal Rust changes here.



Write in a release note style, for example:

- "Added support for..."

- "Fixed an issue where..."

- "Nushell now supports..."

- "Improved performance of..."



If your changes do NOT affect users (internal refactors, cleanup, etc.),

just write:

- "n/a"

- "nan"

- or similar



This tells us the change should not appear in the changelog.



Tips:

- Focus on observable behavior

- Include examples if helpful

- Keep it concise



You can:

- Write a short paragraph (will appear as a bullet point), OR

- Use headings (###) if your change needs more structure



Avoid writing things like:

- "In this PR, I refactored..."

- "This updates internal code..."



You may leave this blank until the PR is ready.

-->
n/a

---

<sub>Stack created with <a
href="https://github.com/github/gh-stack">GitHub Stacks CLI</a> • <a
href="https://gh.io/stacks-feedback">Give Feedback 💬</a></sub>
2026-07-26 20:08:38 +02:00
Piepmatz 189141a2b2 Update some more tests that used nu_repl_code (#18649)
<!--

Thanks for contributing to Nushell!



Before submitting, please read the contributing guide:

https://github.com/nushell/nushell/blob/main/CONTRIBUTING.md



This template helps reviewers understand your changes and allows us to
generate high-quality release notes.

-->



## Description

<!--

Explain what this PR does and why.



This section is intentionally flexible:

- Describe the problem

- Explain your approach

- Include technical details if relevant



Good examples:

- "In this PR, I fixed..."

- "In this PR, I added support for..."

- "This change improves X by..."



Write as much or as little as needed for reviewers to understand your
changes.

-->
This PR updates some more test to the new harness by replacing
`nu_repl_code` and `nu!`.

This set of tests is grouped together, as they did use `nu_repl_code` in
some capacity. After this PR no more `nu_repl_code` should be used
anywhere.


## User-facing changes (Release notes)

<!--

This section is used (mostly as-is) for https://www.nushell.sh/blog/



Describe how Nushell behavior changes from a user's perspective.

Do NOT describe internal Rust changes here.



Write in a release note style, for example:

- "Added support for..."

- "Fixed an issue where..."

- "Nushell now supports..."

- "Improved performance of..."



If your changes do NOT affect users (internal refactors, cleanup, etc.),

just write:

- "n/a"

- "nan"

- or similar



This tells us the change should not appear in the changelog.



Tips:

- Focus on observable behavior

- Include examples if helpful

- Keep it concise



You can:

- Write a short paragraph (will appear as a bullet point), OR

- Use headings (###) if your change needs more structure



Avoid writing things like:

- "In this PR, I refactored..."

- "This updates internal code..."



You may leave this blank until the PR is ready.

-->
n/a




---

<sub>Stack created with <a
href="https://github.com/github/gh-stack">GitHub Stacks CLI</a> • <a
href="https://gh.io/stacks-feedback">Give Feedback 💬</a></sub>
2026-07-26 20:08:37 +02:00
BahexandTim 'Piepmatz' Hesse f852cac740 Update some tests to use the new test infra (#18651)
## Description

- Enabled `pretty_assertions`'s `unstable` feature to get
`assert_matches!` (the stdlib version is available in 1.96)
- Tried to keep most tests 1:1, though I made some significant changes
here and there.

## User-facing changes (Release notes)
N/A

---------

Co-authored-by: Tim 'Piepmatz' Hesse <git+github@cptpiepmatz.de>
2026-07-18 21:58:58 +03:00
Piepmatz 8c4aeb7349 Add test dependencies via test attribute #[deps(...)] (#18570) 2026-07-11 23:10:41 +02:00
Bahex 8560eef575 fix: assigment errors point to the assigment (#18531)
## Description

- #16832

Errors raised for assignment errors did not point to the relevant
assignment, just pointed to the values origin.

## User-facing changes (Release notes)

### More helpful errors for failed assignments with
`enforce-runtime-annotations`

With `enforce-runtime-annotations` enabled, assignments with incorrect
types raise errors.

Previously this error was `nu::shell::cant_convert` originally used for
unsuccessful type coercions of command arguments. Unfortunately, this
error only pointed at the assigned values *origin* and not at the failed
assignment.

This error has been switched to `nu::shell::type_mismatch` and now
points to the failed assignment in addition to the value's origin.

##### example 1
<table>
<tr>
<td>Code</td>
<td width="1000">

```nushell
mut execution_time = -1
$execution_time = $env.CMD_DURATION_MS
```

</td>
</tr>

<tr>
<td>Before</td>
<td>

```
Error: nu::shell::cant_convert

  × Can't convert to int.
   ╭─[Host Environment Variables:1:1]
 1 │ "LANG"="en_US.UTF-8"
   · ▲
   · ╰── can't convert string to int
 2 │ "LC_TIME"="en_DK.UTF-8"
   ╰────
```

</td>
</tr>

<tr>
<td>After</td>
<td>

```
Error: nu::shell::type_mismatch

  × Type mismatch.
   ╭─[repl_entry #3:2:17]
 1 │ mut execution_time = -1
 2 │ $execution_time = $env.CMD_DURATION_MS
   ·                 ┬
   ·                 ╰── expected int, got string
   ╰────
```

</td>
</tr>
</table>

##### example 2
<table>
<tr>
<td>Code</td>
<td width="1000">

```nushell
# delibarete type erasure
# we need to bypass parse-time
# type checking for this example
let stuff: any = {
	foo: "bar"
}

mut x = 1

$x = $stuff.foo
```

</td>
</tr>

<tr>
<td>Before</td>
<td>

```
Error: nu::shell::cant_convert

  × Can't convert to int.
   ╭─[repl_entry #7:5:7]
 4 │ let stuff: any = {
 5 │     foo: "bar"
   ·          ──┬──
   ·            ╰── can't convert string to int
 6 │ }
   ╰────
```

</td>
</tr>

<tr>
<td>After</td>
<td>

```
Error: nu::shell::type_mismatch

  × Type mismatch.
    ╭─[repl_entry #1:5:7]
  4 │ let stuff: any = {
  5 │     foo: "bar"
    ·          ──┬──
    ·            ╰── the value is a string
  6 │ }
  7 │ 
  8 │ mut x = 1
  9 │ 
 10 │ $x = $stuff.foo
    ·    ┬
    ·    ╰── expected int, got string
    ╰────
```

</td>
</tr>
</table>

## Additional notes

- This should make it much easier to diagnose problems described in
#18528
2026-07-07 01:37:52 +03:00
Tyarel8 7c3be8c4ac delete deprecated stdlib copy and paste (#18403)
## Description
Removed the copy/paste command from stdlib that were deprecated in
`0.111.0`. I think it makes sense to remove these sooner rather than
later since it can be confusing that they have the exact same name as
the ones in the "new" `native-clip` experimental option.

## User-facing changes (Release notes)
<!--
This section is used (mostly as-is) for https://www.nushell.sh/blog/

Describe how Nushell behavior changes from a user's perspective.
Do NOT describe internal Rust changes here.

Write in a release note style, for example:
- "Added support for..."
- "Fixed an issue where..."
- "Nushell now supports..."
- "Improved performance of..."

If your changes do NOT affect users (internal refactors, cleanup, etc.),
just write:
- "n/a"
- "nan"
- or similar

This tells us the change should not appear in the changelog.

Tips:
- Focus on observable behavior
- Include examples if helpful
- Keep it concise

You can:
- Write a short paragraph (will appear as a bullet point), OR
- Use headings (###) if your change needs more structure

Avoid writing things like:
- "In this PR, I refactored..."
- "This updates internal code..."

You may leave this blank until the PR is ready.
-->
Removed the deprecated `use std/clip` `copy` and `paste` commands, they
are now called `copy52` and `paste52` for the ones that use the terminal
`OSC 52`, or you can use `clip copy` and `clip paste` from the
experimental option `native-clip` that access the system clipboard
directly.

<!--
Optional.

Examples:
- fixes #123
- closes #456
- related #789

Anything else reviewers should know.
Remove this section if not needed.
-->
2026-06-13 07:49:11 -05:00
Bahex 802eb44d90 test: stderr/stdout full tests should not read user config (#18253)
## Description

Reading my config (which had some elaborate startup code) caused these
tests to fail. Likely because of `term query` calls.

## User-facing changes (Release notes)
N/A

## Additional notes

Tests being affected by user config is unfortunately a reoccurring
issue.

We should consider setting `XDG_{CONFIG,DATA,CACHE}_HOME` and
`XDG_DATA_DIRS` to empty directories during tests to avoid this problem
all together rather than patching it on a test by test basis.
2026-05-20 12:24:12 +03:00
Piepmatz 462ffde0f8 Fix CI not executing all tests on Windows (#18211) 2026-05-16 15:54:00 +02:00
Darren Schroeder fbe85c70c2 fix(repl): improve error handling and cleanup on unexpected errors (#18210)
<!--
Thanks for contributing to Nushell!

Before submitting, please read the contributing guide:
https://github.com/nushell/nushell/blob/main/CONTRIBUTING.md

This template helps reviewers understand your changes and allows us to
generate high-quality release notes.
-->

## Description
This PR improves repl error handling when being redirected.
<!--
Explain what this PR does and why.

This section is intentionally flexible:
- Describe the problem
- Explain your approach
- Include technical details if relevant

Good examples:
- "In this PR, I fixed..."
- "In this PR, I added support for..."
- "This change improves X by..."

Write as much or as little as needed for reviewers to understand your
changes.
-->

## User-facing changes (Release notes)
Improve repl error handling when redirected like `nu > /dev/full` or `nu
2>/dev/full`.

<!--
This section is used (mostly as-is) for https://www.nushell.sh/blog/

Describe how Nushell behavior changes from a user's perspective.
Do NOT describe internal Rust changes here.

Write in a release note style, for example:
- "Added support for..."
- "Fixed an issue where..."
- "Nushell now supports..."
- "Improved performance of..."

If your changes do NOT affect users (internal refactors, cleanup, etc.),
just write:
- "n/a"
- "nan"
- or similar

This tells us the change should not appear in the changelog.

Tips:
- Focus on observable behavior
- Include examples if helpful
- Keep it concise

You can:
- Write a short paragraph (will appear as a bullet point), OR
- Use headings (###) if your change needs more structure

Avoid writing things like:
- "In this PR, I refactored..."
- "This updates internal code..."

You may leave this blank until the PR is ready.
-->

## Additional notes
closes https://github.com/nushell/nushell/issues/18208
closes https://github.com/nushell/nushell/issues/18209
<!--
Optional.

Examples:
- fixes #123
- closes #456
- related #789

Anything else reviewers should know.
Remove this section if not needed.
-->
2026-05-15 09:10:57 -05:00
Darren SchroederandTim 'Piepmatz' Hesse 4b1aca5239 feat: enhance script argument parsing to handle newlines and whitespace correctly (#17826)
Co-authored-by: Tim 'Piepmatz' Hesse <git+github@cptpiepmatz.de>
2026-03-27 10:56:35 +01:00
Piepmatz b36b7eea26 Warn on clippy::needless_raw_strings (#17822)
<!--
Thank you for improving Nushell!
Please, read our contributing guide:
https://github.com/nushell/nushell/blob/main/CONTRIBUTING.md
-->

This PR enables the clippy lint `needless_raw_strings` to avoid raw
strings where they aren't needed. We have a lot of them and I don't
think that's that nice tbh.

## Release notes summary - What our users need to know
<!--
This section will be included as part of our release notes. See the
contributing guide for more details.
Please include only details relevant for users here. Motivation and
technical details can be added above or below this section.

You may leave this section blank until your PR is finalized. Ask a core
team member if you need help filling this section.
-->
n/a
2026-03-17 01:42:03 +01:00
Piepmatz b6a7a2f2d3 Enable env_shlvl_in_repl and env_shlvl_in_exec_repl tests (#17803) 2026-03-15 00:45:22 +01:00
Darren Schroeder 403ec4ee8a fix duplicate custom commands from showing up (#17727) 2026-03-05 13:28:17 -06:00
Chris Denton 03f0cc21a4 Prefer PWD over current_dir if they're the same directory (#17720) 2026-03-05 10:55:29 -06:00
Piepmatz 8a5bf67592 Move native clip commands behind an experimental option (#17664) 2026-02-27 16:59:57 +01:00
2bc9c4b4ac Custom subcommand help (#17610)
Co-authored-by: Motalleb Fallahnezhad <fmotalleb@dornica.net>
Co-authored-by: Motalleb Fallahnezhad <fmotalleb@gmail.com>
2026-02-24 10:25:20 -06:00
Darren Schroeder 28cd326ec3 abstract env var names so they're insensitive on windows and sensitive on other operating systems (#17558)
There are some edge cases when working with environment variables. So, I
took the opportunity in this PR to refactor how nushell handles env
vars. All environment variables across all operating systems and
case-insensitive for lookups and case-preserving for storage.

This is how it now works. All environment variable access goes through
EnvName in env_names.rs now, except for a few places that still need to
use `std::env::var()` type calls for initial nushell setup.

```
//! ## Case Sensitivity Rules
//!
//! - **All platforms**: All environment variable names are case-insensitive but case-preserving.
//!   This means `PATH`, `Path`, and `path` refer to the same variable, and so do `HOME` and `home`.
//!
//! This ensures that:
//! - `$env.PATH`, `$env.path`, `$env.Path` all work on any platform
//! - `$env.HOME`, `$env.home` all refer to the same variable
//! - Case is preserved when storing the variable name
//! - Existing scripts may need updates if they relied on case sensitivity
```

## Release notes summary - What our users need to know
All environment variables across all operating systems and
case-insensitive for lookups and case-preserving for storage.

## Tasks after submitting
<!-- Remove any tasks which aren't relevant for your PR, or add your own
-->
- [ ] Update the
[documentation](https://github.com/nushell/nushell.github.io)
2026-02-17 19:11:40 -06:00
Wind 7816ba9b7f pipefail: enable by default (#17449)
As title
It reveals somes issues, like breaking `do -i`. So this pr fixes it as
well.

I introduce a new type `ExitStatusGuard` which wraps both
`exit_stauts_future` and `ignore_error`. So we can check the status
easier.

## Release notes summary - What our users need to know
nushell will use `pipefail` by default, so something like `^false |
lines` returns an empty list, with a failure exit status code

## Tasks after submitting
NaN
2026-02-04 09:51:28 +08:00
Kai Sforza ddf80f3107 error_make: Another rewrite of error make (#17070)
## User-facing Changes

* New arguments! (`error make "hello"`)
* New parts for `error_struct`! (`error make {inner: [] labels: []
...}`)
* Pipeline inputs for chained errors! (`try {error make foo} catch
{error make bar}`)
* Pipeline inputs for normal errors! (`"help" | error make`)
* External errors! (`error make {src: {path: $nu.cofig-path} ...}`)
* Backwards compatibility!

### Arguments and Inputs

The main changes are in how the arguments are passed. Everything is
still backwards compatible with the old `error make` commands, there's
just a nice extra layer we get from the pipeline and a few new args
(that were already added in #17037). There are some new ways to
(hopefully intentionally) cause an error, such as using a naked `error
make`, pipelines from records and simple string input!

#### Inputs

Because `error make` will just make an error anyway, it can technically
take any input to make an error, but only properly formatted record
input will create a chain. the `x | f $in` pattern can be used for
string input, if that is more comfortable.

#### With no arguments

This is a completely new way to do this, with no arguments the `error
make` invocation is highlighted, along with a simple `originates from
here` message. This makes normal errors very easy to create without any
special message setup.

```
> error make
Error: nu::shell::error

  × originates from here
   ╭─[entry #4:1:1]
 1 │ error make
   · ──────────
   ╰────
```

#### Create a single argument

* With pipeline input: `{msg: foo} | error make`
* With an argument: `error make {msg: foo}`
* With a string argument: `error make foo`
```
Error: nu::shell::error

  × foo
   ╭─[entry #2:1:12]
 1 │ error make {msg: foo}
   ·            ──────────
   ╰────
```
#### Chaining errors together

These will automatically create a chain of errors, placing the pipeline
as an `inner` to the argument. This can very easily be used to get a bit
more detail in a try loop using the naked `error make`:

```
Error: nu::shell::error

  × originates from here
   ╭─[source:1:31]
 1 │ try {error make "foo"} catch {error make}
   ·                               ──────────
   ╰────

Error: nu::shell::error

  × foo
   ╭─[source:1:6]
 1 │ try {error make "foo"} catch {error make}
   ·      ──────────
   ╰────
```

Or with more complex errors:

* With both, combining the errors: `{msg: foo} | error make bar`
* With the raw error from try: `try {error make foo} catch {error make
bar}`

Both are equivalent to:
* `error make {msg: bar inner: [{msg: foo}]}`

```
Error: nu::shell::error

  × bar
   ╭─[entry #1:1:29]
 1 │ try {error make foo} catch {error make bar}
   ·                             ──────────
   ╰────

Error: nu::shell::error

  × foo
   ╭─[entry #1:1:6]
 1 │ try {error make foo} catch {error make bar}
   ·      ──────────
   ╰────
```

### Labels

As is noticeable in the examples above, simple errors no longer use an
extra line for the label. If no label is present, `error make` will
place a bar under the span of itself or the argument to `error make`.
Labels have also gotten a bit of a rewrite, but they're pretty much the
same as those in #17037, except for `label`, which is now only a single
label (not `oneof<list, label>`).
#### Simple Labels

`label.text` and `labels.*.text` is no longer required for a span to
show up, an empty text will simply underline. This example can either
use `label: $record` or be written as `labels: [$record]`:

```
> def f [x] {
  error make {msg: here label: {span: (metadata $x).span}}
}
f abcd
Error: nu::shell::error

  × here
   ╭─[entry #7:4:3]
 3 │ }
 4 │ f abcd
   ·   ────
   ╰────
```

#### Multiple labels
Any number of labels can be added in the `labels` column, allowing for
more detailed error messages, especially for functions:

```
> def f [x y z] {
  error make {msg: here labels: [
    {text: "there" span: (metadata $x).span}
    {text: "everywhere" span: (metadata $y).span}
    {text: "somewhere" span: (metadata $z).span}
  ]
  }
}
f abcd [x y z] {d: a}

Error: nu::shell::error

  × here
   ╭─[entry #11:9:3]
 8 │ }
 9 │ f abcd [x y z] {d: a}
   ·   ──┬─ ───┬─── ───┬──
   ·     │     │       ╰── somewhere
   ·     │     ╰── everywhere
   ·     ╰── there
   ╰────
```

#### External sources

There is a `ShellError::OutsideSpannedLabeledError` that can be used to
refer to external sources, not just the internal nushell spanns. This
has been expanded to allow the multi-label stuff to work using the new
`src` column:

```
> "foo\nbar\nbaz" | save -f /tmp/foo.bar
error make {
  msg: 'error here'
  src: {path: /tmp/foo.bar}
  labels: [
    {text: "this" span: {start: 4 end: 7}}
  ]
}
Error: nu::shell::outside

  × error here
   ╭─[/tmp/foo.bar:2:1]
 1 │ foo
 2 │ bar
   · ─┬─
   ·  ╰── this
 3 │ baz
   ╰────
```

### Errors That Can't be Caught

These will not work since `try` will never get parsed:

- `try {1 + ""} catch {error make badmath}`
- (TODO: Add more examples)

## Internal Changes

Most of the parsing from an error record to an actual error is now moved
into `nu-protocol`, using `FromValue` to turn it into a useful internal
type.

### `nu-protocol::LabeledError`

This struct has a few changes, the main one being the type of
`LabeledError.inner`. It is now a `ShellError`, not another
`LabeledError`. It should be trivial to do a `.into()` for things that
already use `LabeledError.with_inner(x)`.

### `nu-protocol::ShellError::into_value`

I renamed the old `into_value` to `into_full_value` to better say what
it is, since it doesn't just do the `IntoValue::into_value` method, it
also requires some context to create the `Value`. Now `ShellError` has
an `IntoValue` implementation matching other types.

### `nu-protocol::ShellError::{OutsideSource, OutsideSourceNoUrl}`

Miette's derived types don't have a nice way to maybe include a url, so
there are now two types! These allow using multiple labels on outside
sources. They are used internally for the new `{src: {}}` part of the
`error_struct`, and they look a lot more like the `LabeledError`, but
without the need for a separate type and all the fun `impl`s that would
require for the `Diagnostic::source_code` method.

### Misc

* Spelling fix: `into_chainned` => `into_chained`

## Current bugs:
- [x] `OutsideSpannedLabeledError`  
The inner most error of `try {']' from nuon} catch {error make}` will
reference `span: {start: 0, end: 1}`, which in `']' from nuon` will
point to the `]` character, but when it does this in `error make` as an
input it will point to the very first character (probably the `n` in
`nu`).

## Release notes summary - What our users need to know

### New `error make` functionality!
* New arguments! (`error make "hello"`)
* New parts for `error_struct`! (`error make {inner: [] labels: []
...}`)
* Pipeline inputs for chained errors! (`try {error make foo} catch
{error make bar}`)
* Pipeline inputs for normal errors! (`"help" | error make`)
* External errors! (`error make {src: {path: $nu.cofig-path} ...}`)
* Backwards compatibility!


## Tasks after submitting
<!-- Remove any tasks which aren't relevant for your PR, or add your own
-->
- [ ] Update the
[documentation](https://github.com/nushell/nushell.github.io)
2025-12-18 07:34:08 -06:00
Wind 65e710b02c Making --env-config and --config errors lead to error status code when running nu scripts or commands. (#17103)
Fixes: #14745

## Release notes summary - What our users need to know
If user runs script or command with a bad config file, the script or
command won't run.
```
echo 'errnocmd' | save config.nu
nu --config config.nu -c 'echo $env.NU_VERSION'
```

won't show nushell version and exits with status code 1.
2025-12-05 09:12:20 +08:00
Kai Sforza a1f54c5637 Fix up the env.rs tests (#17085)
Just uses `ends-with` and a prefix to skip the control characters at the
start of the strings

This fixes the issues that came up in #17038 for being run in terminals.
This doesn't fix the underlying issue, however it does allow tests to be
run in certain terminals and still pass.

This also fixes a problem with some of the tests that load `std/log`. If
`$env.NU_LOG_FORMAT` is set in the parent shell, then these tests will
incorrectly fail. Clearing the env out before running makes these work.

<!--
Thank you for improving Nushell!
Please, read our contributing guide:
https://github.com/nushell/nushell/blob/main/CONTRIBUTING.md
-->

## Release notes summary - What our users need to know
<!--
This section will be included as part of our release notes. See the
contributing guide for more details.
Please include only details relevant for users here. Motivation and
technical details can be added above or below this section.

You may leave this section blank until your PR is finalized. Ask a core
team member if you need help filling this section.
-->

## Tasks after submitting
<!-- Remove any tasks which aren't relevant for your PR, or add your own
-->
- [ ] Update the
[documentation](https://github.com/nushell/nushell.github.io)
2025-12-04 11:12:28 -06:00
Wind 1025ddb322 make pipefail works with let (#16879)
This pr address comment by @132ikl :
https://github.com/nushell/nushell/issues/16760#issuecomment-3344409581

After visiting IR of `let x = ^false | into int`:
```
# 2 registers, 8 instructions, 5 bytes of data
   0: load-literal           %1, glob-pattern("false", no_expand = false)
   1: push-positional        %1
   2: redirect-out           pipe
   3: call                   decl 142 "run-external", %0
   4: redirect-out           value
   5: call                   decl 299 "into int", %0
   6: store-variable         var 320, %0 # let
   7: return                 %0
```
Nushell runs `store-variable` instruction, which collect values from
registry through `collect_reg`. This pr adds `check_exit_status_future`
logic inside `collect_reg` to make pipefail works with `let`.

## Release notes summary - What our users need to know
### pipefail works well with `let`
```
let x = bash -c "echo 123; exit 1" | into int; $x
Error: nu::shell::non_zero_exit_code

  × External command had a non-zero exit code
   ╭─[entry #28:1:9]
 1 │ let x = bash -c "echo 123; exit 1" | into int; $x
   ·         ──┬─
   ·           ╰── exited with code 1
   ╰────
```
2025-10-17 10:51:45 -04:00
Bahex f21fd3b109 big testing refactor (#16802)
- refactored how `nu!` executes commands
- commands are no longer split into lines and joined with semicolons,
they are passed verbatim to nu
  - removes the need for `pipeline()` 
- **Removed built-in string formatting from `nu!`**. Going through almost
all uses of `nu!` across the code base it became clear that:
  - built-in formatting is rarely used
  - most people are not aware of it and use `format!` anyway
- it can't be used with `"{inline}"` arguments because it's only
activated if there are extra arguments after the nu code string

## Release notes summary - What our users need to know
N/A

## Tasks after submitting
N/A
2025-10-09 13:31:53 +03:00
Windandrose f712c37009 Try to implement pipefail feature (#16449)
Closes: #13817

The core requirement here is to have a way to track all exit status in a
pipeline. To achieve this without affecting command itself.

I created a new struct in `pipeline_data.rs`:
```rust
pub struct PipelineExecutionData {
    pub body: PipelineData,
    /// This field is using to track all exit status in a pipeline.
    pub exit: Vec<Option<(Arc<Mutex<ExitStatusFuture>>, Span)>>,
}
```

Then I changed registers in `EvalContext` from `&'a mut [PipelineData]`
to `&'a mut [PipelineExecutionData]`. So the eval engine itself can
track exit status.
Then during evaluation, when nushell is going to execute
`Instruction::Call`. It takes `input.exit` first, then attach this into
`results.exit`. This is similar to the way nushell implements backtrace
feature.

After all of this, when nushell executes `Instruction::Drain`, or
printing pipeline. It iterates through *exit_futures* reversely. To see
if a command exits with non-zero status.

## Release notes summary - What our users need to know
This release will be add an experimental option for `pipefail`. This can
be set using `nu --experimental-options=['pipefail']`
> If set, the LAST_EXIT_CODE will be set to any command which exit with
a non-zero status, or zero if all commands in the pipeline exit
successfully.
```nushell
> ^false | print aa
aa
> $env.LAST_EXIT_CODE
1
```
It'd be more interesting if using it with
`$env.config.display_errors.exit_code = true`. Show users are able to
see which command is failed.
```nushell
> $env.config.display_errors.exit_code = true
> ^ls | ^false | print aa
aa
Error: nu::shell::non_zero_exit_code

  × External command had a non-zero exit code
   ╭─[entry #5:1:8]
 1 │ ^ls | ^false | print aa
   ·        ──┬──
   ·          ╰── exited with code 1
   ╰────
```

## Tasks after submitting
- [ ] Update the
[documentation](https://github.com/nushell/nushell.github.io)

---------

Co-authored-by: rose <132@ikl.sh>
2025-09-07 21:21:13 -04:00