7111 Commits

Author SHA1 Message Date
Bahex
a08e1f6217 refactor: move SplitRead and MultiLife into nu-utils (#16482) 2025-08-21 22:01:32 +03:00
Kira
f7aee7c4fe Fix highlighting of aliases to external commands (#15408)
Fixes #12965.

# Description
The syntax highlighter currently can't tell the difference between
external command calls and _alias_ calls to external commands. This
leads to unexpected behavior when `highlight_resolved_externals` is
enabled. Specifically, when this option is enabled, alias calls aliasing
external commands are highlighted according to
`color_config.shape_external_resolved` if and only if a command exists
in the PATH directories whose name happens to be the same as the name of
the alias.

The syntax highlighter also can't tell the difference between internal
command calls and alias calls aliasing internal commands, but this just
results in these alias calls being highlighted like normal internal
command calls, which isn't too unexpected.

It is ambiguous what the correct behavior should be. The three options I
can think of are:

1. Treat all alias calls (both aliasing internal and external commands)
as a new shape, like `shape_alias`, and highlight accordingly.
2. Highlight all alias calls like internal command calls, including
those aliasing external commands.
3. Highlight alias calls aliasing external commands according to how the
aliased command would have been highlighted.

I personally like 3. and it was easy to implement (unless I missed
something), so that's what this PR does right now. I'll be happy to
implement a different solution if appropriate. Discussion welcome :)

# User-Facing Changes
All changes are in syntax highlighting only.

Behavior _before_ this PR:

![image](https://github.com/user-attachments/assets/1dc855df-fde8-489e-8c5e-c02979874289)

Behavior _after_ this PR:

![image](https://github.com/user-attachments/assets/9e3a03bf-6730-4849-9123-42bd6b08dd39)

# Tests + Formatting
I didn't write any tests because I couldn't find any existing tests for
syntax highlighting.
2025-08-21 20:05:15 +02:00
andoalon
ac3f93ff05 Change the output of format bits to big endian instead of native endian (#16435)
Currently the command ouputs in native endian. That is unlike any other
tool that I've used that shows bits (windows calculator comes to mind).
Moreover, if you paste the output of `format bits` as a number you won't
get the same output:

```nushell
~> 258 | format bits
00000010 00000001
~> 0b00000010_00000001
513
```

In order to get a roundtrip, you need to reverse the bytes:

```nushell
~> 0b00000001_00000010
258
~> 258 | format bits | split words | str join | $"0b($in)" | into int
513
~> 258 | format bits | split words | reverse | str join | $"0b($in)" | into int # Added `reverse`
258
```

The goal of this PR is to get rid of this weirdness (and as a bonus get
a platform-independent behavior, without depending on what the native
endianness is).

## Release notes summary - What our users need to know
### Change the output of `format bits` to big endian instead of native
endian

This is what most people expect when formatting numbers and other
primtives in binary. However, until now, if you were in a little endian
system, you would get:
```nushell
~> 258 | format bits
00000010 00000001
```
If you copied and pasted that as a number, you would get a surprising
result:
```nushell
~> 0b00000010_00000001
513
```
Now, `format bits` always formats in big endian:
```nushell
~> 258 | format bits
00000001 00000010
```
2025-08-21 10:27:39 -04:00
Bahex
f7c131443f fix(nu): script file not found error should point to commandline, not rust code (#16273) 2025-08-21 16:23:56 +03:00
uraneko
cd1094c94e Sort help message flags by required field (#16476)
closes #16462.

The --help flag will now appear after all required flags in help
messages.

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

## Tasks after submitting
N/A
2025-08-21 11:46:29 +02:00
zc he
3877bfb61a fix(parser): env shorthand false positive (#16337)
More restrictions on env shorthand parsing to avoid false positives.

Fixes #16332
2025-08-20 18:57:33 +03:00
zc he
343e5cf191 fix(parser): export def exposes arguments to current scope (#16262)
- Skip the extra call of `parse_internal_call` unless the `help` flag is set.
- Wrap `parse_internal_call` in a new scope to avoid leaking variables.

Closes #16211
2025-08-20 18:10:16 +03:00
rose
abeb787115 Make Span mandatory for some fields in ShellError (#16471)
Some variants of `ShellError` have `Option<Span>` that really don't need
to. This PR removes the `Option` for `ConfigDirNotFound`
and `DisabledOsSupport`.

Also removes `ShellError::InterruptedByUser`, which had exactly one
usage, in favor of the more widely used `ShellError::Interrupted`

Rel: #13005

## Release notes summary - What our users need to know
N/A
2025-08-20 09:56:06 -04:00
Bruce Weirdan
258a7f6e97 Make xml: prefix always available in query xml (#16472)
## Release notes summary - What our users need to know

`query xml` now has `xml:` namespace prefix available by default,
without the need to specify it via `--namespaces`.

## Details and motivation

`xml:` prefix is rarely (if ever) explicitly declared in XML sources, so
its associated namespace is a bit obscure. `sxd_xpath` seems to assume
it's `http://www.w3.org/XML/1998/namespace`, so we register it by
default.

## 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-08-19 16:39:30 -05:00
rose
dd664e3cdb Add assertion that DeprecationEntry flag do not have dashes (#16475)
Added a `debug_assert` when using `DeprecationType::Flag` to ensure that
the dashes aren't included as part of the flag name. This will hopefully
catch something like the issue discovered in #16473 from occurring.

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

---------

Co-authored-by: Stefan Holderbach <sholderbach@users.noreply.github.com>
2025-08-19 22:28:30 +02:00
rose
2715992d2f Mitigate watch -d breaking change (#16473)
This PR reverts the breaking change of short flag change of `watch -d`
to `--debounce` instead of `--debounce-ms`. This fully prevents #16187
from being a breaking change.

Before #16187:
```nushell
watch -d 1000 foo {}
# => Now watching files at "/home/rose/foo". Press ctrl+c to abort.
```

Before this PR (after #16187):
```nushell
watch -d 1000 foo {}
# => Error: nu::parser::parse_mismatch
# => 
# =>   × Parse mismatch during operation.
# =>    ╭─[entry #15:1:10]
# =>  1 │ watch -d 1000 foo {}
# =>    ·          ──┬─
# =>    ·            ╰── expected duration with valid units
# =>    ╰────
```

After this PR (after #16187):
```nushell
watch -d 1000 foo {}
# => Warning: nu::parser::deprecated
# => 
# =>   ⚠ Flag deprecated.
# =>    ╭─[entry #3:1:7]
# =>  1 │ watch -d 1000 foo {}
# =>    ·       ─┬
# =>    ·        ╰── watch --debounce-ms was deprecated in 0.107.0 and will be removed in 0.109.0.
# =>    ╰────
# =>   help: `--debounce-ms` will be removed in favour of  `--debounce`
# => 
# => Now watching files at "/home/rose/foo". Press ctrl+c to abort.
```

This PR also fixes the `DeprecationEntry` which incorrectly had a `--`
in it, which I failed to realize when reviewing #16187. We should add a
`debug_assert` or something for this.

Rel: #16187

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

N/A

## Tasks after submitting

- [ ] Add `debug_assert` for `DeprecationType::Flag`s with `--`
2025-08-19 21:04:05 +02:00
andoalon
bc8acfd2ea Add --endian flag to into binary (#16466)
This flag brings `into binary` in line with other commands such as `into
int`.

The motivation to do this now comes from #16435:
the change to `format bits` to show the output in big endian makes the
output of `42 | format bits` and `42 | into binary | format bits`
diverge in little endian platforms. By adding this flag, we give the
user the option to make them equal: `42 | into binary --endian big |
format bits` (well, equal minus the padding zeros).

The default behavior is kept the same, since the default value is using
the platforms native endianness.

Results in a little endian platform (with the changes from both
PRs)



## Release notes summary - What our users need to know
Add `--endian` flag to `into binary` to select the endianness of how primitive types are layed out
```nushell
~> 258 | format bits
00000001 00000010
~> 258 | into binary --compact | format bits
00000010 00000001
~> 258 | into binary --compact --endian big | format bits
00000001 00000010
~> 258 | into binary | format bits
00000010 00000001 00000000 00000000 00000000 00000000 00000000 00000000
~> 258 | into binary --endian big | format bits
00000000 00000000 00000000 00000000 00000000 00000000 00000001 00000010
```

## Tasks after submitting
None
2025-08-19 16:42:30 +02:00
Stefan Holderbach
5a7d9062a1 chore: Clippy and dead code elimination pass (#16469)
- **Fix `clippy::non_canonical_partial_ord_impl`**
- **Clippy from stable `needless_return`**
- **Dead code found by `cargo +stable clippy`**
- **Remove dead function used by pre-uu `mv --update`**
- **clippy::manual_is_multiple_of**

## Release notes summary - What our users need to know
N/A
2025-08-19 16:39:48 +02:00
Stefan Holderbach
9ed6c12458 Use direct Value.as_str() in string commands (#16468)
Affects:
- `split chars`
- `split column`
- `split words`

Instead of the loose coercion provided by `.coerce_string` this can be a
direct check for the string identity of the particular `Value` as the
commands are sensibly restricted to `string` input types

Found through inspecting #9573

## Release notes summary - What our users need to know
N/A
2025-08-19 13:21:28 +02:00
Jan9103
5ce9c38540 fix(nu-lsp): hover on external 0x08 handling (#16316)
# Description
issue report: discord `#editor-support` 2025-07-30 (discords `copy
message link` button is broken)

The LSP hover uses `man` under the hood.
Some `man` implementations use `0x08` to underline text, make text bold,
etc.
Nu previously just stripped the `0x08`, leaving the duplicate
characters, random underscores, etc.

With this PR it strips both `0x08` and its preceding character before
stripping the ANSI.

`groff` (`man`'s rendering engine) prints the underscore first
(`_\x08A`) when underscoring (probably in case something cant print
chars on top of another) and thus the char before has to be stripped.

different `man` implementations accept different arguments (example: the
one i use errors from `-P`) and i was unable to find a env-var or
argument to fix the problem (`-T ascii` does nothing on my pc).

I am fairly new to `Cow` stuff, so this is probably far from the most
performant implementation.
Feel free to give me pointers, fork this PR, or whatever.

## Potential bugs

I would be suprised, but some `man` implementation might render the char
first and the underscore second.

## Testing

Apparently not every `man` implementation is affected by the original
bug..

I use:
* voidlinux (gnu)
* groff: `1.23.0`
* man: `man-db-2.13.0_1`
* editor: `helix 25.01.1 (bcb6c20a)`

```
> man rev | to json
"REV(1)                           User Commands                          REV(1)\n\nN\bNA\bAM\bME\bE\n       rev - reverse lines characterwise\n\nS\bSY\bYN\bNO\bOP\bPS\bSI\bIS\bS\n       r\bre\bev\bv [option] [_\bf_\bi_\bl_\be...]\n\nD\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN\n       The r\bre\bev\bv utility copies the specified files to standard output,\n       reversing the order of characters in every line. If no files are\n       specified, standard input is read.\n\n       This utility is a line-oriented tool and it uses in-memory allocated\n       buffer for a whole wide-char line. If the input file is huge and\n       without line breaks then allocating the memory for the file may be\n       unsuccessful.\n\nO\bOP\bPT\bTI\bIO\bON\bNS\bS\n       -\b-h\bh, -\b--\b-h\bhe\bel\blp\bp\n           Display help text and exit.\n\n       -\b-V\bV, -\b--\b-v\bve\ber\brs\bsi\bio\bon\bn\n           Print version and exit.\n\n       -\b-0\b0, -\b--\b-z\bze\ber\bro\bo\n           _\bZ_\be_\br_\bo _\bt_\be_\br_\bm_\bi_\bn_\ba_\bt_\bi_\bo_\bn. Use the byte '\\0' as line separator.\n\nS\bSE\bEE\bE A\bAL\bLS\bSO\bO\n       t\bta\bac\bc(1)\n\nR\bRE\bEP\bPO\bOR\bRT\bTI\bIN\bNG\bG B\bBU\bUG\bGS\bS\n       For bug reports, use the issue tracker at\n       <https://github.com/util-linux/util-linux/issues>.\n\nA\bAV\bVA\bAI\bIL\bLA\bAB\bBI\bIL\bLI\bIT\bTY\bY\n       The r\bre\bev\bv command is part of the util-linux package which can be\n       downloaded from _\bL_\bi_\bn_\bu_\bx _\bK_\be_\br_\bn_\be_\bl _\bA_\br_\bc_\bh_\bi_\bv_\be\n       <https://www.kernel.org/pub/linux/utils/util-linux/>.\n\nutil-linux 2.40.2                 2024-01-31                            REV(1)"
```

# User-Facing Changes

I think this is just a bugfix.

# Tests + Formatting

- [x] `cargo fmt --all -- --check` to check standard code formatting
(`cargo fmt --all` applies these changes)
- [x] `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used`
to check that you're using the standard code style
- [x] `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))
- [x] `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` to run the
tests for the standard library

# After Submitting

Co-authored-by: blindFS <blindfs19@gmail.com>
2025-08-19 17:15:14 +08:00
Harper Andrews
458b8a5362 Fix error message: custom commands cannot be const (#16393)
# Description

Fixes the error you get when you parse something like `const c = random
int` to no longer imply that custom commands can be `const`. My
understanding is that they currently cannot (though that feature is
being tracked at #15074).

# User-Facing Changes

* Improved error message

---------

Co-authored-by: Stefan Holderbach <sholderbach@users.noreply.github.com>
2025-08-19 11:02:26 +02:00
Bruce Weirdan
778601b821 Extend nodeset output formats for query xml (#16465)
Refs
https://discord.com/channels/601130461678272522/615329862395101194/1406413134402551869

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

`query xml` now can output additional information when it returns
Nodesets:

* `--output-type` enables `type` column. It includes the node type
found, e.g. `element` or `comment`
* `--output-names` adds `local_name`, `prefixed_name` and `namespace`
columns
  * `--output-string-value` (re)adds `string_value` column

If you're using any of the `--output-*` switches, and want
`string_value` column to show up, pass `--output-string-value`
explicitly. In the absence of any `--output-*` attributes,
`--output-string-value` is assumed to be on.

## 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-08-18 18:57:56 -05:00
Bahex
bed0c99909 feat: watch returns a stream of events as a table when called without a closure (#16428)
`watch` command can now be used to _return a stream_ of detected events
instead of calling a closure with it's information, though using a
closure is still possible and existing uses won't break.

In addition to this:
```nushell
watch . {|operation, path, new_path|
    if $operation == "Write" and $path like "*.md" {
        md-lint $path
    }
}
```

Now this is also possible:
```nushell
watch .
| where operation == Write and path like "*.md"
| each { md-lint $in.path }
```
2025-08-18 23:28:15 +03:00
Bruce Weirdan
aea3309502 Use fixed column name for query xml output (#16461)
This is a breaking change.

Refs
https://discord.com/channels/601130461678272522/615329862395101194/1406413134402551869
Depends on (and includes) nushell/nushell#16459, which should be merged
first

Partially addresses nushell/nushell#15717

## Motivation and technical details

Variable column names are hard to work with. What's worse, currently
Nushell truncates the column name, making it even more unpredictable.
The only reliable way to deal with that is to rename the results column
like this:

```nushell
.... | query xml "//item/title|//title" | rename string_value | ...
```

so why would we make our users jump through these hoops? To provide some
parallels, `query db` does not add the query into its output, and
neither does `get`.

The choice of the column name comes from XPath spec:
https://www.w3.org/TR/xpath-10/#dt-string-value, adapted to Nushell
conventions

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

`query xml` outputs the results (for nodeset results) in a column with a
fixed name.

Before:

```nushell 
open -r tests/fixtures/formats/jt.xml 
| query xml '//channel/title|//item/title'
# => ╭───┬───────────────────────────────────────────╮
# => │ # │           //channel/title|/...            │
# => ├───┼───────────────────────────────────────────┤
# => │ 0 │ JT                                        │
# => │ 1 │ Creating crossplatform Rust terminal apps │
# => ╰───┴───────────────────────────────────────────╯
```

Now:

```nushell 
open -r tests/fixtures/formats/jt.xml 
| query xml '//channel/title|//item/title'
# => ╭───┬───────────────────────────────────────────╮
# => │ # │             string_value                  │
# => ├───┼───────────────────────────────────────────┤
# => │ 0 │ JT                                        │
# => │ 1 │ Creating crossplatform Rust terminal apps │
# => ╰───┴───────────────────────────────────────────╯
```

## 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-08-18 13:42:43 -05:00
Douglas
040a4eeaab Ability to specify a table name for kv commands (#16450)
Closes #15786 

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

`std-rfc/kv` commands now take an optional `--table (-t)` argument which
allows a custom table name to be used. If not specified, the current
`std-kv-store` table will be used.

## Tasks after submitting

- [x] Added in-help example to `kv set`. Did not add examples to the
other `kv` commands since they should be obvious based on the initial
`kv set`.

## Additional details

Example:

```nushell
use std-rfc/kv *
kv set -t foo bar 5
kv list
# Empty list, since the value was placed in a custom table
# => ╭────────────╮
# => │ empty list │
# => ╰────────────╯
kv list -t foo
# => ╭───┬─────┬───────╮
# => │ # │ key │ value │
# => ├───┼─────┼───────┤
# => │ 0 │ bar │     5 │
# => ╰───┴─────┴───────╯
```

To protect against injection attacks, table names can only include
alphanumeric characters with `_` and `-`.
2025-08-18 08:19:05 -04:00
Bruce Weirdan
1ddae02da7 Multiple output types for query xml (#16459)
This is a breaking change.

Refs
https://discord.com/channels/601130461678272522/615329862395101194/1406413134402551869

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

Previously, `query xml` always returned a table, even for scalar
results. Now scalar results will be returned as scalars.

For example

```nushell
open -r tests/fixtures/formats/jt.xml
| query xml 'false()'
```

used to return

```
╭───┬─────────╮
│ # │ false() │
├───┼─────────┤
│ 0 │ false   │
╰───┴─────────╯
```

and now it will return just `false`.

## 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-08-18 06:34:57 -05:00
Bruce Weirdan
a3b00060b4 Quote strings containing = (#16440)
Fixes nushell/nushell#16438

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

Previously, a record key `=` would not be quoted in `to nuon`, producing
invalid nuon output. It wasn't quoted in other string values either, but
it didn't cause problems there. Now any string containing `=` gets
quoted.
2025-08-17 22:33:07 +02:00
Stuart Carnie
fd4a04211a feat: commandline edit --accept to instantly execute command (#16193)
# Description

Fixes 
- #11065

Revised 
- #15092

Depends on

- https://github.com/nushell/reedline/pull/933

Adds the `--accept` flag to the `commandline` command, to immediately
accept the input.

Example use case: atuin

# User-facing changes

Users get the ability to pass `--accept` or `-A` to `commandline edit`
in order to immediately execute the resulting commandline.

# Tests + Formatting

I added two test cases that execute `commandline edit -A`.
There is also some documentation about their unintuitive expectations
output.

# After Submitting

The [docs](https://www.nushell.sh/commands/docs/commandline_edit.html)
can be updated to the new flag:

--accept, -A: immediately execute the command (no additional return
required)

> [!NOTE]
>
> This PR will be revised if / when
https://github.com/nushell/reedline/pull/933 is accepted

# Demo


[![asciicast](https://asciinema.org/a/Ql4r1oWu8J0C4MecmIZjxw5Pg.svg)](https://asciinema.org/a/Ql4r1oWu8J0C4MecmIZjxw5Pg)
2025-08-17 22:24:17 +02:00
Wind
a40f6d5cba fix uninlined_format_args clippy warnings (#16452)
I noticed some clippy errors while running clippy under 1.88.
```
error: variables can be used directly in the `format!` string
   --> src/config_files.rs:204:25
    |
204 |                         warn!("AutoLoading: {:?}", path);
    |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
    = note: `-D clippy::uninlined-format-args` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(clippy::uninlined_format_args)]`
```
And this pr is going to fix this.

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

## Tasks after submitting
NaN
2025-08-17 12:41:36 +02:00
Piepmatz
0b8531ed9d Add well-optimized string types (#16446) 2025-08-16 18:01:38 +02:00
Darren Schroeder
36427a7434 update to rust version 1.87.0 (#16437)
The PR upgrades nushell to rust version 1.87.0.

## Dev overview from clippy
- I added `result_large_err` to clippy in the root Cargo.toml to avoid
the warnings (and a few places in plugins). At some point a more proper
fix, perhaps boxing these, will need to be performed. This PR is to just
get us over the hump.
- I boxed a couple areas in some commands
- I changed `rdr.bytes()` to `BufReader::new(rdr).bytes()` in nu-json

## Release notes summary - What our users need to know
Users can use rust version 1.87.0 to compile nushell now

## Tasks after submitting
N/A
2025-08-14 11:27:34 -05:00
Bahex
daf52ba5c8 refactor: run env_change hooks before pre_prompt hooks (#16356)
Change the order of hook evaluations, run `env_change` before `pre_prompt`.
New order of execution is: `env_change` -> `pre_prompt` -> `PROMPT_COMMAND`
2025-08-14 02:11:05 +03:00
Tyarel8
2f7f00001d feat(std/bench) add osc 9;4 progress bar (#16245)
# Description
Using `osc 9;4`, `bench` shows a progress bar or circle on supported
terminals, every 10 timing rounds to not degrade performance too much.

# 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-13 16:49:39 -04:00
Bahex
ee7334a772 feat(get,select,reject): add --ignore-case which interprets cell-paths case insensitively, analogous to --optional (#16401)
# Description
Follow up to #16007

Also added some examples for existing flags which were previously
missing.

After the deprecation period of `--ignore-errors (-i)`, `-i` will be
used as the short form of this flag.

# User-Facing Changes
`get`, `select`, `reject` commands now have a `--ignore-case` flag,
which makes the commands interpret all cell-path arguments as completely
case insensitive.

# Tests + Formatting
+1

# After Submitting
Set a reminder for the `--ignore-errors` deprecation and using `-i` as
the short flag. Maybe we can make PRs in advance for future versions and
mark them with GitHub's milestones.
2025-08-13 16:45:33 -04:00
Tyarel8
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
Bruce Weirdan
91e72ae8b4 Validate std/random dice args (#16430)
Fixes #16429
2025-08-13 21:50:49 +02:00
Andrej Kolčin
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
Andrej Kolčin
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
David Yamnitsky
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
Andrej Kolčin
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
Bahex
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
Bahex
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
Bahex
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
Andrej Kolčin
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
Ecorous
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
Ecorous
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
zc he
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
Bruce Weirdan
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
Harper Andrews
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
Bruce Weirdan
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
Bruce Weirdan
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
Harper Andrews
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
Tyarel8
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
Maxim Zhiburt
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
zc he
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