Commit Graph

10515 Commits

Author SHA1 Message Date
3fe9c7c00c feat(each): noop on single null input, map-null equivalent (#16396)
# Description
Basically, now `null | each { "something" }` will be `null` instead of
`"something"`. Thanks to this, `each` can be used to map values similar
to `map-null` custom commands, for example:
- Before
```nu
let args = if $delay != null {
    ["--delay" ($delay | format duration sec | parse '{secs} {_}' | get 0.secs)]
} else {
    []
}
```
- After
```nu
let args = (
    $delay
    | each { ["--delay" ($in | format duration sec | parse '{secs} {_}' | get 0.secs)] }
    | default []
)
```

Please let me know if this change messes something up I'm not seeing.
# User-Facing Changes
- Before
```nu
→ null | each { "something" }
something
```
- After
```nu
→ null | each { "something" }
null
```
# Tests + Formatting
Added a test to check for this.

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->

---------

Co-authored-by: Bahex <17417311+Bahex@users.noreply.github.com>
2025-08-13 15:22:24 -05:00
43992f5b6f Rework PR template (#16412) 2025-08-13 22:10:47 +02:00
91e72ae8b4 Validate std/random dice args (#16430)
Fixes #16429
2025-08-13 21:50:49 +02:00
da54ed8ea1 docs: document undocumented Signature methods (#16417)
Just a small PR which documents methods. I got confused what `rest` did
while working on a plugin, so I decided to document all of them.
2025-08-13 20:58:30 +02:00
3eabc83c61 build(deps): bump crate-ci/typos from 1.35.1 to 1.35.4 (#16424) 2025-08-13 18:55:36 +00:00
cc4a4a11f0 build(deps): bump sysinfo from 0.36.0 to 0.36.1 (#16423) 2025-08-13 18:55:11 +00:00
d53e16748d build(deps): bump rayon from 1.10.0 to 1.11.0 (#16422) 2025-08-13 18:54:22 +00:00
4ead4ce4d6 feat: move random dice to std (#16420)
# Description

As per the suggestion in #16350, this PR moves `random dice` to std.
It's basically a thin wrapper over `random int` already.

# User-Facing Changes (deprecations)

## `random dice` moved to `std`

The `random dice` command has been rewritten in Nushell and moved to the
standard library. The `random dice` built-in is still available with a
deprecation error, but will be removed in 0.108. The new command can be
used as follows:

```nushell
use std/random

random dice
```

It's behavior, parameters, and defaults are the same.


# After Submitting

Update documentation to reflect the change.

Closes #16350
2025-08-13 20:45:45 +02:00
31606a8fe1 Kill background jobs on interrupt (#16285)
# Description
This PR kills all background jobs on interrupt, as a fix for
https://github.com/nushell/nushell/issues/15947.

# User-Facing Changes
If you run the following: `job spawn { print "job spawned"; ^sleep
infinity }; ^sleep infinity`, then hit ctrl-c, the current behavior is
that the `sleep` process from the job will not be killed, it will
reparented to init. With this change, the process will be killed on
ctrl-c.

# Tests + Formatting
I was unsure of the best way to write a test for this.

# After Submitting

---------

Co-authored-by: 132ikl <132@ikl.sh>
2025-08-13 13:11:40 -04:00
7133a04e2f Improve wrong flag help (#16427)
# Description

Currently, when Nushell encounters an unknown flag, it prints all
options in the help string. This is pretty verbose and uses the
`formatted_flags` signature method, which isn't used anywhere else. This
commit refactors the parser to use `did_you_mean` instead, which only
suggest one closest option or sends the user to `help` if nothing close
is found.


# User-Facing Changes (Bug fixes and other changes)

## Improved error messages for misspelled flags

Previously, the help text for a missing flag would list all of them,
which could get verbose on a single line:

```nushell
~> ls --full-path
Error: nu::parser::unknown_flag

  × The `ls` command doesn't have flag `full-path`.
   ╭─[entry #8:1:4]
 1 │ ls --full-path
   ·    ─────┬─────
   ·         ╰── unknown flag
   ╰────
  help: Available flags: --help(-h), --all(-a), --long(-l), --short-names(-s), --full-paths(-f), --du(-d), --directory(-D), --mime-type(-m), --threads(-t). Use
        `--help` for more information.
```

The new error message only suggests the closest flag:

```nushell
> ls --full-path
Error: nu::parser::unknown_flag

  × The `ls` command doesn't have flag `full-path`.
   ╭─[entry #23:1:4]
 1 │ ls --full-path
   ·    ─────┬─────
   ·         ╰── unknown flag
   ╰────
  help: Did you mean: `--full-paths`?
```


---

Closes #16418
2025-08-13 06:25:18 -05:00
79a6c78032 implement FromValue for std::time::Duration and refactor relevant commands to utilize that (#16414)
# Description

- Implemented `FromValue` for `std::time::Duration`.
- It only converts positive `Value::Duration` values, negative ones
raise `ShellError::NeedsPositiveValue`.
- Refactor `job recv` and `watch` commands to use this implementation
rather than handling it ad-hoc.
- Simplified `watch`'s `debounce` & `debounce-ms` and factored it to a
function. Should make removing `debounce-ms` after its deprecation
period ends.
- `job recv` previously used a numeric cast (`i64 as u64`) which would
result in extremely long duration values rather than raising an error
when negative duration arguments were given.

# User-Facing Changes

Changes in error messages:
- Providing the wrong type (bypassing parse time type checking):
  - Before
    ```
    Error: nu:🐚:type_mismatch

      × Type mismatch.
       ╭─[entry #40:1:9]
     1 │ watch . --debounce (1 | $in) {|| }
       ·         ──────────┬─────────
       ·                   ╰── Debounce duration must be a duration
       ╰────
    ```
  - After
    ```
    Error: nu:🐚:cant_convert

      × Can't convert to duration.
       ╭─[entry #2:1:9]
     1 │ watch . --debounce (1 | $in) {|| }
       ·         ──────────┬─────────
       ·                   ╰── can't convert int to duration
       ╰────
    ```
- Providing a negative duration value:
  - Before
    ```
    Error: nu:🐚:type_mismatch

      × Type mismatch.
       ╭─[entry #41:1:9]
     1 │ watch . --debounce -100ms {|| }
       ·         ────────┬────────
       ·                 ╰── Debounce duration is invalid
       ╰────
    ```
  - After
    ```
    Error: nu:🐚:needs_positive_value

      × Negative value passed when positive one is required
       ╭─[entry #4:1:9]
     1 │ watch . --debounce -100ms {|| }
       ·         ────────┬────────
       ·                 ╰── use a positive value
       ╰────
    ```
2025-08-12 22:25:23 +02:00
5478bdff0e feat: null values can be spread as if they are empty lists or records. (#16399)
# Description
Spread operator `...` treats `null` values as empty collections,
, whichever of list or record is appropriate.

# User-Facing Changes
`null` values can be used with the spread operator (`...`)
2025-08-11 23:47:31 +03:00
a4711af952 feat: impl<B> for (From/Into)Value for Cow<'_, B> where B::Owned: (From/Into)Value (#16380)
# Description
Implements `FromValue` and `IntoValue` for `Cow`, which makes it easy to
use it in types that need to implement these traits.

I don't think it will have a significant impact, but it can let us avoid
allocations where we can use static values.

# Tests + Formatting
No need, the implementations are delegated to `B::Owned`.

Co-authored-by: Bahex <Bahex@users.noreply.github.com>
2025-08-11 19:47:50 +02:00
751ef6e8da [parser] Improve type errors for boolean literals (#16408)
Currently, strings `true` and `false` are intercepted early in parsing.
Previously, if they didn't match the expected shape, the parse error
said "expected non-boolean value". This PR changes the message to say
"expected <shape>".

Because the parsing error requires a `&'static str` I had to add a
`to_str(&self) -> &'static str` method on `SyntaxShape`. It's a bit
crude for more complex shapes: it simply says `keyword`, `list`,
`table`, and so on for them, without exposing the underlying structure.

Fixes #16406
2025-08-11 11:59:27 -05:00
038f8f85ed Fix missing $env.PATH unhelpful error and breaking CMD builtins (#16410)
<!--
if this PR closes one or more issues, you can automatically link the PR
with
them by using one of the [*linking
keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword),
e.g.
- this PR should close #xxxx
- fixes #xxxx

you can also mention related issues, PRs or discussions!
-->
Fixes #16409 

# Description
<!--
Thank you for improving Nushell. Please, check our [contributing
guide](../CONTRIBUTING.md) and talk to the core team before making major
changes.

Description of your pull request goes here. **Provide examples and/or
screenshots** if your changes affect the user experience.
-->
After running `hide-env PATH`, there is a more helpful error and CMD
builtins still work.
<img width="503" height="217" alt="image"
src="https://github.com/user-attachments/assets/a43180f9-5bc2-43bd-9773-aa9ad1818386"
/>
<img width="779" height="253" alt="image"
src="https://github.com/user-attachments/assets/03b59209-f9a9-4c61-9ea2-8fbdc27b8d4b"
/>


# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

# Tests + Formatting
<!--
Don't forget to add tests that cover your changes.

Make sure you've run and fixed any issues with these commands:

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to
check that you're using the standard code style
- `cargo test --workspace` to check that all tests pass (on Windows make
sure to [enable developer
mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging))
- `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` to run the
tests for the standard library

> **Note**
> from `nushell` you can also use the `toolkit` as follows
> ```bash
> use toolkit.nu # or use an `env_change` hook to activate it
automatically
> toolkit check pr
> ```
-->

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->

---------

Co-authored-by: 132ikl <132@ikl.sh>
2025-08-11 12:55:22 -04:00
4245c67ce3 Add --raw flag to to html (#16373)
Works towards #16347 however more work may be required first

# Description
Adds a `--raw` flag to `to html`. This stops the resulting html content
being escaped
# User-Facing Changes

# Tests + Formatting
# After Submitting
2025-08-11 21:31:24 +08:00
e56879e588 fix(parser): missing span of short flag that requires a value (#16376)
Fixes #16375

# Description

# User-Facing Changes

Bug fix

# Tests + Formatting

+0.5
2025-08-09 23:50:55 +02:00
c75e7bfbd3 Fix watch return type (#16400)
Refs
https://discord.com/channels/601130461678272522/615329862395101194/1403760147985207487

# Description

Currently `watch` doesn't normally return, ever. The only way to stop it
is to abort with `Ctrl+C` (or some internal error happens), so it never
produces a usable pipeline output. Since nu doesn't have `never` type
yet, `nothing` is the closest thing we can use.

# User-Facing Changes

Users may start to get type errors if they used `watch .... | something`
and the `something` did not accept `nothing`.

# Tests + Formatting

All pass.
2025-08-09 23:43:51 +02:00
e8579a9268 Add examples for receiving data from a job (#16372)
# Description

The existing examples cover how to send data to a job, but I think it
will be much more common to want to receive data from a job.

# User-Facing Changes

Just documentation, though it may be worth highlighting anyway. I really
thought for a while that this was not possible yet. See also my book PR
https://github.com/nushell/nushell.github.io/pull/2006 (`job send` and
`job recv` were not documented in the book at all).
2025-08-09 07:39:44 +08:00
3dead9a001 Respect $env.LC_ALL and $env.LANG in format date (#16369)
Refs
https://github.com/nushell/nushell/issues/16368#issuecomment-3160728758

# Description

Respect user preference for date/time formats, in a more compatible way.
Environment variable order is taken from
https://www.gnu.org/software/gettext/manual/html_node/Locale-Environment-Variables.html.
Previously, only `$env.LC_TIME` was consulted to select the locale.

# User-Facing Changes

Users will be able to specify the format preference via `$env.LANG` and
override it with `$env.LC_ALL`.

# Tests + Formatting

All pass.
2025-08-09 07:36:34 +08:00
0b106789a7 build(deps): bump mach2 from 0.4.2 to 0.4.3 (#16363)
Bumps [mach2](https://github.com/JohnTitor/mach2) from 0.4.2 to 0.4.3.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/JohnTitor/mach2/releases">mach2's
releases</a>.</em></p>
<blockquote>
<h2>0.4.3</h2>
<h2>What's Changed</h2>
<ul>
<li>Add <code>time_value</code> by <a
href="https://github.com/ldm0"><code>@​ldm0</code></a> in <a
href="https://redirect.github.com/JohnTitor/mach2/pull/25">JohnTitor/mach2#25</a></li>
<li>Add <code>mach-o/dyld.h</code> items by <a
href="https://github.com/JohnTitor"><code>@​JohnTitor</code></a> in <a
href="https://redirect.github.com/JohnTitor/mach2/pull/32">JohnTitor/mach2#32</a></li>
<li>Add <code>struct</code> prefix on all the structs in C by <a
href="https://github.com/JohnTitor"><code>@​JohnTitor</code></a> in <a
href="https://redirect.github.com/JohnTitor/mach2/pull/33">JohnTitor/mach2#33</a></li>
<li>chore(ci): Update macOS version by <a
href="https://github.com/JohnTitor"><code>@​JohnTitor</code></a> in <a
href="https://redirect.github.com/JohnTitor/mach2/pull/37">JohnTitor/mach2#37</a></li>
<li>Configure Renovate by <a
href="https://github.com/renovate"><code>@​renovate</code></a> in <a
href="https://redirect.github.com/JohnTitor/mach2/pull/36">JohnTitor/mach2#36</a></li>
<li>chore(deps): pin dependencies by <a
href="https://github.com/renovate"><code>@​renovate</code></a> in <a
href="https://redirect.github.com/JohnTitor/mach2/pull/39">JohnTitor/mach2#39</a></li>
<li>chore: Use original ctest by <a
href="https://github.com/JohnTitor"><code>@​JohnTitor</code></a> in <a
href="https://redirect.github.com/JohnTitor/mach2/pull/40">JohnTitor/mach2#40</a></li>
<li>chore: Prepare 0.4.3 release by <a
href="https://github.com/JohnTitor"><code>@​JohnTitor</code></a> in <a
href="https://redirect.github.com/JohnTitor/mach2/pull/41">JohnTitor/mach2#41</a></li>
</ul>
<h2>New Contributors</h2>
<ul>
<li><a href="https://github.com/ldm0"><code>@​ldm0</code></a> made their
first contribution in <a
href="https://redirect.github.com/JohnTitor/mach2/pull/25">JohnTitor/mach2#25</a></li>
<li><a href="https://github.com/renovate"><code>@​renovate</code></a>
made their first contribution in <a
href="https://redirect.github.com/JohnTitor/mach2/pull/36">JohnTitor/mach2#36</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/JohnTitor/mach2/compare/0.4.2...0.4.3">https://github.com/JohnTitor/mach2/compare/0.4.2...0.4.3</a></p>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="ed16d350ab"><code>ed16d35</code></a>
Merge pull request <a
href="https://redirect.github.com/JohnTitor/mach2/issues/41">#41</a>
from JohnTitor/chore/0.4.3</li>
<li><a
href="86b3f278c4"><code>86b3f27</code></a>
chore: Prepare 0.4.3 release</li>
<li><a
href="6b9a8bcdca"><code>6b9a8bc</code></a>
Merge pull request <a
href="https://redirect.github.com/JohnTitor/mach2/issues/40">#40</a>
from JohnTitor/chore/ctest</li>
<li><a
href="ae47e1935b"><code>ae47e19</code></a>
chore: Use original ctest</li>
<li><a
href="52f3edbfaf"><code>52f3edb</code></a>
Merge pull request <a
href="https://redirect.github.com/JohnTitor/mach2/issues/39">#39</a>
from JohnTitor/renovate/pin-dependencies</li>
<li><a
href="ceee600d4b"><code>ceee600</code></a>
chore(deps): pin dependencies</li>
<li><a
href="ac9f277587"><code>ac9f277</code></a>
chore(renovate): Enable GHA digests helper</li>
<li><a
href="3f3769660c"><code>3f37696</code></a>
Merge pull request <a
href="https://redirect.github.com/JohnTitor/mach2/issues/36">#36</a>
from JohnTitor/renovate/configure</li>
<li><a
href="ab4d126d28"><code>ab4d126</code></a>
Add renovate.json</li>
<li><a
href="d156e25e99"><code>d156e25</code></a>
Merge pull request <a
href="https://redirect.github.com/JohnTitor/mach2/issues/37">#37</a>
from JohnTitor/chore/update-macos-version</li>
<li>Additional commits viewable in <a
href="https://github.com/JohnTitor/mach2/compare/0.4.2...0.4.3">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=mach2&package-manager=cargo&previous-version=0.4.2&new-version=0.4.3)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-08-09 07:30:56 +08:00
bf83756562 Fix example result span (#16395)
Refs
https://discord.com/channels/601130461678272522/614593951969574961/1403435414416654427

# Description

Previously Example result values would have a test span, which would
cause hard to understand errors for the code that uses `scope commands`.

Now they will have the span that points to `scope commands` invocation.

# User-Facing Changes

Errors referencing example results will get slightly better.

# Tests + Formatting

All pass.
2025-08-09 07:29:27 +08:00
06fa1784c1 Clarify that input's history feature uses reedline (#16334)
Follow up to this commit @sholderbach made on my PR #16329:
f21350ec88 (diff-5cab4dac5ced236548db9fbf6cd0e9d250ba12317bb916ec26603054ce9144a7)
2025-08-08 22:20:42 +02:00
e6d673c39e fix (std/help): fix bug and use is-not-empty (#16394)
# Description
In #16354, I introduced a bug thinking that `table -e` would always
return a string, so I fix it here restoring the `to text`. While I was
at it, I changed all instances of `if not ($var | is-empty)` to `if
($var | is-not-empty)` to improve readability.

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

# Tests + Formatting
<!--
Don't forget to add tests that cover your changes.

Make sure you've run and fixed any issues with these commands:

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to
check that you're using the standard code style
- `cargo test --workspace` to check that all tests pass (on Windows make
sure to [enable developer
mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging))
- `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` to run the
tests for the standard library

> **Note**
> from `nushell` you can also use the `toolkit` as follows
> ```bash
> use toolkit.nu # or use an `env_change` hook to activate it
automatically
> toolkit check pr
> ```
-->

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2025-08-08 13:58:33 -05:00
c4fcd54573 nu-table: Fix header on border index coloring (#16377)
Sorry for delay

close #16345

<img width="519" height="263" alt="image"
src="https://github.com/user-attachments/assets/e5fe2a23-5a47-4c18-933f-6cf936ea702c"
/>

About the incorrect alignment of the index header `#` it shall be fixed
with the next `tabled` release.

cc: @fdncred
2025-08-07 08:19:39 -05:00
4e56cd5fc4 fix(parser): external argument with subexpressions (#16346)
Fixes: #16040

# Description

TBH, I not a fan of this whole `parse_external_string` idea.
Maybe I lack some of the background knowledge here, but I don't see why
we choose not to
1. parse external arguments the same way as internal ones
2. treat them literally at runtime if necessary

Tests: +1
2025-08-06 22:17:58 +03:00
0e3ca7b355 build(deps): bump fancy-regex from 0.14.0 to 0.16.1 (#16365) 2025-08-06 05:26:49 +00:00
2b69bd9b6d build(deps): bump crate-ci/typos from 1.34.0 to 1.35.1 (#16360) 2025-08-06 12:27:52 +08:00
3a82c6c88d Fix panic in unit parsing with non-UTF8 code (#16355)
# Description
Trying to parse non-UTF8 data as a value with unit (part of every
literal parse) introduced a replacement character which shifted the span
information so the indices where incorrect and triggered
a panic.

This has been resolved by removing a bad `String::from_utf8_lossy`

# User-Facing Changes
One less possible panic

# Tests + Formatting
Added a test with the original reproducer from fuzzing:

File with `0\xffB` where the `\xff` represents the non utf-8 char `FF`
run as a script to trigger
2025-08-05 22:08:33 +02:00
61a89c1834 Fully qualify the sqlite path for into sqlite (#16349)
- related #16258

# Description


In #16258 we had some trouble getting tests to work properly. After some
investigation with @WindSoilder we figured out that `Table::new` inside
`into_sqlite.rs` did not respect the `$env.PWD`. The underlying
`open_sqlite_db` and in that `Connection::open` respects the current
working directory. That one is updated via `cd` but not necessarily in
tests (and we should not try that). In this PR I join the `$env.PWD`
with the path passed to `into sqlite`.

This PR also adds a test for the auto conversion from #16258.

# User-Facing Changes

Should be none, some edge cases might be fixed now.
2025-08-05 22:02:33 +02:00
fcdc7f3d83 fix(std/help): trim example results and fix binary examples (#16354)
# Description
Added trimming to the example results like in the normal `help`, and
also changed the logic for binary examples to remove the weird spacing.
- Before:
<img width="998" height="919" alt="image"
src="https://github.com/user-attachments/assets/03f18f45-5b12-41bc-b495-232bcf899964"
/>

- After:
<img width="959" height="720" alt="image"
src="https://github.com/user-attachments/assets/894dc622-c603-467c-8904-aef582a82b0a"
/>

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

# Tests + Formatting
<!--
Don't forget to add tests that cover your changes.

Make sure you've run and fixed any issues with these commands:

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to
check that you're using the standard code style
- `cargo test --workspace` to check that all tests pass (on Windows make
sure to [enable developer
mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging))
- `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` to run the
tests for the standard library

> **Note**
> from `nushell` you can also use the `toolkit` as follows
> ```bash
> use toolkit.nu # or use an `env_change` hook to activate it
automatically
> toolkit check pr
> ```
-->

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2025-08-05 13:21:23 -05:00
2b70d27cdf fix(help): don't trim example result beginning (#16353)
# Description
The `help` command, when printing the examples with results, trims the
first line and it appears unindented compared to the following lines.

- Before:
<img width="1110" height="346" alt="image"
src="https://github.com/user-attachments/assets/3487381d-3631-49c9-bb0e-f7ad958b7291"
/>

- After:
<img width="1123" height="339" alt="image"
src="https://github.com/user-attachments/assets/acb45afd-0492-49d2-a5cb-5130bbb4cf94"
/>

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

# Tests + Formatting
<!--
Don't forget to add tests that cover your changes.

Make sure you've run and fixed any issues with these commands:

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to
check that you're using the standard code style
- `cargo test --workspace` to check that all tests pass (on Windows make
sure to [enable developer
mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging))
- `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` to run the
tests for the standard library

> **Note**
> from `nushell` you can also use the `toolkit` as follows
> ```bash
> use toolkit.nu # or use an `env_change` hook to activate it
automatically
> toolkit check pr
> ```
-->

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2025-08-05 13:20:37 -05:00
8c2af9941c feat(std-rfc/str): add str align (#16062) 2025-08-06 00:21:23 +08:00
f015409253 [nu-std] std-rfc/random: add random choice (#16270)
# Description

Adds `random choice` suggested in #16241.

# User-Facing Changes

New `random` module in `std-rfc` with the `choice` subcommand.

# Tests + Formatting

Unsure how do to do tests. Sampling and a histogram should be enough,
but they'll be non-deterministic.

# After Submitting

<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->

---------

Co-authored-by: sholderbach <sholderbach@users.noreply.github.com>
2025-08-04 20:36:28 +02:00
f33d952adf 'stor create/insert/open' & 'query db' now support JSON columns (#16258)
Co-authored-by: Tim 'Piepmatz' Hesse <git+github@cptpiepmatz.de>
2025-08-04 16:58:21 +02:00
9f4c3a1d10 Fix path relative-to for case-insensitive filesystems (#16310)
fixes #16205 

# Description

1. **Adds fallback**: On case-insensitive filesystems (Windows, macOS),
falls back to case-insensitive comparison when the standard comparison
fails
2. **Maintains filesystem semantics**: Only uses case-insensitive
comparison on platforms where it's appropriate

## Before:
```console
$> "/etc" | path relative-to "/Etc"
Error: nu:🐚:cant_convert

  × Can't convert to prefix not found.
   ╭─[entry #33:1:1]
 1 │ "/etc" | path relative-to "/Etc"
   · ───┬──
   ·    ╰── can't convert string to prefix not found
   ╰────
```

## After:
For Windows and macOS:
```console
$> "/etc" | path relative-to "/Etc" | debug -v
""
```
2025-08-04 22:32:31 +08:00
4f9c0775d9 Change the behavior of --ignore-case and --multiline options for find (#16323)
# Description

Changes the behavior of `--ignore-case` and `--multiline` options for
`find`, to make them more consistent between regex mode and search term
mode, and to enable more options for using find.

# User-Facing Changes

Search term mode is now case-sensitive by default.

`--ignore-case` will make the search case-insensitive in search term
mode. In regex mode, the previous behavior of adding a (?i) flag to the
regex is preserved.

`--multiline` will no longer add a (?m) flag in regex mode. Instead, it
will make the search not split multi-line strings into lists of lines.

closes #16317
closes #16022
2025-08-04 22:27:00 +08:00
d528bb713b Fix UTF-8 multibyte handling in explore inputs (#16325)
# Description
`explore` was reading the byte length for computing:
- `:` command input cursor positions
- `/`/`?` search mode cursor positions
- `:try` input box cursor positions
- search highlighting

Fixed this for the majority of cases by using `unicode_width`, this is
only best effort as terminals don't need to follow those expectations
but for the most cases (traditional language scripts etc.) this should
lead to better result. The only way around the uncertainty would be to
perform the highlighting/cursor marking as we go, but this may not be as
compatible with the `ratatui` framework.

Closes #16312

# User-Facing Changes
Fixed cursor position and search highlighting for non-ASCII characters,
with the caveat mentioned above.

# Tests + Formatting
Manually tested
2025-08-03 21:20:35 +02:00
7cc1a86459 typo: help format filesize has a wrong example (#16336)
Just a small one letter typo in the help command. It should be `kB`

<img width="943" height="688" alt="image"
src="https://github.com/user-attachments/assets/fcca3978-cc0d-483f-b74e-465743213b76"
/>
2025-08-03 13:27:03 +02:00
dfbd98013d Add send: vichangemode to reedline config (#16327)
# Description
Allows custom bindings (non-chord) to send a `edit_mode: vi` mode change
via the new `ReedlineEvent::ViChangeMode`
Takes https://github.com/nushell/reedline/pull/932

# User-Facing Changes
You can now set bindings which change the Vi mode. (This still has the
same rules for defining the key-combination: Only modifiers and single
keys are supported)
To do so send a `vichangemode` event with the `mode` field to set
`normal`, `insert`, or `visual`

```nushell
$env.config.keybindings ++=
	[{
	    name: modechangetest
	    modifier: control
	    keycode: "char_["
	    mode: [vi_normal, vi_insert]
	    event: {send: vichangemode, mode: normal}
	}]

```
2025-08-03 13:23:55 +02:00
2c9f6acc03 Forgo full build in the cargo hack wf (#16328)
We ran out of disk space on Github actions with the build part of this
workflow. We hope that `check` should catch the worst offenders.
2025-08-02 21:04:43 +02:00
007d15ed9f Add multiline example for input command (#16329)
# Description

Adds an example that documents how to use `input --reedline` to collect
multiple lines of input from the user

I also removed an extraneous and inconsistent space in the following
example.

# User-Facing Changes

Documentation addition

# Tests + Formatting

I did not run any tests or autoformatters because of the docs-only
nature of the change, and the fact that I copy-pasted the format from an
existing example. If the autoformatter is unhappy, I apologize.

# After Submitting

This PR should automatically update the docs site at the next release,
so no need to do anything there.

---------

Co-authored-by: Stefan Holderbach <sholderbach@users.noreply.github.com>
2025-08-02 21:04:20 +02:00
3e37922537 Bump ureq, get redirect history. (#16078) 2025-08-02 13:55:37 +02:00
1274d1f7e3 Add -h/--help flag to testbin (#16196)
# Description
As title, this pr introduce `-h` flag to testbin, so if I want to see
which testbin I should use, I don't need to look into source code.

### About the change
I don't know if there is any way to get docstring of a function inside
rust code. So I created a trait, and put docstring into it's `help`
method:
```rust
pub trait TestBin {
    // the docstring of original functions are moved here.
    fn help(&self) -> &'static str;
    fn run(&self);
}
```
Take `cococo` testbin as example, the changes are:
```
original cococo function --> Cococo struct, then
1. put the body of `cococo` function into `run` method
2. put the docstring of `cococo` function into `help` method
```

# User-Facing Changes

`-h/--help` flag in testbin is enabled.
```
> nu --testbin -h
Usage: nu --testbin <bin>
<bin>:
chop -> With no parameters, will chop a character off the end of each line
cococo -> Cross platform echo using println!()(e.g: nu --testbin cococo a b c)
echo_env -> Echo's value of env keys from args(e.g: nu --testbin echo_env FOO BAR)
echo_env_mixed -> Mix echo of env keys from input(e.g: nu --testbin echo_env_mixed out-err FOO BAR; nu --testbin echo_env_mixed err-out FOO BAR)
echo_env_stderr -> Echo's value of env keys from args to stderr(e.g: nu --testbin echo_env_stderr FOO BAR)
echo_env_stderr_fail -> Echo's value of env keys from args to stderr, and exit with failure(e.g: nu --testbin echo_env_stderr_fail FOO BAR)
fail -> Exits with failure code 1(e.g: nu --testbin fail)
iecho -> Another type of echo that outputs a parameter per line, looping infinitely(e.g: nu --testbin iecho 3)
input_bytes_length -> Prints the number of bytes received on stdin(e.g: 0x[deadbeef] | nu --testbin input_bytes_length)
meow -> Cross platform cat (open a file, print the contents) using read_to_string and println!()(e.g: nu --testbin meow file.txt)
meowb -> Cross platform cat (open a file, print the contents) using read() and write_all() / binary(e.g: nu --testbin meowb sample.db)
nonu -> Cross platform echo but concats arguments without space and NO newline(e.g: nu --testbin nonu a b c)
nu_repl -> Run a REPL with the given source lines
relay -> Relays anything received on stdin to stdout(e.g: 0x[beef] | nu --testbin relay)
repeat_bytes -> A version of repeater that can output binary data, even null bytes(e.g: nu --testbin repeat_bytes 003d9fbf 10)
repeater -> Repeat a string or char N times(e.g: nu --testbin repeater a 5)
```

# Tests + Formatting
None, all existed tests can guarantee the behavior of testbins doesn't
change.

# After Submitting
NaN
2025-08-02 10:48:07 +08:00
da9615f971 Fix parse-time pipeline type checking to support multiple output types for same input type (#16111)
# Description
Fixes #15485

This PR changes pipeline checking to keep track of all possible output
types instead of only first type matching input type which appears in
the input/output types. For example, in this command:
```nushell
def foo []: [int -> string, int -> record] {
  # ...
}
```
An `int` input to the command may result in a string or a record to be
output. Before this PR, Nushell would always assume that an `int` input
would cause a `string` output because it's the first matching
input/output type pair. This would cause issues during type checking
where the parser would incorrectly determine the output type. After this
PR, Nushell considers the command to output either a string or a record.

# User-Facing Changes
* Parse-time pipeline type checking now properly supports commands with
multiple pipeline output types for the same pipeline input type

# Tests + Formatting
Added a couple tests

# After Submitting
N/A

---------

Co-authored-by: Bahex <Bahex@users.noreply.github.com>
2025-08-02 09:35:25 +08:00
eb8d2d3206 Refactor: introduce 2 associated functions to PipelineData (#16233)
# Description
As title: this pr is try to introduce 2 functions to `PipelineData`:
1. PipelineData::list_stream --> create a PipelineData::ListStream
2. PipelineData::byte_stream -> create a PipelineData::ByteStream
And use these functions everywhere.

### Reason behind this change
I tried to implement `pipefail` feature, but this would required to
change `PipelineData` from enum to struct. So use these functions can
reduce diff if I finally change to struct. [Discord message
here](https://discord.com/channels/601130461678272522/615962413203718156/1396999539000479784)
is my plan.

# User-Facing Changes
NaN

# Tests + Formatting
NaN

# After Submitting
NaN
2025-08-02 09:30:30 +08:00
ee5b5bd39e fix(input list): don't leak ansi styling, fuzzy match indicator preserves styles (#16276)
- fixes #16200

# Description

|    | Select           | Fuzzy           |
| -- | ---------------- | --------------- |
|  | ![select-before] | ![fuzzy-before] |
|  | ![select-fixed]  | ![fuzzy-fixed]  |

[select-before]:
8fe9136472/select-before.svg
[select-fixed]:
8fe9136472/select-after.svg
[fuzzy-before]:
8fe9136472/fuzzy-before.svg
[fuzzy-fixed]:
8fe9136472/fuzzy-after.svg

Using a custom `dialoguer::theme::Theme` implementation, how `input
list` renders items are overridden.

Unfortunately, implementing one of the methods requires
`fuzzy_matcher::skim::SkimMatcherV2` which `dialoguer` does not export
by itself.
Had to add an explicit dependency to `fuzzy_matcher`, which we already
depend on through `dialoguer`. Version specification is copied from
`dialoguer`.

# Tests + Formatting
No tests added.
Couldn't find existing tests, not sure how to test this.

---------

Co-authored-by: Bahex <17417311+Bahex@users.noreply.github.com>
2025-07-31 22:42:10 +02:00
d565c9ed01 Fix commit ID hex formatting in gstat (#16309)
Fix commit ID hex formatting in gstat, closes #16307 

Leading zeros are preserved, maintaining the correct hex representation

This issue is relatively easy to fix, but it's not very easy to verify.
However, I have already tested several scenarios, it works for commit
sha like `000baeef`, `000003c7` and `00000002` etc.
2025-07-31 09:59:14 -05:00
18d5d8aae1 Fixup pre-release checkup workflow (#16305)
Avoid going out of disk by running cargo clean between each build:
https://github.com/taiki-e/cargo-hack#--clean-per-run

Also rename to something shorter for the overview
2025-07-30 23:46:18 +02:00
89c0e325fa fix panic when ..= syntax is used in stepped ranges (#16231)
Fixes #16185

# Description

Stepped range literals where `..=` precedes the second value no longer
cause a parser panic:

```diff
random int 1..=3..5
-Error:   x Main thread panicked.
-  |-> at crates/nu-protocol/src/engine/state_working_set.rs:400:48
-  `-> slice index starts at 8 but ends at 7
+Error: nu::parser::parse_mismatch
+
+  × Parse mismatch during operation.
+   ╭─[entry #1:1:15]
+ 1 │ random int 1..=3..5
+   ·               ─┬
+   ·                ╰── expected number
```
2025-07-30 23:38:59 +02:00