Compare commits

...

109 Commits

Author SHA1 Message Date
91ff57faa7 Bump to version 0.99.0 (#14094)
<!--
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!
-->

# 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.
-->

# 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.
-->
2024-10-15 22:01:08 +03:00
b99affba4b bumping reedline to version 0.36 (#14093) 2024-10-15 11:05:57 -07:00
639bd4fc2e change display_error.exit_code to false (#13873)
The idea comes from @amtoine, I think it would be good to keey
`display_error.exit_code` same value, if user is using default config or
using no config file at all.
2024-10-14 09:57:30 -05:00
a0f38f8845 Fix deleted lowercase in keybinding parsing (#14081)
# Description
Adds back the `to_ascii_lowercase` deleted in #13802. Also fixes the
error messages having the lowercased value instead of the original
value.
2024-10-13 19:31:09 +00:00
a11c9e9d70 Ratelimit save command progress bar updates (#14075)
<!--
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!
-->

# 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.
-->

Currently, the `save -p` command updates the progress animation each
time any data is written. This PR rate limits the animation so it
doesn't play as fast.

Here's an asciinema of [current
behavior](https://asciinema.org/a/8RWrWTozQSceqx6tYY7kzblqj) and
[proposed behavior](https://asciinema.org/a/E1pi0gMwMwFcxVHOy9Fv1Kk6R).

# User-Facing Changes

* `save -p` progress bar has a smoother animation

# Tests + Formatting

- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

# After Submitting
N/A
2024-10-13 07:01:03 -05:00
bdbcf82967 Revert "Add the history import command" (#14077) 2024-10-12 21:43:24 -05:00
1f47d72e86 Add the history import command (#13450)
# Description

Adds a simple command for importing history between different file
formats. It essentially opens the history of the format opposite of the
one currently selected, and writes new items to the current history. It
also supports piping, because why not.

As more history backends are added, this may need to be extended -
either make the source explicit, or autodetect based on existing files.
For now it should be good though.

This should replace some of the work-arounds mentioned in
https://github.com/nushell/nushell/issues/9403.

I suspect it will have at least one problem:
https://github.com/nushell/nushell/issues/9403 mentions the history file
might be locked on Windows. That being said, I was able to successfully
import plaintext history into sqlite on Linux, so the command should be
functional at least in that environment.

The locking issue could be solved later by plumbing reedline history to
the command (so that it doesn't have to reopen it). But first, I want to
get some general input on the approach.

# User-Facing Changes
New command: `history import`

# Tests + Formatting
There's a unit test, but didn't add a proper integration test yet. Not
entirely sure how - I see there's the `nu!` macro for that, but not sure
how feasible it's to inspect history generated by commands ran that way.
Could use a hint.2
2024-10-12 16:42:27 -05:00
d83781ddec support filesize arguments in random binary/chars (#14068)
Closes #13920

# User-Facing Changes

`random binary` and `random chars` now support filesize arguments:

```nushell
random binary 1kb
random chars --length 1kb
```
2024-10-12 14:49:05 +08:00
e32e55938b Reduce nesting in the history command code (#14069)
# Description

This is a purely cosmetic change to make the code read more linearly.

# User-Facing Changes

None.
2024-10-12 14:44:49 +08:00
de08b68ba8 Fix try printing when it is not the last pipeline element (#13992)
# Description

Fixes #13991. This was done by more clearly separating the case when a
pipeline is drained vs when it is being written (to a file).

I also added an `OutDest::Print` case which might not be strictly
necessary, but is a helpful addition.

# User-Facing Changes

Bug fix.

# Tests + Formatting

Added a test.

# After Submitting

There are still a few redirection bugs that I found, but they require
larger code changes, so I'll leave them until after the release.
2024-10-12 14:37:10 +08:00
0e3a8c552c Correct wording from previous PR (#14066)
# Description

Apologies - The updated wording I used in the last PR *description* was
not what I actually pushed. I failed to commit and push the last update.
This PR fixes the code to reflect what was described in #14065:

```
-r, --header-row - use the first input column as the table header-row (or keynames when combined with --as-record)
```

# User-Facing Changes

Help/doc only

# Tests + Formatting

- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

(And visually confirmed help changes ;-))

# After Submitting

N/A
2024-10-11 13:57:32 -05:00
389e7d2502 make FooterMode::Auto work (#14063)
# Description

@Yethal discovered that `FooterMode::Auto` in the config as
`$env.config.footer_mode = auto` did not work. This PR attempts to fix
that problem by implementing the auto algorithm that was already
supposed to work.

# 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.
-->
2024-10-11 13:36:09 -05:00
fce6146576 Refactor config updates (#13802)
# Description
This PR standardizes updates to the config through a new
`UpdateFromValue` trait. For now, this trait is private in case we need
to make changes to it.

Note that this PR adds some additional `ShellError` cases to create
standard error messages for config errors. A follow-up PR will move
usages of the old error cases to these new ones. This PR also uses
`Type::custom` in lots of places (e.g., for string enums). Not sure if
this is something we want to encourage.

# User-Facing Changes
Should be none.
2024-10-11 18:40:32 +02:00
02313e6819 Fix --header-row description (#14065)
# Description

The help description on `transpose --header-row/-r` appears to be wrong
(and now that I understand that, it probably explains why it's confused
me for so long).

It currently says:

```
 -r, --header-row - treat the first row as column names
```

This just looks wrong - The first **row** of the input data is not
considered. It's the first **column** that is used to create the
header-row of the transposed table.

For example:

To record using `-dr`:

```nu
[[col-names         values ];
 [foo                  1   ]
 [bar                  5   ]
 [baz                  7   ]
 [cat                  -12 ]
] | transpose -dr

╭─────┬─────╮
│ foo │ 1   │
│ bar │ 5   │
│ baz │ 7   │
│ cat │ -12 │
╰─────┴─────╯
```

To table using `-r`:

```nu
[[col-names         values ];
 [foo                  1   ]
 [bar                  5   ]
 [baz                  7   ]
 [cat                  -12 ]
] | transpose -r

╭───┬─────┬─────┬─────┬─────╮
│ # │ foo │ bar │ baz │ cat │
├───┼─────┼─────┼─────┼─────┤
│ 0 │   1 │   5 │   7 │ -12 │
╰───┴─────┴─────┴─────┴─────╯
```

# User-Facing Changes

Updates the help description to:

```
-r, --header-row - use the first input column as the table header-row (or keynames when combined with --as-record)
```

# Tests + Formatting

- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

# After Submitting

N/A
2024-10-11 10:14:58 -05:00
df0a174802 fix unknown_command when parsing certain strings with equal signs (#14053)
# Description

Prevents errors when `=` is used before the end of:

- strings in lists/records (with a symbol adjacent to the quotes)
- raw strings

```
> ["=a"]
Error: nu::parser::unknown_command

  × Unknown command.
   ╭─[entry #9:1:1]
 1 │ ["=a"]
   · ───┬──
   ·    ╰── unknown command
   ╰────
```

```
> r#'=a'#
Error: nu::parser::unknown_command

  × Unknown command.
   ╭─[entry #5:1:1]
 1 │ r#'=a'#
   · ───┬───
   ·    ╰── unknown command
   ╰────
```

Closes #13902, closes #13901, closes #9879, closes #6401, closes #5806

# User-Facing Changes

Variable names in environment shorthand assignments must satisfy
`is_identifier`.
2024-10-11 07:53:39 -05:00
bcb7ef48b6 Reduce duplication in history path construction (#13475)
# Description
Currently there is a bit of chaos regarding construction of history file
paths. Various pieces of code across a number of crates reimplement the
same/similar logic:
- There is `get_history_path`, but it requires a directory parameter (it
really just joins it with a file name).
- Some places use a const for the directory parameter, others use a
string literal - in all cases the value seems to be `"nushell"`.
- Some places assume the `"nushell"` value, other plumb it down from
close to the top of the call stack.
- Some places use a constant for history file names while others assume
it.

This PR tries to make it so that the history/config path format is
defined in a single places and so dependencies on it are easier to
follow:
- It removes `get_history_path` and adds a `file_path` method to
`HistoryConfig` instead (an extra motivation being, this is a convenient
place that can be used from all creates that need a history file path)
- Adds a `nu_config_dir` function that returns the nushell configuration
directory.
- Updates existing code to rely on the above, effectively removing
duplicate uses of `"nushell"` and `NUSHELL_FOLDER` and assumptions about
file names associated with different history formats

# User-Facing Changes
None
2024-10-11 07:51:50 -05:00
9f714e62cb [umkdir][tests] get umask instead of assuming it (#14046)
# Description

Contributors to this projects will have a test failure if their `umask`
is not set to `0022`.

Apparently on Debian (at least on my install), it is set to `0002` which
makes my test fail. While `0022` is safer than the value I have, I want
to reduce the amount if issue new contributors could have.

I am making this test not assuming anything and instead, reading the
user umask.

# Related discussion

I see that the `umask` command implementation has been discussed in
#12256 . We could use this and enforce a umask for tests who rely on
this. I believe however (let me know what you think) that hard coded
values are harder to read in the test.



# User-Facing Changes
N/A

# Tests + Formatting
All green on my side after this MR 👍 


# After Submitting
Documentation is not impacted

---------

Co-authored-by: Stefan Holderbach <sholderbach@users.noreply.github.com>
2024-10-11 14:13:42 +02:00
a95c2198a6 Remove group command (#14056)
# Description

Removes the `group` command that was deprecated back in 0.96.0 with
#13377.

# User-Facing Changes

Breaking change, removed `group` command.
2024-10-11 06:43:12 -05:00
2df91e7f92 Removed CustomValue portion of CustomValue type name strings. (#14054)
# Description

This changes the names returned by CustomValue::name() of the various
custom value structs to just say the name of the thing they represent.
For instance "DataFrameCustomValue" is not just "DataFrame".

# User-Facing Changes
- Places such as or errors where NuDataFrameCustomValue would be seen,
now just shows as NuDataFrame.
2024-10-11 06:41:24 -05:00
44be445b57 Revert "fix $env.FILE_PWD and $env.CURRENT_FILE inside use (#13958)" (#14057)
This reverts commit 5002d87af4 from pr
#13958

It seems that something unexpected happened from
[@ealap](https://github.com/ealap)'s report. Thanks!

Reopen: #13425
2024-10-11 14:45:42 +08:00
e43632fd95 Create Sha256sum file for each release binary (#14050)
<!--
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!
-->

# 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.
-->

Create Sha256sum file for each release binary
A test release could be found here:
https://github.com/nushell/nightly/releases/tag/0.98.2
2024-10-11 11:16:22 +08:00
69e4abad0f hard-code selection color to be reverse (#14052)
# Description

This PR makes visual selection in Nushell a little bit more readable.

### Before

![image](https://github.com/user-attachments/assets/3020abd2-c02c-4f16-b68a-cbe72278cbc8)

### After

![image](https://github.com/user-attachments/assets/fcf919fa-bc02-449b-b5bc-ed05959cc7de)

# 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.
-->
2024-10-10 12:55:01 -05:00
3bedbd0669 Respect use_ansi_coloring setting in banner (#14049)
# Description

Partial fix for #14043 - If `$env.config.use_ansi_coloring` is `false`,
strip the ansi coloring before displaying.

# User-Facing Changes

Bug fix

# Tests + Formatting

- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

# After Submitting

N/A
2024-10-10 09:58:37 -05:00
1d15bbc95b Making nushell works better with external args which surrounded by backtick quotes (#13910)
# Description
Fixes: #13431
Fixes: #13578

The issue happened because nushell thinks external program name and
external arg with totally same rule. But actually they are a little bit
different.
When parsing external program name, backtick is a thing and it should be
keeped.
But when parsing external args, backtick is just a mark that it's a
**bareword which may contain space**. So in this context, it's already
useless.

# User-Facing Changes
After the pr, the following command will work as intended.
```nushell
> ^echo `"hello"`
hello
```

# Tests + Formatting
Added 3 test cases.
2024-10-10 20:57:30 +08:00
5002d87af4 fix $env.FILE_PWD and $env.CURRENT_FILE inside use (#13958)
# Description
Fixes: #13425 

Similar to `source-env`, `use` command should also remove `FILE_PWD` and
`CURRENT_FILE` after evaluating code block in the module file.

And user input can be a directory, in this case, we need to use the
return value of `find_in_dirs_env` carefully, so in case, I renamed
`maybe_file_path` to `maybe_file_path_or_dir` to emphasize it.

# User-Facing Changes
`$env.FILE_PWD` and `$env.CURRENT_FILE` will be more reliable to use.

# Tests + Formatting
Added 2 test cases.

# After Submitting
NaN
2024-10-10 20:54:00 +08:00
2a3805c164 Virtual std module subdirectories (#14040)
# Description

Uses "normal" module `std/<submodule>/mod.nu` instead of renaming the
files (as requested in #13842).

# User-Facing Changes

No user-facing changes other than in `view files` results. Imports
remain the same after this PR.

# Tests + Formatting

- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

Also manually confirmed that it does not interfere with nupm, since we
did have a conflict at one point (and it's not possible to test here).

# Performance Tests

## Linux

### Nushell Startup - No config

```nu
bench --pretty -n 200  { <path_to>/nu -c "exit" }
```

| Release | Startup Time |
| --- | --- |
| 0.98.0 | 22ms 730µs 768ns +/- 1ms 515µs 942ns
| This commit | 9ms 312µs 68ns +/- 709µs 378ns
| Yesterday's nightly | 9ms 230µs 953ns +/- 9ms 67µs 689ns

### Nushell Startup - Load full standard library

Measures relative impact of a full `use std *`, which isn't recommended,
but worth tracking.

```nu
bench --pretty -n 200  { <path_to>/nu -c "use std *; exit" }
```

| Release | Startup Time |
| --- | --- |
| 0.98.0 | 23ms 10µs 636ns +/- 1ms 277µs 854ns
| This commit | 26ms 922µs 769ns +/- 562µs 538ns
| Yesterday's nightly | 28ms 133µs 95ns +/- 761µs 943ns
| `deprecated_dirs` removal PR * | 23ms 610µs 333ns +/- 369µs 436ns

\* Current increase is partially due to double-loading `dirs` with
removal warning in older version.

# After Submitting

Still TODO - Update standard library doc
2024-10-10 06:56:37 -05:00
52f646d8db fix format date by getting the env vars properly (#14037)
# Description

This PR is from a [discussion in
Discord](https://discord.com/channels/601130461678272522/988303282931912704/1292900183742611466).
The gist is that `format date` didn't respect the $env.LC_TIME env var.
The reason for this is because it was using std::env::var which doesn't
understand nushell's env. Now, this should work.

![image](https://github.com/user-attachments/assets/e4d494b1-9f2b-4993-9729-244e0c47ef0c)


# 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.
-->
2024-10-10 06:38:26 -05:00
36c1073441 Rework sorting and add cell path and closure comparators to sort-by (#13154)
# Description

Closes #12535
Implements sort-by functionality of #8322
Fixes sort-by part of #8667

This PR does two main things: add a new cell path and closure parameter
to `sort-by`, and attempt to make Nushell's sorting behavior
well-defined.

## `sort-by` features

The `columns` parameter is replaced with a `comparator` parameter, which
can be a cell path or a closure. Examples are from docs PR.

1. Cell paths

The basic interactive usage of `sort-by` is the same. For example, `ls |
sort-by modified` still works the same as before. It is not quite a
drop-in replacement, see [behavior changes](#behavior-changes).
   
   Here's an example of how the cell path comparator might be useful:
   
   ```nu
   > let cities = [
{name: 'New York', info: { established: 1624, population: 18_819_000 } }
{name: 'Kyoto', info: { established: 794, population: 37_468_000 } }
{name: 'São Paulo', info: { established: 1554, population: 21_650_000 }
}
   ]
   > $cities | sort-by info.established
   ╭───┬───────────┬────────────────────────────╮
   │ # │   name    │            info            │
   ├───┼───────────┼────────────────────────────┤
   │ 0 │ Kyoto     │ ╭─────────────┬──────────╮ │
   │   │           │ │ established │ 794      │ │
   │   │           │ │ population  │ 37468000 │ │
   │   │           │ ╰─────────────┴──────────╯ │
   │ 1 │ São Paulo │ ╭─────────────┬──────────╮ │
   │   │           │ │ established │ 1554     │ │
   │   │           │ │ population  │ 21650000 │ │
   │   │           │ ╰─────────────┴──────────╯ │
   │ 2 │ New York  │ ╭─────────────┬──────────╮ │
   │   │           │ │ established │ 1624     │ │
   │   │           │ │ population  │ 18819000 │ │
   │   │           │ ╰─────────────┴──────────╯ │
   ╰───┴───────────┴────────────────────────────╯
   ```

2. Key closures

You can supply a closure which will transform each value into a sorting
key (without changing the underlying data). Here's an example of a key
closure, where we want to sort a list of assignments by their average
grade:

   ```nu
   > let assignments = [
       {name: 'Homework 1', grades: [97 89 86 92 89] }
       {name: 'Homework 2', grades: [91 100 60 82 91] }
       {name: 'Exam 1', grades: [78 88 78 53 90] }
       {name: 'Project', grades: [92 81 82 84 83] }
   ]
   > $assignments | sort-by { get grades | math avg }
   ╭───┬────────────┬───────────────────────╮
   │ # │    name    │        grades         │
   ├───┼────────────┼───────────────────────┤
   │ 0 │ Exam 1     │ [78, 88, 78, 53, 90]  │
   │ 1 │ Project    │ [92, 81, 82, 84, 83]  │
   │ 2 │ Homework 2 │ [91, 100, 60, 82, 91] │
   │ 3 │ Homework 1 │ [97, 89, 86, 92, 89]  │
   ╰───┴────────────┴───────────────────────╯
   ```

3. Custom sort closure

The `--custom`, or `-c`, flag will tell `sort-by` to interpret closures
as custom sort closures. A custom sort closure has two parameters, and
returns a boolean. The closure should return `true` if the first
parameter comes _before_ the second parameter in the sort order.
   
For a simple example, we could rewrite a cell path sort as a custom sort
(see
[here](https://github.com/nushell/nushell.github.io/pull/1568/files#diff-a7a233e66a361d8665caf3887eb71d4288000001f401670c72b95cc23a948e86R231)
for a more complex example):
   
   ```nu
   > ls | sort-by -c {|a, b| $a.size < $b.size }
   ╭───┬─────────────────────┬──────┬──────────┬────────────────╮
   │ # │        name         │ type │   size   │    modified    │
   ├───┼─────────────────────┼──────┼──────────┼────────────────┤
   │ 0 │ my-secret-plans.txt │ file │    100 B │ 10 minutes ago │
   │ 1 │ shopping_list.txt   │ file │    100 B │ 2 months ago   │
   │ 2 │ myscript.nu         │ file │  1.1 KiB │ 2 weeks ago    │
   │ 3 │ bigfile.img         │ file │ 10.0 MiB │ 3 weeks ago    │
   ╰───┴─────────────────────┴──────┴──────────┴────────────────╯
   ```
   

## Making sort more consistent

I think it's important for something as essential as `sort` to have
well-defined semantics. This PR contains some changes to try to make the
behavior of `sort` and `sort-by` consistent. In addition, after working
with the internals of sorting code, I have a much deeper understanding
of all of the edge cases. Here is my attempt to try to better define
some of the semantics of sorting (if you are just interested in changes,
skip to "User-Facing changes")

- `sort`, `sort -v`, and `sort-by` now all work the same. Each
individual sort implementation has been refactored into two functions in
`sort_utils.rs`: `sort`, and `sort_by`. These can also be used in other
parts of Nushell where values need to be sorted.
  - `sort` and `sort-by` used to handle `-i` and `-n` differently.
- `sort -n` would consider all values which can't be coerced into a
string to be equal
- `sort-by -i` and `sort-by -n` would only work if all values were
strings
- In this PR, insensitive sort only affects comparison between strings,
and natural sort only applies to numbers and strings (see below).
- (not a change) Before and after this PR, `sort` and `sort-by` support
sorting mixed types. There was a lot of discussion about potentially
making `sort` and `sort-by` only work on lists of homogeneous types, but
the general consensus was that `sort` should not error just because its
input contains incompatible types.
- In order to try to make working with data containing `null` values
easier, I changed the PartialOrd order to sort `Nothing` values to the
end of a list, regardless of what other types the list contains. Before,
`null` would be sorted before `Binary`, `CellPath`, and `Custom` values.
- (not a change) When sorted, lists of mixed types will contain sorted
values of each type in order, for the most part
- (not a change) For example, `[0x[1] (date now) "a" ("yesterday" | into
datetime) "b" 0x[0]]` will be sorted as `["a", "b", a day ago, now, [0],
[1]]`, where sorted strings appear first, then sorted datetimes, etc.
- (not a change) The exception to this is `Int`s and `Float`s, which
will intermix, `Strings` and `Glob`s, which will intermix, and `None` as
described above. Additionally, natural sort will intermix strings with
ints and floats (see below).
- Natural sort no longer coerce all inputs to strings.
- I did originally make natural only apply to strings, but @fdncred
pointed out that the previous behavior also allowed you to sort numeric
strings with numbers. This seems like a useful feature if we are trying
to support sorting with mixed types, so I settled on coercing only
numbers (int, float). This can be reverted if people don't like it.
- Here is an example of this behavior in action, which is the same
before and after this PR:
      ```nushell
      $ [1 "4" 3 "2"] | sort --natural
      ╭───┬───╮
      │ 0 │ 1 │
      │ 1 │ 2 │
      │ 2 │ 3 │
      │ 3 │ 4 │
      ╰───┴───╯
      ```



# User-Facing Changes

## New features

- Replaces the `columns` string parameter of `sort-by` with a cell path
or a closure.
  - The cell path parameter works exactly as you would expect
- By default, the `closure` parameter acts as a "key sort"; that is,
each element is transformed by the closure into a sorting key
- With the `--custom` (`-c`) parameter, you can define a comparison
function for completely custom sorting order.

## Behavior changes

<details>
<summary><code>sort -v</code> does not coerce record values to
strings</summary>

This was a bit of a surprising behavior, and is now unified with the
behavior of `sort` and `sort-by`. Here's an example where you can
observe the values being implicitly coerced into strings for sorting, as
they are sorted like strings rather than numbers:

Old behavior:

```nushell
$ {foo: 9 bar: 10} | sort -v
╭─────┬────╮
│ bar │ 10 │
│ foo │ 9  │
╰─────┴────╯
```

New behavior:

```nushell
$ {foo: 9 bar: 10} | sort -v
╭─────┬────╮
│ foo │ 9  │
│ bar │ 10 │
╰─────┴────╯
```

</details>


<details>
<summary>Changed <code>sort-by</code> parameters from
<code>string</code> to <code>cell-path</code> or <code>closure</code>.
Typical interactive usage is the same as before, but if passing a
variable to <code>sort-by</code> it must be a cell path (or closure),
not a string</summary>

Old behavior:

```nushell
$ let sort = "modified"
$ ls | sort-by $sort
╭───┬──────┬──────┬──────┬────────────────╮
│ # │ name │ type │ size │    modified    │
├───┼──────┼──────┼──────┼────────────────┤
│ 0 │ foo  │ file │  0 B │ 10 hours ago   │
│ 1 │ bar  │ file │  0 B │ 35 seconds ago │
╰───┴──────┴──────┴──────┴────────────────╯
```

New behavior:

```nushell
$ let sort = "modified"
$ ls | sort-by $sort
Error: nu:🐚:type_mismatch

  × Type mismatch.
   ╭─[entry #10:1:14]
 1 │ ls | sort-by $sort
   ·              ──┬──
   ·                ╰── Cannot sort using a value which is not a cell path or closure
   ╰────
$ let sort = $."modified"
$ ls | sort-by $sort
╭───┬──────┬──────┬──────┬───────────────╮
│ # │ name │ type │ size │   modified    │
├───┼──────┼──────┼──────┼───────────────┤
│ 0 │ foo  │ file │  0 B │ 10 hours ago  │
│ 1 │ bar  │ file │  0 B │ 2 minutes ago │
╰───┴──────┴──────┴──────┴───────────────╯
```
</details>

<details>
<summary>Insensitve and natural sorting behavior reworked</summary>

Previously, the `-i` and `-n` worked differently for `sort` and
`sort-by` (see "Making sort more consistent"). Here are examples of how
these options result in different sorts now:

1. `sort -n`
- Old behavior (types other than numbers, strings, dates, and binary
sorted incorrectly)
      ```nushell
      $ [2sec 1sec] | sort -n
      ╭───┬──────╮
      │ 0 │ 2sec │
      │ 1 │ 1sec │
      ╰───┴──────╯
      ```
    - New behavior
      ```nushell
      $ [2sec 1sec] | sort -n
      ╭───┬──────╮
      │ 0 │ 1sec │
      │ 1 │ 2sec │
      ╰───┴──────╯
      ```
    
2. `sort-by -i`
- Old behavior (uppercase words appear before lowercase words as they
would in a typical sort, indicating this is not actually an insensitive
sort)
     ```nushell
     $ ["BAR" "bar" "foo" 2 "FOO" 1] | wrap a | sort-by -i a
     ╭───┬─────╮
     │ # │  a  │
     ├───┼─────┤
     │ 0 │   1 │
     │ 1 │   2 │
     │ 2 │ BAR │
     │ 3 │ FOO │
     │ 4 │ bar │
     │ 5 │ foo │
     ╰───┴─────╯
     ```
- New behavior (strings are sorted stably, indicating this is an
insensitive sort)
     ```nushell
     $ ["BAR" "bar" "foo" 2 "FOO" 1] | wrap a | sort-by -i a
     ╭───┬─────╮
     │ # │  a  │
     ├───┼─────┤
     │ 0 │   1 │
     │ 1 │   2 │
     │ 2 │ BAR │
     │ 3 │ bar │
     │ 4 │ foo │
     │ 5 │ FOO │
     ╰───┴─────╯
     ```

3. `sort-by -n`
- Old behavior (natural sort does not work when data contains non-string
values)
     ```nushell
     $ ["10" 8 "9"] | wrap a | sort-by -n a
     ╭───┬────╮
     │ # │ a  │
     ├───┼────┤
     │ 0 │  8 │
     │ 1 │ 10 │
     │ 2 │ 9  │
     ╰───┴────╯
     ```
   - New behavior
     ```nushell
     $ ["10" 8 "9"] | wrap a | sort-by -n a
     ╭───┬────╮
     │ # │ a  │
     ├───┼────┤
     │ 0 │  8 │
     │ 1 │ 9  │
     │ 2 │ 10 │
     ╰───┴────╯
     ```

</details>

<details>
<summary>
Sorting a list of non-record values with a non-existent column/path now
errors instead of sorting the values directly (<code>sort</code> should
be used for this, not <code>sort-by</code>)
</summary>

Old behavior:

```nushell
$ [2 1] | sort-by foo
╭───┬───╮
│ 0 │ 1 │
│ 1 │ 2 │
╰───┴───╯
```

New behavior:

```nushell
$ [2 1] | sort-by foo
Error: nu:🐚:incompatible_path_access

  × Data cannot be accessed with a cell path
   ╭─[entry #29:1:17]
 1 │ [2 1] | sort-by foo
   ·                 ─┬─
   ·                  ╰── int doesn't support cell paths
   ╰────
```

</details>

<details>
<summary><code>sort</code> and <code>sort-by</code> output
<code>List</code> instead of <code>ListStream</code> </summary>

This isn't a meaningful change (unless I misunderstand the purpose of
ListStream), since `sort` and `sort-by` both need to collect in order to
do the sorting anyway, but is user observable.

Old behavior:

```nushell
$ ls | sort | describe -d
╭──────────┬───────────────────╮
│ type     │ stream            │
│ origin   │ nushell           │
│ subtype  │ {record 3 fields} │
│ metadata │ {record 1 field}  │
╰──────────┴───────────────────╯
```

```nushell
$ ls | sort-by name | describe -d
╭──────────┬───────────────────╮
│ type     │ stream            │
│ origin   │ nushell           │
│ subtype  │ {record 3 fields} │
│ metadata │ {record 1 field}  │
╰──────────┴───────────────────╯
```

New behavior:


```nushell
ls | sort | describe -d
╭────────┬─────────────────╮
│ type   │ list            │
│ length │ 22              │
│ values │ [table 22 rows] │
╰────────┴─────────────────╯
```

```nushell
$ ls | sort-by name | describe -d
╭────────┬─────────────────╮
│ type   │ list            │
│ length │ 22              │
│ values │ [table 22 rows] │
╰────────┴─────────────────╯
```

</details>

- `sort` now errors when nothing is piped in (`sort-by` already did
this)

# Tests + Formatting

I added lots of unit tests on the new sort implementation to enforce new
sort behaviors and prevent regressions.

# After Submitting

See [docs PR](https://github.com/nushell/nushell.github.io/pull/1568),
which is ~2/3 finished.

---------

Co-authored-by: NotTheDr01ds <32344964+NotTheDr01ds@users.noreply.github.com>
Co-authored-by: Ian Manske <ian.manske@pm.me>
2024-10-09 19:18:16 -07:00
2979595cc5 [str replace] add exemple for escaped regexes (#14038)
# Description

This is a follow-up of
https://github.com/nushell/nushell.github.io/pull/1584

The goal is to provide the user understanding of how to escape strings

# User-Facing Changes
Nothing except documentation

# Tests + Formatting
 
 I don't know why but these two tests are failing on my system:

- `test_std_util path_add`
- `commands::umkdir::mkdir_umask_permission`

Since I hardly believe it is linked to my changes, I will let your CI
check it. Meanwhile, I will check my system, highly likely that it is
something something related to me recently switching shells, hacking my
way through prompts environments, etc.


# After Submitting

Will check how to re-generate the [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged
2024-10-09 13:35:56 -05:00
d67120be19 update to reedline 5e556bfd (#14034)
# Description

This PR updates nushell to the latest commit 5e556bfd.

# 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.
-->
2024-10-09 09:07:34 -05:00
ad31f1cf26 Fix dirs removal warning (#14029)
# Description

* Primary purpose is to fix an issue with a missing escaped opening
parenthesis in the warning message when running an old `dirs` alias.
This was creating an error condition from improper interpolation.

Also

* Incorporates #13842 feedback from @kubouch by renaming `std/lib` to
`std/util`
* Removes duplication of code in `export-env`
* Renames submodule exports to `std/<submodule>` rather than
`./<submodule>` - No user-facing change other than `view files` appears
"prettier".
* In #13842, I converted the test cases to use `use std/<module>`
syntax. Previously, the tests were (effectively) using `use std *` (due
to pre-existing bugs, now fixed).

So "before", we only had test coverage on `use std *`, and "after" we
only had test coverage on `use std/<module>`. I've started adding test
cases so that we have coverage on *both* scenarios going forward.

For now, `formats` and `util` have been updated with tests for both
scenarios. I'll continue adding the others in future PRs.

# User-Facing Changes

No user-facing changes - Bug fix, refactor, and test cases only

# Tests + Formatting

- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

# After Submitting

Still working on updating the Doc. I ran into the `dirs` issue while
writing it and rabbit-trailed to fix it in this PR.
2024-10-09 08:03:33 -05:00
99798ace7d Bump crate-ci/typos from 1.25.0 to 1.26.0 (#14031)
Bumps [crate-ci/typos](https://github.com/crate-ci/typos) from 1.25.0 to
1.26.0.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/crate-ci/typos/releases">crate-ci/typos's
releases</a>.</em></p>
<blockquote>
<h2>v1.26.0</h2>
<h2>[1.26.0] - 2024-10-07</h2>
<h3>Compatibility</h3>
<ul>
<li><em>(pre-commit)</em> Requires 3.2+</li>
</ul>
<h3>Fixes</h3>
<ul>
<li><em>(pre-commit)</em> Resolve deprecations in 4.0 about deprecated
stage names</li>
</ul>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/crate-ci/typos/blob/master/CHANGELOG.md">crate-ci/typos's
changelog</a>.</em></p>
<blockquote>
<h2>[1.26.0] - 2024-10-07</h2>
<h3>Compatibility</h3>
<ul>
<li><em>(pre-commit)</em> Requires 3.2+</li>
</ul>
<h3>Fixes</h3>
<ul>
<li><em>(pre-commit)</em> Resolve deprecations in 4.0 about deprecated
stage names</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="6802cc60d4"><code>6802cc6</code></a>
chore: Release</li>
<li><a
href="caa55026ae"><code>caa5502</code></a>
docs: Update changelog</li>
<li><a
href="2114c19241"><code>2114c19</code></a>
Merge pull request <a
href="https://redirect.github.com/crate-ci/typos/issues/1114">#1114</a>
from tobiasraabe/patch-1</li>
<li><a
href="9de7b2c6be"><code>9de7b2c</code></a>
Updates stage names in <code>.pre-commit-hooks.yaml</code>.</li>
<li><a
href="14f49f455c"><code>14f49f4</code></a>
Merge pull request <a
href="https://redirect.github.com/crate-ci/typos/issues/1105">#1105</a>
from crate-ci/renovate/unicode-width-0.x</li>
<li><a
href="58ffa4baef"><code>58ffa4b</code></a>
Merge pull request <a
href="https://redirect.github.com/crate-ci/typos/issues/1108">#1108</a>
from crate-ci/renovate/stable-1.x</li>
<li><a
href="003cb76937"><code>003cb76</code></a>
chore(deps): Update dependency STABLE to v1.81.0</li>
<li><a
href="bc00184a23"><code>bc00184</code></a>
chore(deps): Update Rust crate unicode-width to 0.2.0</li>
<li>See full diff in <a
href="https://github.com/crate-ci/typos/compare/v1.25.0...v1.26.0">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=crate-ci/typos&package-manager=github_actions&previous-version=1.25.0&new-version=1.26.0)](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>
2024-10-09 09:52:36 +08:00
ba4becc61c Bump indexmap from 2.5.0 to 2.6.0 (#13983)
Bumps [indexmap](https://github.com/indexmap-rs/indexmap) from 2.5.0 to
2.6.0.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/indexmap-rs/indexmap/blob/master/RELEASES.md">indexmap's
changelog</a>.</em></p>
<blockquote>
<h2>2.6.0 (2024-10-01)</h2>
<ul>
<li>Implemented <code>Clone</code> for <code>map::IntoIter</code> and
<code>set::IntoIter</code>.</li>
<li>Updated the <code>hashbrown</code> dependency to version 0.15.</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="bf0362ba25"><code>bf0362b</code></a>
Merge pull request <a
href="https://redirect.github.com/indexmap-rs/indexmap/issues/354">#354</a>
from cuviper/release-2.6.0</li>
<li><a
href="bd0b4f7c8c"><code>bd0b4f7</code></a>
Add all release dates</li>
<li><a
href="53400496f4"><code>5340049</code></a>
Release 2.6.0</li>
<li><a
href="7f8022912a"><code>7f80229</code></a>
Merge pull request <a
href="https://redirect.github.com/indexmap-rs/indexmap/issues/343">#343</a>
from cuviper/hash_table</li>
<li><a
href="e577bf2556"><code>e577bf2</code></a>
Use <code>hashbrown::HashTable</code> instead of
<code>RawTable</code></li>
<li><a
href="09b48ec3b3"><code>09b48ec</code></a>
Merge pull request <a
href="https://redirect.github.com/indexmap-rs/indexmap/issues/353">#353</a>
from cuviper/move_index</li>
<li><a
href="267b83d701"><code>267b83d</code></a>
Add an explicit bounds check in <code>move_index</code></li>
<li><a
href="d74a4daffb"><code>d74a4da</code></a>
Merge pull request <a
href="https://redirect.github.com/indexmap-rs/indexmap/issues/349">#349</a>
from waywardmonkeys/improve-doc-formatting</li>
<li><a
href="5b0ed20b87"><code>5b0ed20</code></a>
docs: Improve doc formatting with backticks</li>
<li><a
href="15518f3152"><code>15518f3</code></a>
Merge pull request <a
href="https://redirect.github.com/indexmap-rs/indexmap/issues/348">#348</a>
from cuviper/clone-intoiter</li>
<li>Additional commits viewable in <a
href="https://github.com/indexmap-rs/indexmap/compare/2.5.0...2.6.0">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=indexmap&package-manager=cargo&previous-version=2.5.0&new-version=2.6.0)](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>
Co-authored-by: Jack Wright <jack.wright@disqo.com>
2024-10-08 17:07:21 -07:00
397499b106 Add ls colors to cjs and mjs files (#14028)
<!--
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!
-->

# 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.
-->
Add ls color highlighting for *.cjs and *.mjs files in line with regular
*.js files
Add an icon to *.cjs files in line with *.js and *.mjs files
2024-10-08 08:55:20 -05:00
55c3fc9141 Improve keybinding parsing for Unicode support (#14020)
# Description

This pull request enhances the `add_parsed_keybinding` function to
provide greater flexibility in specifying keycodes for keybindings in
Nushell. Previously, the function only supported specifying keycodes
directly through character notation (e.g., `char_e` for the character
`e`). This limited users to a small set of keybindings, especially in
scenarios where specific non-English characters were needed.

With this new version, users can also specify characters using their
Unicode codes, such as `char_u003B` for the semicolon (`;`), providing a
more flexible approach to customization, for example like this:

```nushell
{
    name: move_to_line_end_or_take_history_hint
    modifier: shift
    keycode: char_u003B # char_;
    mode: vi_normal
    event: {
        until: [
            { send: historyhintcomplete }
            { edit: movetolineend }
        ]
    }
}
```

# User-Facing Changes

Added support for specifying keycodes using Unicode codes, e.g.,
char_u002C (comma - `,`):

```nushell
{
    name: <command_name>, # name of the command
    modifier: none,       # key modifier
    keycode: char_u002C,  # Unicode code for the comma (',')
    mode: vi_normal,      # mode in which this binding should work
    event: {
        send: <action>    # action to be performed
    }
}
```
2024-10-08 14:42:15 +02:00
2830ec008c Replace the old encode base64 and decode base64 with new-base64 commands (#14018)
<!--
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!
-->

# 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.
-->
Maybe we can deprecate `encode new-base64` and `decode new-base64`
first, to make the code clean and simple I'd rather remove the old
`encode base64` and `decode base64` and replace them with the `*
new-base64` commands.

Related PR: https://github.com/nushell/nushell/pull/13428

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

- `encode new-base64` --> `encode base64`
- `decode new-base64` --> `decode base64`

# 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.
-->

It's a breaking change
2024-10-08 11:01:43 +08:00
4c8b09eb97 Load env when importing with use std * (#14012)
# Description

After a `use std *`, the environment variables exported from the
submodules' `export-env` blocks are not available because of #13403.
This causes failures in `log` (currently) and will cause issues in
`dirs` once we stop autoloading it separately.

When the submodules are loaded separately (e.g., `use std/log`),
everything already worked correctly. While this is the preferred way of
doing it, we also want `use std *` to work properly.

This is a workaround for the standard library submodules. It is
definitely not ideal, but it can be removed when and if #13403 is fixed.

For now, we need to duplicate any environment settings in both the
submodules (when loaded with `use std/log`) and in the standard library
itself (when loaded with `use std *`). Again, this should not be
necessary, but currently is because of #13403.

# User-Facing Changes

Bug fix

# Tests + Formatting

- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

# After Submitting

N/A
2024-10-07 09:34:47 +03:00
98e0864be8 update nushell to reedline 871075e (#14017)
# Description

update nushell to the latest reedline

# 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.
-->
2024-10-06 20:49:56 -05:00
6dc71f5ad0 add unicode-width to str stats (#14014)
# Description

This PR adds another type of length to `str stats`, unicode-width.
```nushell
❯ "\u{ff03}" | str stats
╭───────────────┬───╮
│ lines         │ 1 │
│ words         │ 0 │
│ bytes         │ 3 │
│ chars         │ 1 │
│ graphemes     │ 1 │
│ unicode-width │ 2 │
╰───────────────┴───╯
❯ "Amélie Amelie" | str stats
╭───────────────┬────╮
│ lines         │ 1  │
│ words         │ 2  │
│ bytes         │ 15 │
│ chars         │ 14 │
│ graphemes     │ 13 │
│ unicode-width │ 13 │
╰───────────────┴────╯
❯ '今天天气真好' | str stats
╭───────────────┬────╮
│ lines         │ 1  │
│ words         │ 6  │
│ bytes         │ 18 │
│ chars         │ 6  │
│ graphemes     │ 6  │
│ unicode-width │ 12 │
╰───────────────┴────╯
❯ "Μπορῶ νὰ φάω σπασμένα γυαλιὰ χωρὶς νὰ πάθω τίποτα." | str stats
╭───────────────┬────╮
│ lines         │ 1  │
│ words         │ 9  │
│ bytes         │ 96 │
│ chars         │ 50 │
│ graphemes     │ 50 │
│ unicode-width │ 50 │
╰───────────────┴────╯
❯ "\n" | str stats
╭───────────────┬───╮
│ lines         │ 1 │
│ words         │ 0 │
│ bytes         │ 1 │
│ chars         │ 1 │
│ graphemes     │ 1 │
│ unicode-width │ 0 │
╰───────────────┴───╯
```
The idea of this PR came from me wondering if we could replace `#` with
`\u{ff03}` in tables.

# 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.
-->
2024-10-06 15:17:12 -05:00
d6f4e4c4fe Improve completer (#14004)
This pr does two optimization for the completer:
- Switch `sort_by` to `sort_unstable_by` on `sort_completions` function
since it reduces memory allocation and the orders of the identical
completions are not matter.
- Change `prefix` type from `Vec<u8>` to `&[u8]` to reduce cloning and
memory.
2024-10-06 20:31:37 +02:00
33ae71f300 Fix example for hide-env (#14013)
# Description
Fix example in documentation for hide-env

# 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.
-->
2024-10-06 08:50:11 -05:00
abcca0897e Fix operator completion typo and increase consistency (#14006)
# Description

* Fixes missing closing parenthesis on `not-in` completion

Also tweaks the others to give them consistent capitalization and
punctuation:

* First word initial-case, other words lower-case
* Exception - Initial-case for "also known as" after slash or inside
parens
* No closing period for any completion help
* Word-smithing on others.  E.g., "Mod" is technically "Remainder"

# User-Facing Changes

Operator completions

# Tests + Formatting

- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`
- 
# After Submitting

N/A
2024-10-05 18:11:17 -05:00
b1379b2b14 Fix namespace collision in std and nupm (#14009)
# Description

Fxes https://github.com/nushell/nupm/issues/102

Not loading `std` at startup has caused an issue with nupm and std where
the `dirs` module name clashes and nupm won't load. This was technically
a preexisting bug that was previously masked. This could have been fixed
(and also should be) by changing the import statement in nupm, but the
potential for collision would remain in other (user) modules.

This PR explicitly sets the relative path for the import statements in
`std/mod.nu` so that there are no collisions.

# User-Facing Changes

Bugfix

# Tests + Formatting

- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

# After Submitting

N/A
2024-10-05 14:55:47 -05:00
27ebccce80 Set proc/env cwd to engine_state value (#14005)
# Description

Fixes #14000 by once again calling `set_current_dir()`, but doing so
with the `cwd` from the current state, rather than the (previously
removed) argument to `merge_env()`.

# User-Facing Changes

Bug fix

# Tests + Formatting

If this looks good, I'll look at adding a test case for it.

- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

# After Submitting

N/A
2024-10-05 20:42:44 +03:00
6964968f14 update osc_633 string escaping (#14008)
# Description

VSCode OSC 633 needs particular string escaping to function properly. I
missed some escapes during my initial implementation. This PR should
cover the escapes I missed originally.
 
# 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.
-->
2024-10-05 10:03:01 -05:00
68377c176d Remove superfluous separator when there's no flag description/comment (#14007)
# Description

Fixes a small side-issue in #10977 - If a command flag didn't have a
comment/description, it would still show an unnecessary separator at the
end of the line.

This fixes that, plus uses the `: ` (colon) to separate the flag from
the description. This aligns with the way that named parameters are
handled.

# User-Facing Changes

Help/doc only

# Tests + Formatting

- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

# After Submitting

N/A
2024-10-05 15:19:26 +02:00
baadaee016 Add operator completions (#13818)
# Description

This PR addresses #13676 . It adds completions for the operators listed
on https://www.nushell.sh/lang-guide/chapters/operators.html#operators
based on the type of the value before the cursor. Currently, values
created as the output of other operations will not have completions. For
example `(1 + 3)` will not have completions. When operators are
added/removed/updated the completions will have to be adjusted manually.

# User-Facing Changes
- Tab completions for operators

# Tests
Added unit tests to the new completion struct OperationCompletion for
int completions, float completions, and str completions
2024-10-04 16:54:25 +02:00
199aa2ad3a escape dollarsign in tab completion (#13988)
<!--
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!
-->

# 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.
-->
fixes #13518 

This pr escapes file/directory names, which start with a dollar sign
since it's being interpreted as a variable.

# 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.
-->
2024-10-04 08:44:40 -05:00
29b176b719 Updated warning message for old dirs/shells (#13997)
# Description

@kubouch noticed that the warning message from #13842 when using a
"Shells" alias mentioned `config.nu`, but he's using it in the prompt
which means loading it in `env.nu`. Updated the warning message to:

> ... feature, and to remove this warning, please add the following
> to your startup configuration (typically env.nu or config.nu):

# User-Facing Changes

No change in functionality - More clear instructions, hopefully.

# Tests + Formatting

- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

# After Submitting

Doc and release notes still to be updated for #13842
2024-10-04 15:03:30 +03:00
6ce20675eb Consistent default key bindings for ide_completion_menu (#13955)
Updates Ctrl+p to open the ide_completion menu and otherwise advance to
the "previous" menu item.

Ctrl+n opens the ide_completion_menu and subsequently advances to the
"next" menu item. Ctrl+p should share this behavior for the "previous"
menu item. See nushell/nushell#13946 for detailed discussion.

Tested by building and running nushell without a custom config, falling
back to this default config.
2024-10-04 06:54:37 -05:00
1e9967c3bf nu-table/ Fix footer truncation in case of head_on_border (#13998)
Hi there;

I do think it must be fixed.

I also did improve performance for a fraction in case of header on
border.
I want to believe :) I didn't bench it.
But we didn't cached the width in this code branch before.
Which was causing all data reestimation.

close #13966
cc: @fdncred
2024-10-04 06:44:59 -05:00
e0bc85d0dd Update fill.rs to fix last example given with help (#13993)
Original stated it filled on the left to a width of 5 while showing the
command and output to fill on both sides to a width of 10. Changed
wording of description to match effect of example and displayed result.
2024-10-03 17:04:36 -05:00
e3fd4d3f81 since windows allows slash or backslash, allow both instead of MAIN_SEPARATOR (#13996)
# Description

I mean't to do this small change the other day but forgot. We probably
shouldn't be using MAIN_SEPARATOR because **\\*.rs is an illegal glob.
So, update this to just use slash.

# 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.
-->
2024-10-03 10:10:11 -05:00
00709fc5bd Improves startup time when using std-lib (#13842)
Updated summary for commit
[612e0e2](612e0e2160)
- While folks are welcome to read through the entire comments, the core
information is summarized here.

# Description

This PR drastically improves startup times of Nushell by only parsing a
single submodule of the Standard Library that provides the `banner` and
`pwd` commands. All other Standard Library commands and submodules are
parsed when imported by the user. This cuts startup times by more than
60%.

At the moment, we have stopped adding to `std-lib` because every
addition adds a small amount to the Nushell startup time.
With this change, we should once again be able to allow new
functionality to be added to the Standard Library without it impacting
`nu` startup times.

# User-Facing Changes

* Nushell now starts about 60% faster
* Breaking change: The `dirs` (Shells) aliases will return a warning
message that it will not be auto-loaded in the following release, along
with instructions on how to restore it (and disable the message)
* The `use std <submodule> *` syntax is available for convenience, but
should be avoided in scripts as it parses the entire `std` module and
all other submodules and places it in scope. The correct syntax to
*just* load a submodule is `use std/<submodule> *` (asterisk optional).
The slash is important. This will be documented.
* `use std *` can be used for convenience to load all of the library but
still incurs the full loading-time.
* `std/dirs`: Semi-breaking change. The `dirs` command replaces the
`show` command. This is more in line with the directory-stack
functionality found in other shells. Existing users will not be impacted
by this as the alias (`shells`) remains the same.

* Breaking-change: Technically a breaking change, but probably only
impacts maintainers of `std`. The virtual path for the standard library
has changed. It could previously be imported using its virtual path (and
technically, this would have been the correct way to do it):

  ```nu
  use NU_STDLIB_VIRTUAL_DIR/std
  ```

  The path is now simply `std/`:

  ```nu
  use std
  ```

  All submodules have moved accordingly.
  

# Timings

Comparisons below were made:

* In a temporary, clean config directory using `$env.XDG_CONFIG_HOME =
(mktemp -d)`.
* `nu` was run with a release build
* `nu` was run one time to generate the default `config.nu` (etc.) files
- Otherwise timings would include the user-prompt
* The shell was exited and then restarted several times to get timing
samples

(Note: Old timings based on 0.97 rather than 0.98, but in the range of
being accurate)

| Scenario | `$nu.startup-time` |
| --- | --- |
| 0.97.2
([aaaab8e](aaaab8e070))
Without this PR | 23ms - 24ms |
| This PR with deprecated commands | 9ms - <11ms |
| This PR after deprecated commands are removed in following release |
8ms - <10ms |
| Final PR (remove deprecated), using `--no-std-lib` | 6.1ms to 6.4ms |
| Final PR (remove deprecated), using `--no-config-file` | 3.1ms - 3.6ms
|
| Final PR (remove deprecated), using `--no-config-file --no-std-lib` |
1ms - 1.5ms |

*These last two timings point to the opportunity for further
optimization (see comment in thread below (will link once I write it).*

# Implementation details for future maintenance

* `use std banner` is a ridiculously deceptive call. That call parses
and imports *all* of `std` into scope. Simply replacing it with `use
std/core *` is essentially what saves ~14-15ms. This *only* imports the
submodule with the `banner` and `pwd` commands.

* From the code-comments, the reason that `NU_STDLIB_VIRTUAL_DIR` was
used as a prefix was so that there wouldn't be an issue if a user had a
`./std/mod.nu` in the current directory. This does **not** appear to be
an issue. After removing the prefix, I tested with both a relative
module as well as one in the `$env.NU_LIB_DIRS` path, and in all cases
the *internal* `std` still took precedence.

* By removing the prefix, users can now `use std` (and variants) without
requiring that it already be parsed and in scope.

* In the next release, we'll stop autoloading the `dirs` (shells)
functionality. While this only costs an additional 1-1.5ms, I think it's
better moved to the `config.nu` where the user can optionally remove it.
The main reason is its use of aliases (which have also caused issues) -
The `n`, `p`, and `g` short-commands are valuable real-estate, and users
may want to map these to something else.
  
For this release, there's an `deprecated_dirs` module that is still
autoloaded. As with the top-level commands, use of these will give a
deprecation warning with instructions on how to handle going forward.

To help with this, moved the aliases to their own submodule inside the
`dirs` module.

* Also sneaks in a small change where the top-level `dirs` command is
now the replacement for `dirs show`

* Fixed a double-import of `assert` in `dirs.nu`
* The `show_banner` step is replaced with simply `banner` rather than
re-importing it.

* A `virtual_path` may now be referenced with either a forward-slash or
a backward-slash on Windows. This allows `use std/<submodule>` to work
on all platforms.

# Performance side-notes:

* Future parsing and/or IR improvements should improve performance even
further.
* While the existing load time penalty of `std-lib` was not noticeable
on many systems, Nushell runs on a wide-variety of hardware and OS
platforms. Slower platforms will naturally see a bigger jump in
performance here. For users starting multiple Nushell sessions
frequently (e.g., `tmux`, Zellij, `screen`, et. al.) it is recommended
to keep total startup time (including user configuration) under ~250ms.

# Tests + Formatting

* All tests are green

* Updated tests:
- Removed the test that confirmed that `std` was loaded (since we
don't).
- Removed the `shells` test since it is not autoloaded. Main `dirs.nu`
functionality is tested through `stdlib-test`.
- Many tests assumed that the library was fully loaded, because it was
(even though we didn't intend for it to be). Fixed those tests.
- Tests now import only the necessary submodules (e.g., `use
std/assert`, rather than `use std assert`)
- Some tests *thought* they were loading `std/log`, but were doing so
improperly. This was masked by the now-fixed "load-everything-into-scope
bug". Local CI would pass due the `$env.NU_LOG_<...>` variables being
inherited from the calling process, but would fail in the "clean" GitHub
CI environment. These tests have also been fixed.

 * Added additional tests for the changes

# After Submitting

Will update the Standard Library doc page
2024-10-03 06:28:22 -05:00
157494e803 Make get_env_var return a reference to a Value (#13987)
# Description
Title says it all, changes `EngineState::get_env_var` to return a
`Option<&'a Value>` instead of an owned `Option<Value>`. This avoids
some unnecessary clones.

I also made a similar change to the `PluginExecutionContext` trait.
2024-10-02 13:05:48 +02:00
f03ba6793e Fix non-zero exit code errors in middle of pipeline (#13899)
# Description
Fixes #13868. Should come after #13885.

# User-Facing Changes
Bug fix.

# Tests + Formatting
Added a test.
2024-10-02 06:04:18 -05:00
475aa4f1dd Fix LAST_EXIT_CODE not being set for internal errors (#13954)
# Description
Fixes #13949 where `$env.LAST_EXIT_CODE` was not being set for internal
errors.

# Tests + Formatting
Cannot test due to limitations with the `nu_repl` test bin.
2024-10-02 06:00:50 -05:00
1d6ac16530 polars into-df struct fix (#13977)
# Description
This fixes an issue with converting to a dataframe when specifying a
struct in the schema. Things like the following now work correctly:
```nushell
 [[foo bar]; [{a: "a_0", b:"b_0"} 1] [{a: "a_1", b: "b_1" } 2]] | polars into-df -s {foo: {a: str, b: str}, bar: u8}
```
2024-10-02 05:59:14 -05:00
573a7e2c7b Bump tempfile from 3.12.0 to 3.13.0 (#13984)
Bumps [tempfile](https://github.com/Stebalien/tempfile) from 3.12.0 to
3.13.0.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/Stebalien/tempfile/blob/master/CHANGELOG.md">tempfile's
changelog</a>.</em></p>
<blockquote>
<h2>3.13.0</h2>
<ul>
<li>Add <code>with_suffix</code> constructors for easily creating new
temporary files with a specific suffix (e.g., a specific file
extension). Thanks to <a
href="https://github.com/Borgerr"><code>@​Borgerr</code></a>.</li>
<li>Update dependencies (fastrand &amp; rustix).</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="a354f8cb11"><code>a354f8c</code></a>
chore: release 3.13.0</li>
<li><a
href="d21b602fa2"><code>d21b602</code></a>
chore: update deps</li>
<li><a
href="d6600da8fc"><code>d6600da</code></a>
Add for <code>with_suffix</code> (<a
href="https://redirect.github.com/Stebalien/tempfile/issues/299">#299</a>)</li>
<li><a
href="19280c5889"><code>19280c5</code></a>
Document current default permissions for tempdirs (<a
href="https://redirect.github.com/Stebalien/tempfile/issues/296">#296</a>)</li>
<li><a
href="c5eac9f690"><code>c5eac9f</code></a>
fix: address clippy unnecessary deref lint in test (<a
href="https://redirect.github.com/Stebalien/tempfile/issues/294">#294</a>)</li>
<li>See full diff in <a
href="https://github.com/Stebalien/tempfile/compare/v3.12.0...v3.13.0">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=tempfile&package-manager=cargo&previous-version=3.12.0&new-version=3.13.0)](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>
2024-10-02 06:17:03 +00:00
cebbc82322 Bump once_cell from 1.19.0 to 1.20.1 (#13982)
Bumps [once_cell](https://github.com/matklad/once_cell) from 1.19.0 to
1.20.1.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/matklad/once_cell/blob/master/CHANGELOG.md">once_cell's
changelog</a>.</em></p>
<blockquote>
<h2>1.20.1</h2>
<ul>
<li>Allow using <code>race</code> module using just
<code>portable_atomic</code>, without <code>critical_section</code> and
provide
better error messages on targets without atomic CAS instruction,
<a
href="https://redirect.github.com/matklad/once_cell/pull/265">#265</a>.</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="3b9bd9b872"><code>3b9bd9b</code></a>
release 1.20.1</li>
<li><a
href="f61508a632"><code>f61508a</code></a>
Merge pull request <a
href="https://redirect.github.com/matklad/once_cell/issues/265">#265</a>
from taiki-e/portable-atomic</li>
<li><a
href="449e5d7b2d"><code>449e5d7</code></a>
Add portable-atomic feature and disable portable-atomic/critical-section
by d...</li>
<li><a
href="72f7c2e5fa"><code>72f7c2e</code></a>
Merge pull request <a
href="https://redirect.github.com/matklad/once_cell/issues/260">#260</a>
from brodycj/propagate-critical-section-to-portable-a...</li>
<li><a
href="be6b6238fb"><code>be6b623</code></a>
v1.20.0</li>
<li><a
href="f2d95bfe79"><code>f2d95bf</code></a>
update Cargo (dev-)dependencies; update Cargo.lock.msrv</li>
<li><a
href="dd6b5c2909"><code>dd6b5c2</code></a>
ci: fix TEST_BETA with TEMPORARY WORKAROUND in RUSTFLAGS</li>
<li><a
href="7317eae758"><code>7317eae</code></a>
add <code>cargo test --workspace</code> to beginning of TEST task</li>
<li><a
href="bd54bf7aff"><code>bd54bf7</code></a>
fix default-features flag for parking_lot_core in dependencies</li>
<li><a
href="bb70b9e7e6"><code>bb70b9e</code></a>
cargo fmt updates</li>
<li>Additional commits viewable in <a
href="https://github.com/matklad/once_cell/compare/v1.19.0...v1.20.1">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=once_cell&package-manager=cargo&previous-version=1.19.0&new-version=1.20.1)](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>
2024-10-02 06:15:10 +00:00
cf5b2aeb88 Update wrap example (#13986)
# Description

As with #13985, credit to @AlifianK for suggesting this in
https://github.com/nushell/nushell.github.io/pull/1572

Updates the example in `wrap` to not use 1-based, sequential numbers.

# User-Facing Changes

Help/doc only

# Tests + Formatting

- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

# After Submitting

N/A
2024-10-02 06:11:07 +00:00
52eb9c2ef3 Update merge example (#13985)
# Description

All credit to @AlifianK for suggesting this in the doc repo
(https://github.com/nushell/nushell.github.io/pull/1571).

This updates the merge example to make it more clear by using a
different set of numbers that can't easily be confused with an `index`.
Also changes the `index` to `id` to remove the "magic column name
conversion". (#13780).

# User-Facing Changes

Help/Doc change only

# Tests + Formatting

- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

# After Submitting

N/A
2024-10-02 06:09:57 +00:00
702dcd8581 Bump crate-ci/typos from 1.24.6 to 1.25.0 (#13978) 2024-10-02 01:08:43 +00:00
9e6ada6411 Fix typos (#13980)
Fix typos of
https://github.com/nushell/nushell/actions/runs/11135506119/job/30945650562?pr=13978
2024-10-02 08:49:59 +08:00
a38663ec90 Bump actions-rust-lang/setup-rust-toolchain from 1.10.0 to 1.10.1 (#13979)
Bumps
[actions-rust-lang/setup-rust-toolchain](https://github.com/actions-rust-lang/setup-rust-toolchain)
from 1.10.0 to 1.10.1.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/actions-rust-lang/setup-rust-toolchain/releases">actions-rust-lang/setup-rust-toolchain's
releases</a>.</em></p>
<blockquote>
<h2>v1.10.1</h2>
<ul>
<li>Fix problem matcher for rustfmt output.
The format has changed since <a
href="https://redirect.github.com/rust-lang/rustfmt/pull/5971">rust-lang/rustfmt#5971</a>
and now follows the form &quot;filename:line&quot;.
Thanks to <a
href="https://github.com/0xcypher02"><code>@​0xcypher02</code></a> for
pointing out the problem.</li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/actions-rust-lang/setup-rust-toolchain/compare/v1...v1.10.1">https://github.com/actions-rust-lang/setup-rust-toolchain/compare/v1...v1.10.1</a></p>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/actions-rust-lang/setup-rust-toolchain/blob/main/CHANGELOG.md">actions-rust-lang/setup-rust-toolchain's
changelog</a>.</em></p>
<blockquote>
<h2>[1.10.1] - 2024-10-01</h2>
<ul>
<li>Fix problem matcher for rustfmt output.
The format has changed since <a
href="https://redirect.github.com/rust-lang/rustfmt/pull/5971">rust-lang/rustfmt#5971</a>
and now follows the form &quot;filename:line&quot;.
Thanks to <a
href="https://github.com/0xcypher02"><code>@​0xcypher02</code></a> for
pointing out the problem.</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="11df97af8e"><code>11df97a</code></a>
Update the rustfmt problem matcher</li>
<li>See full diff in <a
href="https://github.com/actions-rust-lang/setup-rust-toolchain/compare/v1.10.0...v1.10.1">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=actions-rust-lang/setup-rust-toolchain&package-manager=github_actions&previous-version=1.10.0&new-version=1.10.1)](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>
2024-10-02 08:32:07 +08:00
02804ab537 Simplify the Dockerfile (#13974)
<!--
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!
-->

# Description

Works for `docker build` and `docker buildx build`
For more detail about the new Dockerfile syntax:
https://www.docker.com/blog/new-dockerfile-capabilities-v1-7-0/
2024-10-01 06:28:14 -05:00
b2d0d9cf13 Make SpanId and RegId also use new ID struct (#13963)
# Description
In the PR #13832 I used some newtypes for the old IDs. `SpanId` and
`RegId` already used newtypes, to streamline the code, I made them into
the same style as the other marker-based IDs.

Since `RegId` should be a bit smaller (it uses a `u32` instead of
`usize`) according to @devyn, I made the `Id` type generic with `usize`
as the default inner value.

The question still stands how `Display` should be implemented if even.

# User-Facing Changes
Users of the internal values of `RegId` or `SpanId` have breaking
changes but who outside nushell itself even uses these?

# After Submitting
The IDs will be streamlined and all type-safe.
2024-10-01 13:23:27 +02:00
46589faaca allow bools to be type checked with each other (#13968)
# Description

This PR allows bools to be type checked against each other.


![image](https://github.com/user-attachments/assets/64dc36f8-59bc-4e66-8380-6b693c77a2d3)

I looked for test and maybe we don't have any for type checked math
stuff. I didn't see any.

# 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.
-->
2024-09-30 19:18:07 -05:00
166d5fa4ff nu-exlore/ Fix :try table view (#13964)
Must be addressed @fdncred 
But I would recheck.


![image](https://github.com/user-attachments/assets/657c4f63-62ae-413d-b6cc-90e918864e69)

close #13957
2024-09-30 14:45:13 -05:00
4bd38847c2 update human-date-parser crate (#13962)
# Description

closes https://github.com/nushell/nushell/issues/13759 and fixes some
odd behavior from the human-date-parser crate.

# 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.
-->
2024-09-30 11:47:50 -05:00
30a4187be4 a potential solution that may fix vt processing (#13961)
# Description

This PR is related #11950 and serves as another potential fix alongside
rolling it back with https://github.com/nushell/nushell/pull/13959. The
idea here is to try and properly setup the input and output console
modes. I searched through a log of GitHub code to come up with this,
including deno, wezterm, conpty, among others. It seems to work but it
would be great if someone else would be able to test. I added comments
from the consoleapi.h from windows to know what the other flags are in
case we need to make other changes.

# 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.
-->
2024-09-30 11:34:29 -05:00
f0c83a4459 Replace raw usize IDs with new types (#13832)
# Description

In this PR I replaced most of the raw usize IDs with
[newtypes](https://doc.rust-lang.org/rust-by-example/generics/new_types.html).
Some other IDs already started using new types and in this PR I did not
want to touch them. To make the implementation less repetitive, I made
use of a generic `Id<T>` with marker structs. If this lands I would try
to move make other IDs also in this pattern.

Also at some places I needed to use `cast`, I'm not sure if the type was
incorrect and therefore casting not needed or if actually different ID
types intermingle sometimes.

# User-Facing Changes

Probably few, if you got a `DeclId` via a function and placed it later
again it will still work.
2024-09-30 13:20:15 +02:00
fc61416c79 Fix issue with ls | explore coloring of file names (#13952)
close #13936

The fix seem to be exactly what you've @fdncred  described.
But I'd recheck that everything is good.


![image](https://github.com/user-attachments/assets/5d9ce02b-9545-4a96-9718-b19d2e5810b8)

Take care.
Have a great week.
2024-09-29 14:03:56 -05:00
8200831b07 Fix panic on too few arguments for custom function (#10395)
# Description
Old code was comparing remaining positional arguments with total number
of arguments, where it should've compared remaining positional with
with remaining arguments of any kind. This means that if a function was
given too few arguments, `calculate_end_span` would believe that it
actually had too many arguments, since after parsing the first few
arguments, the number of remaining arguments needed were fewer than the
*total* number of arguments, of which we had used several.

Fixes #9072
Fixes: https://github.com/nushell/nushell/issues/13930
Fixes: https://github.com/nushell/nushell/issues/12069
Fixes: https://github.com/nushell/nushell/issues/8385

Extracted from #10381

## Bonus

It also improves the error handling on missing positional arguments
before keywords (no longer crashing since #9851). Instead of just giving
the keyword to the parser for the missing positional, we give an
explicit error about a missing positional argument. I would like better
descriptions than "missing var_name" though, but I'm not sure if that's
available without

Old error
```
Error: nu::parser::parse_mismatch

  × Parse mismatch during operation.
   ╭─[entry #1:1:1]
 1 │ let = if foo
   ·     ┬
   ·     ╰── expected valid variable name
   ╰────
```

New error
```
Error: nu::parser::missing_positional

  × Missing required positional argument.
   ╭─[entry #18:1:1]
 1 │ let = foo
   ·    ┬
   ·    ╰── missing var_name
   ╰────
  help: Usage: let <var_name> = <initial_value>
```

# User-Facing Changes
The program `alias = = =` is no longer accepted by the parser
2024-09-27 23:39:45 +08:00
497954d84c ensure toolkit is using external cargo command (#13943)
# Description

@cptpiepmatz and I ran into a problem where `toolkit check pr` and
`toolkit clippy --verbose` wouldn't work. I tracked it down to me using
`cargo-completions.nu` out of the nu_scripts repo. It was redefining
`cargo clippy`. The fix was to ensure that all `cargo` commands in
`toolkit.nu` use the external `^cargo`.

Specifically, the problem with `cargo clippy` in `cargo-completions.nu`
is it didn't seem to allow `-- -D blah` type parameters.

# 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.
-->
2024-09-27 08:52:48 -05:00
bcaef8959c Expose flag truncate-ragged-lines in polars open (#13939)
# Description
Introduces a new flag `--truncate-ragged-lines` for `polars open` that
will truncate lines that are longer than the schema.

# User-Facing Changes
- Introduction of the flag `--truncate-ragged-lines` for `polars open`
2024-09-27 06:54:46 -05:00
5bef81a059 Added command polars len for performing count(*) like operations. (#13941)
# Description
This request exposes the prelude::polars::len expression. It is ended
for doing fast select count(*) like operations:

<img width="626" alt="Screenshot 2024-09-26 at 18 14 45"
src="https://github.com/user-attachments/assets/74285fc6-f99c-46e0-9226-9a7d41738d78">

# User-Facing Changes
- Introduction of the `polars len` command
2024-09-27 06:54:28 -05:00
d68c3ec89a Only ask to create config files the first time nu is started (#13857)
# Description

Implements #13669

When nu is started for the first time, the directory represented by
`$nu.default-config-dir` typically will not exist. In this case, Nushell
will create the directory. It will then detect that either or both
`config.nu`/`env.nu` don't exist and offer to create them.

(Existing behavior) If the user declines, the directory will still be
created (since the history file lives there as well). The
`default_config.nu` and `default_env.nu` will be loaded.

On subsequent launches, as long as the config directory continues to
exist, the user will not be prompted to recreate the config files.
Nushell will behave as if the user answered "N" to the prompt in that
`default_config.nu` and `default_env.nu` will be used.

The user can still create a `config.nu` or `env.nu` at any point, and
that will be used. In that case, `default_config.nu` and/or
`default_env.nu` will no longer be loaded (unless and until #13671 is
implemented).

# User-Facing Changes

User will no longer be prompted to create config files if they are
missing so long as the config directory exists.

## Before this change:

1. Nushell starts for the first time
2. The directory where config files are stored does not exist
3. The config files do not exist
   * User is asked whether they want to create `env.nu`
- User says, "Y", `default_env.nu` is copied to the directory as
`env.nu` (and directory is created if needed)
- User says, "n", `default_env.nu` is loaded, but no file on the
filesystem is created.
 
   * User is asked whether they want to create `config.nu`
- User says, "Y", `default_config.nu` is copied to the directory as
`config.nu` (and directory is created if needed)
- User says, "n", `default_config.nu` is loaded, but no file on the
filesystem is created.

4. The next time `nu` is run, if either file is missing, the user will
be prompted again for that file.

## After this change:

Steps 1 - 3 remains the same.

4. The next time `nu` is run, we check if the directory exists.  If so:
5. Do not prompt user to create any missing files **(New Behavior)**
6. `$nu.default-config-dir/env.nu` exists?
   * Yes? Use it. (Normal behavior)
   * No?  Evaluate `default_env.nu`.  (Normal behavior)
   * No file is created on the filesystem

7. `$nu.default-config-dir/config.nu` exists?
   * Yes? Use it. (Normal behavior)
   * No?  Evaluate `default_config.nu` (Normal behavior)
   * No file is created on the filesystem

# Tests + Formatting

- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

# After Submitting

This behavior isn't currently mentioned in the configuration doc. I'll
probably hold off on changing anything in the doc until #13671 is
implemented. Regardless, given the timing, this won't make it into a
release for at least 4 weeks.
2024-09-26 13:54:42 -05:00
0c72f881a6 Fix Docker image build failure (#13938)
## Description
While building the docker image under `nushell/docker` directory,
following build failure observed.


![nushell-docker-error](https://github.com/user-attachments/assets/972048d7-b001-4325-b947-93e95b98f4d1)

The problem here is the following lines of code that decide which
`nushell` binary to download, extract, and install
https://github.com/nushell/nushell/blob/main/docker/Dockerfile#L16-L19

The issue is especially with wildcard asterisk (*) which downloads both
`amd64` and `arm64` binary while building.

## Fix
Introduced build arg `TARGETARCH` which will be populated implicitly by
docker `build/buildx` which will help us to decide which binary to
download.

## User-Facing Changes
None. 

## Testing Details
Tested building docker image on both `amd64` and `arm64` systems.
**amd64/x86_64**

![nushell-docker-amd64](https://github.com/user-attachments/assets/ea30b7e3-0664-4a5b-bb13-4c18cdae2a31)

**arm64**

![nushell-docker-arm64](https://github.com/user-attachments/assets/54e47051-1ee7-4695-bc6c-1e211532a545)
2024-09-26 09:57:37 -05:00
8195e2d638 Bump rustix from 0.38.34 to 0.38.37 (#13878)
Notable this gets https://github.com/bytecodealliance/rustix/pull/1147
which makes things work on Android again.

Without this update latest `0.98.0` release gets stuck in a loop
outputting the below error due to the `TCGETS2` usage:

> Error: Os { code: 13, kind: PermissionDenied, message: "Permission
denied" }
2024-09-26 14:20:59 +02:00
e8c20390e0 fix ls_colors coloring in grid and ls (#13935)
# Description

After PR https://github.com/nushell/nushell/pull/12953, LS_COLORS
coloring broke in the `grid` and `ls` commands because the full path to
the files were not available. This PR restores the coloring.


# 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.
-->
2024-09-25 18:16:54 -05:00
13df0af514 Set current working directory at startup (#12953)
This PR sets the current working directory to the location of the
Nushell executable at startup, using `std::env::set_current_dir()`. This
is desirable because after PR
https://github.com/nushell/nushell/pull/12922, we no longer change our
current working directory even after `cd` is executed, and some OS might
lock the directory where Nushell started.

The location of the Nushell executable is chosen because it cannot be
removed while Nushell is running anyways, so we don't have to worry
about OS locking it.

This PR has the side effect that it breaks buggy command even harder.
I'll keep this PR as a draft until these commands are fixed, but it
might be helpful to pull this PR if you're working on fixing one of
those bugs.

---------

Co-authored-by: Devyn Cairns <devyn.cairns@gmail.com>
Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
2024-09-25 13:04:26 -05:00
54e9aa92bc Respect $env.config.use_kitty_protocol in input listen (#13892)
Fixes nushell/nushell#13891

# Description

`input listen` now respects `$env.config.use_kitty_protocol`
This is essentially a copy-paste from `keybindings listen` where it was
already implemented.

# User-Facing Changes

`input listen` now respects `$env.config.use_kitty_protocol`

# Tests + Formatting

# After Submitting

---------

Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
2024-09-25 08:57:00 -05:00
1afff777a6 update folder_depth algorithm for glob command (#13915)
# Description

This PR updates the `folder_depth` algorithm in order to make `glob` a
bit faster. The algorithm works like this. Since `folder_depth` is
always used we need to set it to a value. If the glob pattern contains
`**` then make `folder_depth` `usize::MAX`. If `--depth` is not
provided, make it 1, otherwise use the provided value.

closes #13914

# 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.
-->
2024-09-25 08:15:18 -05:00
071faae772 fix inspect and explore panics on empty records (#13893)
# Description

Fixes a couple panics:

```
> {} | inspect
Error:   x Main thread panicked.
  |-> at crates/nu-command/src/debug/inspect_table.rs:87:15
  `-> attempt to divide by zero
```

```
> {} | explore
# see an empty column, press Down
Error:   x Main thread panicked.
  |-> at crates/nu-explore/src/views/cursor/mod.rs:39:9
  `-> attempt to subtract with overflow
```

# User-Facing Changes

`{} | inspect` now outputs an empty table:

```
╭─────────────┬────────╮
│ description │ record │
├─────────────┴────────┤
│                      │
├──────────────────────┤
```

`{} | explore` opens the help menu.

Both match the empty list behavior.

# Tests

I'm not sure how to test `explore`, as it waits for interaction.
2024-09-25 07:48:16 -05:00
08a241f763 update the defaults for shell_integration (#13929)
# Description

This PR updates the shell_integration defaults so that they work as
described in default_config.nu even when there is no config.nu file.

closes #13924

# 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.
-->
2024-09-25 07:43:05 -05:00
63f9e273b3 add binary as input to hash commands (#13923)
# Description

This allows `hash sha256` to support binary input. The code was there
but the signature wasn't.

closes #13916
2024-09-25 16:47:52 +08:00
71d604067a Bump actions-rust-lang/setup-rust-toolchain from 1.9.0 to 1.10.0 (#13922)
Bumps
[actions-rust-lang/setup-rust-toolchain](https://github.com/actions-rust-lang/setup-rust-toolchain)
from 1.9.0 to 1.10.0.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/actions-rust-lang/setup-rust-toolchain/releases">actions-rust-lang/setup-rust-toolchain's
releases</a>.</em></p>
<blockquote>
<h2>v1.10.0</h2>
<h2>What's Changed</h2>
<ul>
<li>Add new parameter cache-directories that is propagated to
Swatinem/rust-cache (<a
href="https://redirect.github.com/actions-rust-lang/setup-rust-toolchain/issues/44">#44</a>
by <a
href="https://github.com/pranc1ngpegasus"><code>@​pranc1ngpegasus</code></a>)</li>
<li>Add new parameter cache-key that is propagated to
Swatinem/rust-cache as key (<a
href="https://redirect.github.com/actions-rust-lang/setup-rust-toolchain/issues/41">#41</a>
by <a
href="https://github.com/iainlane"><code>@​iainlane</code></a>)</li>
<li>Make rustup toolchain installation more robust in light of planned
changes <a
href="https://redirect.github.com/rust-lang/rustup/issues/3635">rust-lang/rustup#3635</a>
and <a
href="https://redirect.github.com/rust-lang/rustup/pull/3985">rust-lang/rustup#3985</a></li>
<li>Allow installing multiple Rust toolchains by specifying multiple
versions in the toolchain input parameter.</li>
<li>Configure the rustup override behavior via the new override input.
(<a
href="https://redirect.github.com/actions-rust-lang/setup-rust-toolchain/issues/38">#38</a>)</li>
</ul>
<h2>New Contributors</h2>
<ul>
<li><a
href="https://github.com/pranc1ngpegasus"><code>@​pranc1ngpegasus</code></a>
made their first contribution in <a
href="https://redirect.github.com/actions-rust-lang/setup-rust-toolchain/pull/44">actions-rust-lang/setup-rust-toolchain#44</a></li>
<li><a href="https://github.com/iainlane"><code>@​iainlane</code></a>
made their first contribution in <a
href="https://redirect.github.com/actions-rust-lang/setup-rust-toolchain/pull/41">actions-rust-lang/setup-rust-toolchain#41</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/actions-rust-lang/setup-rust-toolchain/compare/v1...v1.10.0">https://github.com/actions-rust-lang/setup-rust-toolchain/compare/v1...v1.10.0</a></p>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/actions-rust-lang/setup-rust-toolchain/blob/main/CHANGELOG.md">actions-rust-lang/setup-rust-toolchain's
changelog</a>.</em></p>
<blockquote>
<h1>Changelog</h1>
<p>All notable changes to this project will be documented in this
file.</p>
<p>The format is based on <a
href="https://keepachangelog.com/en/1.0.0/">Keep a Changelog</a>,
and this project adheres to <a
href="https://semver.org/spec/v2.0.0.html">Semantic Versioning</a>.</p>
<h2>[Unreleased]</h2>
<ul>
<li>Add new parameter <code>cache-directories</code> that is propagated
to <code>Swatinem/rust-cache</code> (<a
href="https://redirect.github.com/actions-rust-lang/setup-rust-toolchain/issues/44">#44</a>
by <a
href="https://github.com/pranc1ngpegasus"><code>@​pranc1ngpegasus</code></a>)</li>
<li>Add new parameter <code>cache-key</code> that is propagated to
<code>Swatinem/rust-cache</code> as <code>key</code> (<a
href="https://redirect.github.com/actions-rust-lang/setup-rust-toolchain/issues/41">#41</a>
by <a
href="https://github.com/iainlane"><code>@​iainlane</code></a>)</li>
<li>Make rustup toolchain installation more robust in light of planned
changes <a
href="https://redirect.github.com/rust-lang/rustup/issues/3635">rust-lang/rustup#3635</a>
and <a
href="https://redirect.github.com/rust-lang/rustup/pull/3985">rust-lang/rustup#3985</a></li>
<li>Allow installing multiple Rust toolchains by specifying multiple
versions in the <code>toolchain</code> input parameter.</li>
<li>Configure the <code>rustup override</code> behavior via the new
<code>override</code> input. (<a
href="https://redirect.github.com/actions-rust-lang/setup-rust-toolchain/issues/38">#38</a>)</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="4d1965c914"><code>4d1965c</code></a>
Add override input parameter that controls the <code>rustup
override</code> behavior</li>
<li><a
href="b31b1317f2"><code>b31b131</code></a>
Allow installing multiple Rust toolchains at once.</li>
<li><a
href="9f99923fad"><code>9f99923</code></a>
Add pre-commit for basic checks</li>
<li><a
href="86a2ce6673"><code>86a2ce6</code></a>
Make toolchain install more robust</li>
<li><a
href="eb4a655afd"><code>eb4a655</code></a>
Document new keys and add changelog</li>
<li><a
href="a90048dfdd"><code>a90048d</code></a>
Merge pull request <a
href="https://redirect.github.com/actions-rust-lang/setup-rust-toolchain/issues/41">#41</a>
from iainlane/iainlane/propagate-cache-key</li>
<li><a
href="597574aacb"><code>597574a</code></a>
Update key name in README</li>
<li><a
href="634cedf365"><code>634cedf</code></a>
Merge pull request <a
href="https://redirect.github.com/actions-rust-lang/setup-rust-toolchain/issues/44">#44</a>
from pranc1ngpegasus/feat/able-to-cache-additional-dir...</li>
<li><a
href="5d6934e965"><code>5d6934e</code></a>
Able to cache additional directories</li>
<li><a
href="b01657d9bb"><code>b01657d</code></a>
Add support for adding to cache key</li>
<li>See full diff in <a
href="https://github.com/actions-rust-lang/setup-rust-toolchain/compare/v1.9.0...v1.10.0">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=actions-rust-lang/setup-rust-toolchain&package-manager=github_actions&previous-version=1.9.0&new-version=1.10.0)](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>
2024-09-25 09:55:58 +08:00
66d0e18674 Bump rustsec/audit-check from 1.4.1 to 2.0.0 (#13921)
Bumps [rustsec/audit-check](https://github.com/rustsec/audit-check) from
1.4.1 to 2.0.0.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/rustsec/audit-check/releases">rustsec/audit-check's
releases</a>.</em></p>
<blockquote>
<h2>v2.0.0</h2>
<h2>What's Changed</h2>
<ul>
<li>Run on Node 20.x by <a
href="https://github.com/clechasseur"><code>@​clechasseur</code></a> in
<a
href="https://redirect.github.com/rustsec/audit-check/pull/16">rustsec/audit-check#16</a></li>
<li>Remove <code>generate-lockfile</code> To Prevent Overwriting
Checked-In Lock Files by <a
href="https://github.com/tillmann-crabnebula"><code>@​tillmann-crabnebula</code></a>
in <a
href="https://redirect.github.com/rustsec/audit-check/pull/20">rustsec/audit-check#20</a></li>
<li>Added support for <code>working-directory</code> by <a
href="https://github.com/ranger-ross"><code>@​ranger-ross</code></a> in
<a
href="https://redirect.github.com/rustsec/audit-check/pull/21">rustsec/audit-check#21</a></li>
<li>fix: security fix for vulnerability in <code>braces</code> library
by <a
href="https://github.com/clechasseur"><code>@​clechasseur</code></a> in
<a
href="https://redirect.github.com/rustsec/audit-check/pull/23">rustsec/audit-check#23</a></li>
<li>npm audit fix by <a
href="https://github.com/tarcieri"><code>@​tarcieri</code></a> in <a
href="https://redirect.github.com/rustsec/audit-check/pull/24">rustsec/audit-check#24</a></li>
<li>v2.0.0 release prep by <a
href="https://github.com/tarcieri"><code>@​tarcieri</code></a> in <a
href="https://redirect.github.com/rustsec/audit-check/pull/25">rustsec/audit-check#25</a></li>
</ul>
<h2>New Contributors</h2>
<ul>
<li><a
href="https://github.com/clechasseur"><code>@​clechasseur</code></a>
made their first contribution in <a
href="https://redirect.github.com/rustsec/audit-check/pull/16">rustsec/audit-check#16</a></li>
<li><a
href="https://github.com/tillmann-crabnebula"><code>@​tillmann-crabnebula</code></a>
made their first contribution in <a
href="https://redirect.github.com/rustsec/audit-check/pull/20">rustsec/audit-check#20</a></li>
<li><a
href="https://github.com/ranger-ross"><code>@​ranger-ross</code></a>
made their first contribution in <a
href="https://redirect.github.com/rustsec/audit-check/pull/21">rustsec/audit-check#21</a></li>
<li><a href="https://github.com/tarcieri"><code>@​tarcieri</code></a>
made their first contribution in <a
href="https://redirect.github.com/rustsec/audit-check/pull/24">rustsec/audit-check#24</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/rustsec/audit-check/compare/v1.4.1...v2.0.0">https://github.com/rustsec/audit-check/compare/v1.4.1...v2.0.0</a></p>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/rustsec/audit-check/blob/main/CHANGELOG.md">rustsec/audit-check's
changelog</a>.</em></p>
<blockquote>
<h1>Changelog</h1>
<p>All notable changes to this project will be documented in this
file.</p>
<p>The format is based on <a
href="https://keepachangelog.com/en/1.0.0/">Keep a Changelog</a>,
and this project adheres to <a
href="https://semver.org/spec/v2.0.0.html">Semantic Versioning</a>.</p>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="69366f33c9"><code>69366f3</code></a>
Prep for v2.0.0 release (<a
href="https://redirect.github.com/rustsec/audit-check/issues/25">#25</a>)</li>
<li><a
href="7b350a127d"><code>7b350a1</code></a>
npm audit fix (<a
href="https://redirect.github.com/rustsec/audit-check/issues/24">#24</a>)</li>
<li><a
href="286a088f1c"><code>286a088</code></a>
fix: update <code>@clechasseur/rs-actions-core</code> and other
dependencies (<a
href="https://redirect.github.com/rustsec/audit-check/issues/23">#23</a>)</li>
<li><a
href="b7dc4ebf0c"><code>b7dc4eb</code></a>
Added support for <code>working-directory</code> (<a
href="https://redirect.github.com/rustsec/audit-check/issues/21">#21</a>)</li>
<li><a
href="6dc762e804"><code>6dc762e</code></a>
update to latest upstream and rebuild (<a
href="https://redirect.github.com/rustsec/audit-check/issues/20">#20</a>)</li>
<li><a
href="fe0359b3e1"><code>fe0359b</code></a>
Run on Node 20.x (<a
href="https://redirect.github.com/rustsec/audit-check/issues/16">#16</a>)</li>
<li><a
href="4da312dd0f"><code>4da312d</code></a>
docs: Update repo link</li>
<li><a
href="d6805b6463"><code>d6805b6</code></a>
docs: Bump version in README</li>
<li>See full diff in <a
href="https://github.com/rustsec/audit-check/compare/v1.4.1...v2.0.0">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=rustsec/audit-check&package-manager=github_actions&previous-version=1.4.1&new-version=2.0.0)](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>
2024-09-25 09:55:47 +08:00
a940a8aa80 Some small tweaks to release and nightly workflow (#13912)
<!--
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!
-->

# 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.
-->

# 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.
-->
2024-09-24 23:13:05 +08:00
0d30550950 update reedline to the latest 660a5074 (#13909)
# Description

This PR updates nushell to the latest reedline commit 660a5074

# 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.
-->
2024-09-24 08:46:47 -05:00
65bb0ff167 Add threads to the ls command in order to increase performance in some circumstances (#13836)
# Description

This PR tries to allow the `ls` command to use multiple threads if so
specified. The reason why you'd want to use threads is if you notice
`ls` taking a long time. The one place I see that happening is from WSL.

I'm not sure how real-world this test is but you can see that this
simple `ls` of a folder with length takes a while 9366 ms. I've run this
test many times and it ranges from about 15 seconds to about 10 seconds.
But with the `--threads` parameter, it takes less time, 2744ms in this
screenshot.

![image](https://github.com/user-attachments/assets/e5c4afa2-7837-4437-8e6e-5d4bc3894ae1)

The only way forward I could find was to _always_ use threading and
adjust the number of threads based on if the user provides a flag. That
seemed the easiest way to do it after applying @devyn's interleave
advice.

No feelings hurt if this doesn't land. It's more of an experiment but I
think it has potential.

# 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.
-->
2024-09-24 08:40:48 -05:00
151767a5e3 Support kitty key modifiers in keybindings (#13906)
# Description
hi hi, this makes the parsing of modifier key combos in config more
general, and adds support for additional kitty keyboard protocol
modifiers. It seems that support for [kitty
keys](https://sw.kovidgoyal.net/kitty/keyboard-protocol) had already
been added to nushell in https://github.com/nushell/nushell/pull/10540,
and this was the only missing piece to making them available in
keybindings.

# User-Facing Changes
- keybindings in config can include the super, hyper and meta modifiers
(e.g. `modifier: super`, `modifier: shift_super`, etc.), and these
modifiers will work in supporting terminals (kitty, foot, wezterm,
alacritty...)
- all permutations of snake_cased modifier combinations now behave
equivalently for the purpose of describing keybindings in config (e.g.
`control_alt_shift` was previously supported where `shift_control_alt`
was a config error — now they're the same)

# Tests
None of this looks to be tested at the moment. I only found a smoke test
under the nu-cli crate, and I couldn't break tests elsewhere by stuffing
around with modifier handling. Works on my machine, though! 🌈
2024-09-24 15:37:04 +02:00
a948ec6c2c Fix handling of stopped TUI applications on unix (#13741)
# Description

Instead of handling a foreground process being stopped in any way, we
were simply ignoring SIGTSTP (which the terminal usually sends to the
foreground process group when Ctrl-Z is pressed), and propagating this
to our foreground children. This works for most processes, but it
generally fails for applications which put the terminal in raw mode[1]
and implement their own suspension mechanism (typically TUI apps like
helix[2], neovim[3], top[4] or amp[5]). In these cases, triggering
suspension within the app results in the terminal getting blocked, since
the application is waiting for a SIGCONT, while nushell is waiting for
it to exit.

Fix this by unblocking SIGTSTP for our foreground children (neovim,
helix and probably others send this to themselves while trying to
suspend), and displaying the following message whenever one of them gets
stopped:

    nushell currently does not support background jobs
    press any key to continue

Pressing any key will then send SIGCONT to the child's process group and
resume waiting.

This fix is probably going to be superseded by a proper background job
implementation (#247) at some point, but for now it's better than
completely blocking the terminal.

[1]
https://docs.rs/crossterm/latest/crossterm/terminal/index.html#raw-mode
[2] https://helix-editor.com/
[3] https://neovim.io/
[4] https://man7.org/linux/man-pages/man1/top.1.html
[5] https://amp.rs/

- fixes #1038
- fixes #7335
- fixes #10335

# User-Facing Changes

While any foreground process is running, Ctrl-Z is no longer ignored.
Instead, the message described above is displayed, and nushell waits for
a key to be pressed.

# 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.
-->
2024-09-24 06:44:58 -05:00
28a7461057 Added command polars profile for profiling lazy dataframes (#13904)
# Description
Introduce a new command `polars profile` for profiling lazy dataframes:

<img width="965" alt="Screenshot 2024-09-22 at 23 46 18"
src="https://github.com/user-attachments/assets/11402dd3-8256-43df-a986-64241c15354f">

# User-Facing Changes
- Introduces new command `polars profile`
2024-09-23 07:57:59 -05:00
6f47990a63 Add search terms to into value (#13890)
# Description

From [Discord
today](https://discord.com/channels/601130461678272522/729071784321876040/1286904159047778316),
`into value` isn't classified with `conversions` like the other `into
...` subcommands. I think this is correct, since it's a `table->table`
operation, so it's a filter that has the side effect of (potentially)
converting (via inference) cell values.

But we should at least have some search terms that help here, so this PR
adds *"conversion"* and *"convert"* to the command.

# User-Facing Changes

`help -f conversion` will return `into value`

# Tests + Formatting

- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

# After Submitting

N/A
2024-09-23 07:55:58 -05:00
183c2221bb Removes more quotes on external command arguments (#13883)
# Description
Fixes: #13662

I don't think nushell need to parse and keep nested quote on external
command arguments. Some nested quote is safe to removed. After the pr,
nushell will behave more likely to bash.

# User-Facing Changes
#### Before
```
> ^echo {a:1,b:'c',c:'d'}
{a:1,b:c',c:'d} 
```
#### After
```
> ^echo {a:1,b:'c',c:'d'}
{a:1,b:c,c:d}
```

# Tests + Formatting
Added some tests to cover the behavior
2024-09-23 06:44:51 -05:00
03ee54a4df Fix try not working with let, etc. (#13885)
# Description
Partialy addresses #13868. `try` does not catch non-zero exit code
errors from the last command in a pipeline if the result is assigned to
a variable using `let` (or `mut`).

This was fixed by adding a new `OutDest::Value` case. This is used when
the pipeline is in a "value" position. I.e., it will be collected into a
value. This ended up replacing most of the usages of `OutDest::Capture`.
So, this PR also renames `OutDest::Capture` to `OutDest::PipeSeparate`
to better fit the few remaining use cases for it.

# User-Facing Changes
Bug fix.

# Tests + Formatting
Added two tests.
2024-09-23 06:44:25 -05:00
2541a712e4 Added polars concat to allow concatenation of multiple dataframes (#13879)
# Description
Provides the ability to concatenate multiple dataframes together

# User-Facing Changes
- Introduces new command `polars concat`
2024-09-23 06:43:43 -05:00
ee877607fb fix the ability to add a plugin by name instead of path (#13877)
# Description

This plugin fixes the ability to do `plugin add nu_plugin_polars` and
have nushell look in NU_PLUGINS_DIR to find the plugin and add it.

closes #13040

# 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.
-->
2024-09-23 06:43:19 -05:00
93351b889a view source: add content_type metadata (#13859)
# Description
Add content type metadata to the output of `view source`.

I've gone along with the mime type used [here][xdg], but this shouldn't
be merged until there is consensus #13858.

`to nuon`'s output has content type `application/x-nuon`

[xdg]:
https://gitlab.freedesktop.org/xdg/shared-mime-info/-/merge_requests/231

# User-Facing Changes
Combined with `metadata access`, allows richer display_output hooks.
Might be useful with other commands that make use of content_type like
the `http` commands.
2024-09-23 06:42:52 -05:00
5fa9d76500 polars: add binary type support (#13830)
# Description
This adds support for reading and writing binary types in the polars
commands.

The `BinaryOffset` type can be read into a Nushell native `Value` type
no problem, but unfortunately this is a lossy conversion, as there's
no Nushell-native semantic equivalent to the fixed size binary type
in Arrow.

# User-Facing Changes

`polars open` and `polars save` now work with binary types.
2024-09-23 06:28:41 -05:00
cd0d0364ec Fix do -p not waiting for external commands (#13881)
# Description
Similar to #13870 (thanks @WindSoilder), this PR adds a boolean which
determines whether to ignore any errors from an external command. This
is in order to fix #13876. I.e., `do -p` does not wait for externals to
complete before continuing.

# User-Facing Changes
Bug fix.

# Tests + Formatting
Added a test.
2024-09-22 22:26:32 +08:00
cf5fec63c0 Add loongarch64-unknown-linux-gnu-gcc build target (#13895)
# Description

Add `loongarch64-unknown-linux-gnu-gcc` build target
A test release could be found here:
https://github.com/nushell/nightly/releases/tag/v0.98.1
Loongarch64 workflow build result:
https://github.com/nushell/nightly/actions/runs/10973523602/job/30471006104
2024-09-22 17:20:15 +08:00
5c5cf418fb Bump crate-ci/typos from 1.24.5 to 1.24.6 (#13864)
Bumps [crate-ci/typos](https://github.com/crate-ci/typos) from 1.24.5 to
1.24.6.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/crate-ci/typos/releases">crate-ci/typos's
releases</a>.</em></p>
<blockquote>
<h2>v1.24.6</h2>
<h2>[1.24.6] - 2024-09-16</h2>
<h3>Fixes</h3>
<ul>
<li>Respect negation (<code>!</code>) in
<code>extend-exclude</code></li>
</ul>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/crate-ci/typos/blob/master/CHANGELOG.md">crate-ci/typos's
changelog</a>.</em></p>
<blockquote>
<h2>[1.24.6] - 2024-09-16</h2>
<h3>Fixes</h3>
<ul>
<li>Respect negation (<code>!</code>) in
<code>extend-exclude</code></li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="8e6a4285bc"><code>8e6a428</code></a>
chore: Release</li>
<li><a
href="cab7c3c4a5"><code>cab7c3c</code></a>
docs: Update changelog</li>
<li><a
href="c4a6592239"><code>c4a6592</code></a>
Merge pull request <a
href="https://redirect.github.com/crate-ci/typos/issues/1100">#1100</a>
from epage/invert</li>
<li><a
href="ad3538f719"><code>ad3538f</code></a>
refactor(cli): Switch from Overrides to Gitignore</li>
<li><a
href="d9b55f966c"><code>d9b55f9</code></a>
fix(cli): Allow negative expressions in extend-exclude</li>
<li><a
href="777cf42dc2"><code>777cf42</code></a>
refactor(cli): Be explicit in overrides</li>
<li><a
href="0e8148fbbd"><code>0e8148f</code></a>
test(cli): Show inverted extend-exclude behavior</li>
<li>See full diff in <a
href="https://github.com/crate-ci/typos/compare/v1.24.5...v1.24.6">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=crate-ci/typos&package-manager=github_actions&previous-version=1.24.5&new-version=1.24.6)](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>
2024-09-22 15:16:28 +08:00
fb14008f50 Bump shadow-rs from 0.34.0 to 0.35.0 (#13863)
Bumps [shadow-rs](https://github.com/baoyachi/shadow-rs) from 0.34.0 to
0.35.0.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/baoyachi/shadow-rs/releases">shadow-rs's
releases</a>.</em></p>
<blockquote>
<h2>v0.35.0</h2>
<h2>What's Changed</h2>
<ul>
<li>Update time crate by <a
href="https://github.com/diniamo"><code>@​diniamo</code></a> in <a
href="https://redirect.github.com/baoyachi/shadow-rs/pull/182">baoyachi/shadow-rs#182</a></li>
</ul>
<h2>New Contributors</h2>
<ul>
<li><a href="https://github.com/diniamo"><code>@​diniamo</code></a> made
their first contribution in <a
href="https://redirect.github.com/baoyachi/shadow-rs/pull/182">baoyachi/shadow-rs#182</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/baoyachi/shadow-rs/compare/v0.34.0...v0.35.0">https://github.com/baoyachi/shadow-rs/compare/v0.34.0...v0.35.0</a></p>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="4358b4a094"><code>4358b4a</code></a>
Update Cargo.toml</li>
<li><a
href="2851d669dd"><code>2851d66</code></a>
Merge pull request <a
href="https://redirect.github.com/baoyachi/shadow-rs/issues/182">#182</a>
from diniamo/update-time</li>
<li><a
href="e77dcef733"><code>e77dcef</code></a>
Update time crate</li>
<li>See full diff in <a
href="https://github.com/baoyachi/shadow-rs/compare/v0.34.0...v0.35.0">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=shadow-rs&package-manager=cargo&previous-version=0.34.0&new-version=0.35.0)](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>
2024-09-22 15:16:20 +08:00
18c8c16c5e Bump unicode-segmentation from 1.11.0 to 1.12.0 (#13862)
Bumps
[unicode-segmentation](https://github.com/unicode-rs/unicode-segmentation)
from 1.11.0 to 1.12.0.
<details>
<summary>Commits</summary>
<ul>
<li><a
href="9e3f88c06c"><code>9e3f88c</code></a>
Publish 1.12</li>
<li><a
href="187d8b8e84"><code>187d8b8</code></a>
Support Unicode 16.0.0 (<a
href="https://redirect.github.com/unicode-rs/unicode-segmentation/issues/140">#140</a>)</li>
<li><a
href="0f55f70b44"><code>0f55f70</code></a>
Fix unwrap panic in next_boundary() (<a
href="https://redirect.github.com/unicode-rs/unicode-segmentation/issues/137">#137</a>)</li>
<li><a
href="0fa7148d3b"><code>0fa7148</code></a>
Merge pull request <a
href="https://redirect.github.com/unicode-rs/unicode-segmentation/issues/138">#138</a>
from cardigan1008/issue-overflow</li>
<li><a
href="164f787b72"><code>164f787</code></a>
fmt</li>
<li><a
href="cbb87720d2"><code>cbb8772</code></a>
fix: arithmetic overflow</li>
<li><a
href="2081c29df7"><code>2081c29</code></a>
Merge pull request <a
href="https://redirect.github.com/unicode-rs/unicode-segmentation/issues/136">#136</a>
from Jules-Bertholet/std-tables</li>
<li><a
href="e96ec2eb6c"><code>e96ec2e</code></a>
Use stdlib alphabetic and numeric character tables</li>
<li><a
href="592ce00a3f"><code>592ce00</code></a>
Merge pull request <a
href="https://redirect.github.com/unicode-rs/unicode-segmentation/issues/134">#134</a>
from Jules-Bertholet/fix</li>
<li><a
href="dce3a345cc"><code>dce3a34</code></a>
Add comments to <code>handle_incb_consonant</code></li>
<li>Additional commits viewable in <a
href="https://github.com/unicode-rs/unicode-segmentation/compare/v1.11.0...v1.12.0">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=unicode-segmentation&package-manager=cargo&previous-version=1.11.0&new-version=1.12.0)](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>
2024-09-22 15:16:11 +08:00
299a218de7 Bump tango-bench from 0.5.0 to 0.6.0 (#13861)
Bumps [tango-bench](https://github.com/bazhenov/tango) from 0.5.0 to
0.6.0.
<details>
<summary>Commits</summary>
<ul>
<li><a
href="425ddb93be"><code>425ddb9</code></a>
v0.6.0</li>
<li><a
href="0da1bf5f39"><code>0da1bf5</code></a>
Fixing incorrect path to gnuplot graph</li>
<li><a
href="6b084ea189"><code>6b084ea</code></a>
Limit visibility of internal type</li>
<li><a
href="4ea09e2216"><code>4ea09e2</code></a>
Solo support (<a
href="https://redirect.github.com/bazhenov/tango/issues/35">#35</a>)</li>
<li><a
href="abd888cbc0"><code>abd888c</code></a>
toolchain file added</li>
<li><a
href="2d722474ff"><code>2d72247</code></a>
Async poc (dev-branch) (<a
href="https://redirect.github.com/bazhenov/tango/issues/34">#34</a>)</li>
<li><a
href="5e236aec24"><code>5e236ae</code></a>
Simplify code</li>
<li><a
href="40569a9c98"><code>40569a9</code></a>
Documentation added</li>
<li><a
href="5908909fb2"><code>5908909</code></a>
README updated</li>
<li><a
href="6fb1ebd6f6"><code>6fb1ebd</code></a>
Gnuplot support (<a
href="https://redirect.github.com/bazhenov/tango/issues/33">#33</a>)</li>
<li>Additional commits viewable in <a
href="https://github.com/bazhenov/tango/compare/v0.5.0...v0.6.0">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=tango-bench&package-manager=cargo&previous-version=0.5.0&new-version=0.6.0)](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>
2024-09-22 15:15:58 +08:00
1a081c09de Bump version to 0.98.1 (#13896) 2024-09-22 12:41:44 +08:00
296 changed files with 6520 additions and 5138 deletions

View File

@ -20,6 +20,6 @@ jobs:
continue-on-error: true
steps:
- uses: actions/checkout@v4.1.7
- uses: rustsec/audit-check@v1.4.1
- uses: rustsec/audit-check@v2.0.0
with:
token: ${{ secrets.GITHUB_TOKEN }}

View File

@ -36,7 +36,7 @@ jobs:
- uses: actions/checkout@v4.1.7
- name: Setup Rust toolchain and cache
uses: actions-rust-lang/setup-rust-toolchain@v1.9.0
uses: actions-rust-lang/setup-rust-toolchain@v1.10.1
- name: cargo fmt
run: cargo fmt --all -- --check
@ -64,7 +64,7 @@ jobs:
- uses: actions/checkout@v4.1.7
- name: Setup Rust toolchain and cache
uses: actions-rust-lang/setup-rust-toolchain@v1.9.0
uses: actions-rust-lang/setup-rust-toolchain@v1.10.1
- name: Tests
run: cargo test --workspace --profile ci --exclude nu_plugin_*
@ -93,7 +93,7 @@ jobs:
- uses: actions/checkout@v4.1.7
- name: Setup Rust toolchain and cache
uses: actions-rust-lang/setup-rust-toolchain@v1.9.0
uses: actions-rust-lang/setup-rust-toolchain@v1.10.1
- name: Install Nushell
run: cargo install --path . --locked --no-default-features
@ -144,7 +144,7 @@ jobs:
- uses: actions/checkout@v4.1.7
- name: Setup Rust toolchain and cache
uses: actions-rust-lang/setup-rust-toolchain@v1.9.0
uses: actions-rust-lang/setup-rust-toolchain@v1.10.1
- name: Clippy
run: cargo clippy --package nu_plugin_* -- $CLIPPY_OPTIONS

View File

@ -27,7 +27,7 @@ jobs:
# if: github.repository == 'nushell/nightly'
steps:
- name: Checkout
uses: actions/checkout@v4.1.7
uses: actions/checkout@v4
if: github.repository == 'nushell/nightly'
with:
ref: main
@ -36,10 +36,10 @@ jobs:
token: ${{ secrets.WORKFLOW_TOKEN }}
- name: Setup Nushell
uses: hustcer/setup-nu@v3.13
uses: hustcer/setup-nu@v3
if: github.repository == 'nushell/nightly'
with:
version: 0.97.1
version: 0.98.0
# Synchronize the main branch of nightly repo with the main branch of Nushell official repo
- name: Prepare for Nightly Release
@ -65,7 +65,7 @@ jobs:
}
standard:
name: Std
name: Nu
needs: prepare
strategy:
fail-fast: false
@ -82,6 +82,7 @@ jobs:
- armv7-unknown-linux-gnueabihf
- armv7-unknown-linux-musleabihf
- riscv64gc-unknown-linux-gnu
- loongarch64-unknown-linux-gnu
extra: ['bin']
include:
- target: aarch64-apple-darwin
@ -114,11 +115,13 @@ jobs:
os: ubuntu-22.04
- target: riscv64gc-unknown-linux-gnu
os: ubuntu-latest
- target: loongarch64-unknown-linux-gnu
os: ubuntu-22.04
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v4.1.7
- uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0
@ -128,15 +131,15 @@ jobs:
echo "targets = ['${{matrix.target}}']" >> rust-toolchain.toml
- name: Setup Rust toolchain and cache
uses: actions-rust-lang/setup-rust-toolchain@v1.9.0
uses: actions-rust-lang/setup-rust-toolchain@v1.10.1
# WARN: Keep the rustflags to prevent from the winget submission error: `CAQuietExec: Error 0xc0000135`
with:
rustflags: ''
- name: Setup Nushell
uses: hustcer/setup-nu@v3.13
uses: hustcer/setup-nu@v3
with:
version: 0.97.1
version: 0.98.0
- name: Release Nu Binary
id: nu
@ -187,14 +190,14 @@ jobs:
- name: Waiting for Release
run: sleep 1800
- uses: actions/checkout@v4.1.7
- uses: actions/checkout@v4
with:
ref: main
- name: Setup Nushell
uses: hustcer/setup-nu@v3.13
uses: hustcer/setup-nu@v3
with:
version: 0.97.1
version: 0.98.0
# Keep the last a few releases
- name: Delete Older Releases

View File

@ -98,6 +98,13 @@ if $os in ['macos-latest'] or $USE_UBUNTU {
$env.CARGO_TARGET_ARMV7_UNKNOWN_LINUX_MUSLEABIHF_LINKER = 'armv7r-linux-musleabihf-gcc'
cargo-build-nu
}
'loongarch64-unknown-linux-gnu' => {
aria2c https://github.com/loongson/build-tools/releases/download/2024.08.08/x86_64-cross-tools-loongarch64-binutils_2.43-gcc_14.2.0-glibc_2.40.tar.xz
tar xf x86_64-cross-tools-loongarch64-*.tar.xz
$env.PATH = ($env.PATH | split row (char esep) | prepend $'($env.PWD)/cross-tools/bin')
$env.CARGO_TARGET_LOONGARCH64_UNKNOWN_LINUX_GNU_LINKER = 'loongarch64-unknown-linux-gnu-gcc'
cargo-build-nu
}
_ => {
# musl-tools to fix 'Failed to find tool. Is `musl-gcc` installed?'
# Actually just for x86_64-unknown-linux-musl target

View File

@ -14,8 +14,8 @@ defaults:
shell: bash
jobs:
standard:
name: Std
release:
name: Nu
strategy:
fail-fast: false
@ -32,6 +32,7 @@ jobs:
- armv7-unknown-linux-gnueabihf
- armv7-unknown-linux-musleabihf
- riscv64gc-unknown-linux-gnu
- loongarch64-unknown-linux-gnu
extra: ['bin']
include:
- target: aarch64-apple-darwin
@ -64,27 +65,29 @@ jobs:
os: ubuntu-22.04
- target: riscv64gc-unknown-linux-gnu
os: ubuntu-latest
- target: loongarch64-unknown-linux-gnu
os: ubuntu-22.04
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v4.1.7
- uses: actions/checkout@v4
- name: Update Rust Toolchain Target
run: |
echo "targets = ['${{matrix.target}}']" >> rust-toolchain.toml
- name: Setup Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1.9.0
uses: actions-rust-lang/setup-rust-toolchain@v1.10.1
# WARN: Keep the rustflags to prevent from the winget submission error: `CAQuietExec: Error 0xc0000135`
with:
cache: false
rustflags: ''
- name: Setup Nushell
uses: hustcer/setup-nu@v3.13
uses: hustcer/setup-nu@v3
with:
version: 0.97.1
version: 0.98.0
- name: Release Nu Binary
id: nu
@ -104,3 +107,26 @@ jobs:
files: ${{ steps.nu.outputs.archive }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
sha256sum:
needs: release
name: Create Sha256sum
runs-on: ubuntu-latest
steps:
- name: Download Release Archives
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: >-
gh release download ${{ github.ref_name }}
--repo ${{ github.repository }}
--pattern '*'
--dir release
- name: Create Checksums
run: cd release && shasum -a 256 * > ../SHA256SUMS
- name: Publish Checksums
uses: softprops/action-gh-release@v2.0.8
with:
draft: true
files: SHA256SUMS
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@ -10,4 +10,4 @@ jobs:
uses: actions/checkout@v4.1.7
- name: Check spelling
uses: crate-ci/typos@v1.24.5
uses: crate-ci/typos@v1.26.0

128
Cargo.lock generated
View File

@ -1479,9 +1479,9 @@ checksum = "95765f67b4b18863968b4a1bd5bb576f732b29a4a28c7cd84c09fa3e2875f33c"
[[package]]
name = "fastrand"
version = "2.1.0"
version = "2.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a"
checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6"
[[package]]
name = "fd-lock"
@ -1865,6 +1865,12 @@ dependencies = [
"serde",
]
[[package]]
name = "hashbrown"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb"
[[package]]
name = "hashlink"
version = "0.9.1"
@ -1979,9 +1985,9 @@ checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9"
[[package]]
name = "human-date-parser"
version = "0.1.2"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c5cbf96a7157cc349eeafe4595e4f283c3fcab73b5a656d8b2cc00a870a74e1a"
checksum = "1116cf4debfe770c12168458321c4a8591b71c4c19f7100de07c84cf81701c63"
dependencies = [
"chrono",
"pest",
@ -2074,12 +2080,12 @@ dependencies = [
[[package]]
name = "indexmap"
version = "2.5.0"
version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5"
checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da"
dependencies = [
"equivalent",
"hashbrown 0.14.5",
"hashbrown 0.15.0",
"serde",
]
@ -2938,7 +2944,7 @@ dependencies = [
[[package]]
name = "nu"
version = "0.98.0"
version = "0.99.0"
dependencies = [
"assert_cmd",
"crossterm 0.28.1",
@ -2993,7 +2999,7 @@ dependencies = [
[[package]]
name = "nu-cli"
version = "0.98.0"
version = "0.99.0"
dependencies = [
"chrono",
"crossterm 0.28.1",
@ -3028,7 +3034,7 @@ dependencies = [
[[package]]
name = "nu-cmd-base"
version = "0.98.0"
version = "0.99.0"
dependencies = [
"indexmap",
"miette",
@ -3040,7 +3046,7 @@ dependencies = [
[[package]]
name = "nu-cmd-extra"
version = "0.98.0"
version = "0.99.0"
dependencies = [
"fancy-regex",
"heck",
@ -3065,7 +3071,7 @@ dependencies = [
[[package]]
name = "nu-cmd-lang"
version = "0.98.0"
version = "0.99.0"
dependencies = [
"itertools 0.13.0",
"nu-engine",
@ -3077,7 +3083,7 @@ dependencies = [
[[package]]
name = "nu-cmd-plugin"
version = "0.98.0"
version = "0.99.0"
dependencies = [
"itertools 0.13.0",
"nu-engine",
@ -3088,7 +3094,7 @@ dependencies = [
[[package]]
name = "nu-color-config"
version = "0.98.0"
version = "0.99.0"
dependencies = [
"nu-ansi-term",
"nu-engine",
@ -3100,7 +3106,7 @@ dependencies = [
[[package]]
name = "nu-command"
version = "0.98.0"
version = "0.99.0"
dependencies = [
"alphanumeric-sort",
"base64 0.22.1",
@ -3210,7 +3216,7 @@ dependencies = [
[[package]]
name = "nu-derive-value"
version = "0.98.0"
version = "0.99.0"
dependencies = [
"heck",
"proc-macro-error",
@ -3221,7 +3227,7 @@ dependencies = [
[[package]]
name = "nu-engine"
version = "0.98.0"
version = "0.99.0"
dependencies = [
"log",
"nu-glob",
@ -3233,7 +3239,7 @@ dependencies = [
[[package]]
name = "nu-explore"
version = "0.98.0"
version = "0.99.0"
dependencies = [
"ansi-str",
"anyhow",
@ -3245,6 +3251,7 @@ dependencies = [
"nu-engine",
"nu-json",
"nu-parser",
"nu-path",
"nu-pretty-hex",
"nu-protocol",
"nu-table",
@ -3258,14 +3265,14 @@ dependencies = [
[[package]]
name = "nu-glob"
version = "0.98.0"
version = "0.99.0"
dependencies = [
"doc-comment",
]
[[package]]
name = "nu-json"
version = "0.98.0"
version = "0.99.0"
dependencies = [
"fancy-regex",
"linked-hash-map",
@ -3278,7 +3285,7 @@ dependencies = [
[[package]]
name = "nu-lsp"
version = "0.98.0"
version = "0.99.0"
dependencies = [
"assert-json-diff",
"crossbeam-channel",
@ -3299,7 +3306,7 @@ dependencies = [
[[package]]
name = "nu-parser"
version = "0.98.0"
version = "0.99.0"
dependencies = [
"bytesize",
"chrono",
@ -3315,7 +3322,7 @@ dependencies = [
[[package]]
name = "nu-path"
version = "0.98.0"
version = "0.99.0"
dependencies = [
"dirs",
"omnipath",
@ -3324,7 +3331,7 @@ dependencies = [
[[package]]
name = "nu-plugin"
version = "0.98.0"
version = "0.99.0"
dependencies = [
"log",
"nix 0.29.0",
@ -3340,7 +3347,7 @@ dependencies = [
[[package]]
name = "nu-plugin-core"
version = "0.98.0"
version = "0.99.0"
dependencies = [
"interprocess",
"log",
@ -3354,7 +3361,7 @@ dependencies = [
[[package]]
name = "nu-plugin-engine"
version = "0.98.0"
version = "0.99.0"
dependencies = [
"log",
"nu-engine",
@ -3370,7 +3377,7 @@ dependencies = [
[[package]]
name = "nu-plugin-protocol"
version = "0.98.0"
version = "0.99.0"
dependencies = [
"nu-protocol",
"nu-utils",
@ -3382,7 +3389,7 @@ dependencies = [
[[package]]
name = "nu-plugin-test-support"
version = "0.98.0"
version = "0.99.0"
dependencies = [
"nu-ansi-term",
"nu-cmd-lang",
@ -3400,7 +3407,7 @@ dependencies = [
[[package]]
name = "nu-pretty-hex"
version = "0.98.0"
version = "0.99.0"
dependencies = [
"heapless",
"nu-ansi-term",
@ -3409,7 +3416,7 @@ dependencies = [
[[package]]
name = "nu-protocol"
version = "0.98.0"
version = "0.99.0"
dependencies = [
"brotli",
"byte-unit",
@ -3447,7 +3454,7 @@ dependencies = [
[[package]]
name = "nu-std"
version = "0.98.0"
version = "0.99.0"
dependencies = [
"log",
"miette",
@ -3458,7 +3465,7 @@ dependencies = [
[[package]]
name = "nu-system"
version = "0.98.0"
version = "0.99.0"
dependencies = [
"chrono",
"itertools 0.13.0",
@ -3476,7 +3483,7 @@ dependencies = [
[[package]]
name = "nu-table"
version = "0.98.0"
version = "0.99.0"
dependencies = [
"fancy-regex",
"nu-ansi-term",
@ -3486,11 +3493,12 @@ dependencies = [
"nu-utils",
"once_cell",
"tabled",
"terminal_size",
]
[[package]]
name = "nu-term-grid"
version = "0.98.0"
version = "0.99.0"
dependencies = [
"nu-utils",
"unicode-width",
@ -3498,7 +3506,7 @@ dependencies = [
[[package]]
name = "nu-test-support"
version = "0.98.0"
version = "0.99.0"
dependencies = [
"nu-glob",
"nu-path",
@ -3510,7 +3518,7 @@ dependencies = [
[[package]]
name = "nu-utils"
version = "0.98.0"
version = "0.99.0"
dependencies = [
"crossterm_winapi",
"log",
@ -3536,7 +3544,7 @@ dependencies = [
[[package]]
name = "nu_plugin_example"
version = "0.98.0"
version = "0.99.0"
dependencies = [
"nu-cmd-lang",
"nu-plugin",
@ -3546,7 +3554,7 @@ dependencies = [
[[package]]
name = "nu_plugin_formats"
version = "0.98.0"
version = "0.99.0"
dependencies = [
"chrono",
"eml-parser",
@ -3561,7 +3569,7 @@ dependencies = [
[[package]]
name = "nu_plugin_gstat"
version = "0.98.0"
version = "0.99.0"
dependencies = [
"git2",
"nu-plugin",
@ -3570,7 +3578,7 @@ dependencies = [
[[package]]
name = "nu_plugin_inc"
version = "0.98.0"
version = "0.99.0"
dependencies = [
"nu-plugin",
"nu-protocol",
@ -3579,12 +3587,13 @@ dependencies = [
[[package]]
name = "nu_plugin_polars"
version = "0.98.0"
version = "0.99.0"
dependencies = [
"chrono",
"chrono-tz 0.9.0",
"env_logger 0.11.5",
"fancy-regex",
"hashbrown 0.14.5",
"indexmap",
"log",
"mimalloc",
@ -3613,7 +3622,7 @@ dependencies = [
[[package]]
name = "nu_plugin_query"
version = "0.98.0"
version = "0.99.0"
dependencies = [
"gjson",
"nu-plugin",
@ -3628,7 +3637,7 @@ dependencies = [
[[package]]
name = "nu_plugin_stress_internals"
version = "0.98.0"
version = "0.99.0"
dependencies = [
"interprocess",
"serde",
@ -3742,7 +3751,7 @@ checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3"
[[package]]
name = "nuon"
version = "0.98.0"
version = "0.99.0"
dependencies = [
"chrono",
"fancy-regex",
@ -3877,9 +3886,12 @@ checksum = "80adb31078122c880307e9cdfd4e3361e6545c319f9b9dcafcb03acd3b51a575"
[[package]]
name = "once_cell"
version = "1.19.0"
version = "1.20.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
checksum = "82881c4be219ab5faaf2ad5e5e5ecdff8c66bd7402ca3160975c93b24961afd1"
dependencies = [
"portable-atomic",
]
[[package]]
name = "open"
@ -5135,9 +5147,9 @@ dependencies = [
[[package]]
name = "reedline"
version = "0.35.0"
version = "0.36.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c5289de810296f8f2ff58d35544d92ae98d0a631453388bc3e608086be0fa596"
checksum = "57016fc0ec4c651a05cb80fb1200b7c3518afcc2f769edffe15aca2363395c15"
dependencies = [
"arboard",
"chrono",
@ -5433,9 +5445,9 @@ dependencies = [
[[package]]
name = "rustix"
version = "0.38.34"
version = "0.38.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f"
checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811"
dependencies = [
"bitflags 2.6.0",
"errno",
@ -5715,9 +5727,9 @@ dependencies = [
[[package]]
name = "shadow-rs"
version = "0.34.0"
version = "0.35.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "69fe0bac8a8752586a618a1c80d01d8ca5d40fce4f6077fbc851e48dcbdb90df"
checksum = "fca0e9bdc073d7173ba993fb7886477af5df75588b57afcb4b96f21911ab0bfa"
dependencies = [
"const_format",
"is_debug",
@ -6120,9 +6132,9 @@ dependencies = [
[[package]]
name = "tango-bench"
version = "0.5.0"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3e79d9e491b718fb52bb2052726a0e66fe89a31cc6979fe58c72c73f058c279e"
checksum = "257822358c6f206fed78bfe6369cf959063b0644d70f88df6b19f2dadc93423e"
dependencies = [
"alloca",
"anyhow",
@ -6153,9 +6165,9 @@ checksum = "c1bbb9f3c5c463a01705937a24fdabc5047929ac764b2d5b9cf681c1f5041ed5"
[[package]]
name = "tempfile"
version = "3.12.0"
version = "3.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64"
checksum = "f0f2c9fc62d0beef6951ccffd757e241266a2c833136efbe35af6cd2567dca5b"
dependencies = [
"cfg-if",
"fastrand",
@ -6568,9 +6580,9 @@ dependencies = [
[[package]]
name = "unicode-segmentation"
version = "1.11.0"
version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202"
checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493"
[[package]]
name = "unicode-truncate"

View File

@ -11,7 +11,7 @@ license = "MIT"
name = "nu"
repository = "https://github.com/nushell/nushell"
rust-version = "1.79.0"
version = "0.98.0"
version = "0.99.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@ -91,8 +91,8 @@ filesize = "0.2"
filetime = "0.2"
fuzzy-matcher = "0.3"
heck = "0.5.0"
human-date-parser = "0.1.1"
indexmap = "2.5"
human-date-parser = "0.2.0"
indexmap = "2.6"
indicatif = "0.17"
interprocess = "2.2.0"
is_executable = "1.0"
@ -118,7 +118,7 @@ nu-ansi-term = "0.50.1"
num-format = "0.4"
num-traits = "0.2"
omnipath = "0.1"
once_cell = "1.18"
once_cell = "1.20"
open = "5.3"
os_pipe = { version = "1.2", features = ["io_safety"] }
pathdiff = "0.2"
@ -137,7 +137,7 @@ rand = "0.8"
rand_chacha = "0.3.1"
ratatui = "0.26"
rayon = "1.10"
reedline = "0.35.0"
reedline = "0.36.0"
regex = "1.9.5"
rmp = "0.8"
rmp-serde = "1.3"
@ -155,13 +155,13 @@ strip-ansi-escapes = "0.2.0"
syn = "2.0"
sysinfo = "0.30"
tabled = { version = "0.16.0", default-features = false }
tempfile = "3.10"
tempfile = "3.13"
terminal_size = "0.3"
titlecase = "2.0"
toml = "0.8"
trash = "3.3"
umask = "2.1"
unicode-segmentation = "1.11"
unicode-segmentation = "1.12"
unicode-width = "0.1"
ureq = { version = "2.10", default-features = false }
url = "2.2"
@ -189,22 +189,22 @@ unchecked_duration_subtraction = "warn"
workspace = true
[dependencies]
nu-cli = { path = "./crates/nu-cli", version = "0.98.0" }
nu-cmd-base = { path = "./crates/nu-cmd-base", version = "0.98.0" }
nu-cmd-lang = { path = "./crates/nu-cmd-lang", version = "0.98.0" }
nu-cmd-plugin = { path = "./crates/nu-cmd-plugin", version = "0.98.0", optional = true }
nu-cmd-extra = { path = "./crates/nu-cmd-extra", version = "0.98.0" }
nu-command = { path = "./crates/nu-command", version = "0.98.0" }
nu-engine = { path = "./crates/nu-engine", version = "0.98.0" }
nu-explore = { path = "./crates/nu-explore", version = "0.98.0" }
nu-lsp = { path = "./crates/nu-lsp/", version = "0.98.0" }
nu-parser = { path = "./crates/nu-parser", version = "0.98.0" }
nu-path = { path = "./crates/nu-path", version = "0.98.0" }
nu-plugin-engine = { path = "./crates/nu-plugin-engine", optional = true, version = "0.98.0" }
nu-protocol = { path = "./crates/nu-protocol", version = "0.98.0" }
nu-std = { path = "./crates/nu-std", version = "0.98.0" }
nu-system = { path = "./crates/nu-system", version = "0.98.0" }
nu-utils = { path = "./crates/nu-utils", version = "0.98.0" }
nu-cli = { path = "./crates/nu-cli", version = "0.99.0" }
nu-cmd-base = { path = "./crates/nu-cmd-base", version = "0.99.0" }
nu-cmd-lang = { path = "./crates/nu-cmd-lang", version = "0.99.0" }
nu-cmd-plugin = { path = "./crates/nu-cmd-plugin", version = "0.99.0", optional = true }
nu-cmd-extra = { path = "./crates/nu-cmd-extra", version = "0.99.0" }
nu-command = { path = "./crates/nu-command", version = "0.99.0" }
nu-engine = { path = "./crates/nu-engine", version = "0.99.0" }
nu-explore = { path = "./crates/nu-explore", version = "0.99.0" }
nu-lsp = { path = "./crates/nu-lsp/", version = "0.99.0" }
nu-parser = { path = "./crates/nu-parser", version = "0.99.0" }
nu-path = { path = "./crates/nu-path", version = "0.99.0" }
nu-plugin-engine = { path = "./crates/nu-plugin-engine", optional = true, version = "0.99.0" }
nu-protocol = { path = "./crates/nu-protocol", version = "0.99.0" }
nu-std = { path = "./crates/nu-std", version = "0.99.0" }
nu-system = { path = "./crates/nu-system", version = "0.99.0" }
nu-utils = { path = "./crates/nu-utils", version = "0.99.0" }
reedline = { workspace = true, features = ["bashisms", "sqlite"] }
crossterm = { workspace = true }
@ -234,12 +234,12 @@ nix = { workspace = true, default-features = false, features = [
] }
[dev-dependencies]
nu-test-support = { path = "./crates/nu-test-support", version = "0.98.0" }
nu-plugin-protocol = { path = "./crates/nu-plugin-protocol", version = "0.98.0" }
nu-plugin-core = { path = "./crates/nu-plugin-core", version = "0.98.0" }
nu-test-support = { path = "./crates/nu-test-support", version = "0.99.0" }
nu-plugin-protocol = { path = "./crates/nu-plugin-protocol", version = "0.99.0" }
nu-plugin-core = { path = "./crates/nu-plugin-core", version = "0.99.0" }
assert_cmd = "2.0"
dirs = { workspace = true }
tango-bench = "0.5"
tango-bench = "0.6"
pretty_assertions = { workspace = true }
regex = { workspace = true }
rstest = { workspace = true, default-features = false }
@ -320,4 +320,4 @@ bench = false
# Run individual benchmarks like `cargo bench -- <regex>` e.g. `cargo bench -- parse`
[[bench]]
name = "benchmarks"
harness = false
harness = false

View File

@ -5,27 +5,27 @@ repository = "https://github.com/nushell/nushell/tree/main/crates/nu-cli"
edition = "2021"
license = "MIT"
name = "nu-cli"
version = "0.98.0"
version = "0.99.0"
[lib]
bench = false
[dev-dependencies]
nu-cmd-lang = { path = "../nu-cmd-lang", version = "0.98.0" }
nu-command = { path = "../nu-command", version = "0.98.0" }
nu-test-support = { path = "../nu-test-support", version = "0.98.0" }
nu-cmd-lang = { path = "../nu-cmd-lang", version = "0.99.0" }
nu-command = { path = "../nu-command", version = "0.99.0" }
nu-test-support = { path = "../nu-test-support", version = "0.99.0" }
rstest = { workspace = true, default-features = false }
tempfile = { workspace = true }
[dependencies]
nu-cmd-base = { path = "../nu-cmd-base", version = "0.98.0" }
nu-engine = { path = "../nu-engine", version = "0.98.0" }
nu-path = { path = "../nu-path", version = "0.98.0" }
nu-parser = { path = "../nu-parser", version = "0.98.0" }
nu-plugin-engine = { path = "../nu-plugin-engine", version = "0.98.0", optional = true }
nu-protocol = { path = "../nu-protocol", version = "0.98.0" }
nu-utils = { path = "../nu-utils", version = "0.98.0" }
nu-color-config = { path = "../nu-color-config", version = "0.98.0" }
nu-cmd-base = { path = "../nu-cmd-base", version = "0.99.0" }
nu-engine = { path = "../nu-engine", version = "0.99.0" }
nu-path = { path = "../nu-path", version = "0.99.0" }
nu-parser = { path = "../nu-parser", version = "0.99.0" }
nu-plugin-engine = { path = "../nu-plugin-engine", version = "0.99.0", optional = true }
nu-protocol = { path = "../nu-protocol", version = "0.99.0" }
nu-utils = { path = "../nu-utils", version = "0.99.0" }
nu-color-config = { path = "../nu-color-config", version = "0.99.0" }
nu-ansi-term = { workspace = true }
reedline = { workspace = true, features = ["bashisms", "sqlite"] }

View File

@ -42,91 +42,75 @@ impl Command for History {
let Some(history) = engine_state.history_config() else {
return Ok(PipelineData::empty());
};
// todo for sqlite history this command should be an alias to `open ~/.config/nushell/history.sqlite3 | get history`
if let Some(config_path) = nu_path::config_dir() {
let clear = call.has_flag(engine_state, stack, "clear")?;
let long = call.has_flag(engine_state, stack, "long")?;
let signals = engine_state.signals().clone();
let Some(history_path) = history.file_path() else {
return Err(ShellError::ConfigDirNotFound { span: Some(head) });
};
let mut history_path = config_path;
history_path.push("nushell");
match history.file_format {
HistoryFileFormat::Sqlite => {
history_path.push("history.sqlite3");
}
HistoryFileFormat::Plaintext => {
history_path.push("history.txt");
}
}
if call.has_flag(engine_state, stack, "clear")? {
let _ = std::fs::remove_file(history_path);
// TODO: FIXME also clear the auxiliary files when using sqlite
return Ok(PipelineData::empty());
}
if clear {
let _ = std::fs::remove_file(history_path);
// TODO: FIXME also clear the auxiliary files when using sqlite
Ok(PipelineData::empty())
} else {
let history_reader: Option<Box<dyn ReedlineHistory>> = match history.file_format {
HistoryFileFormat::Sqlite => {
SqliteBackedHistory::with_file(history_path.clone().into(), None, None)
.map(|inner| {
let boxed: Box<dyn ReedlineHistory> = Box::new(inner);
boxed
})
.ok()
}
HistoryFileFormat::Plaintext => FileBackedHistory::with_file(
history.max_size as usize,
history_path.clone().into(),
)
let long = call.has_flag(engine_state, stack, "long")?;
let signals = engine_state.signals().clone();
let history_reader: Option<Box<dyn ReedlineHistory>> = match history.file_format {
HistoryFileFormat::Sqlite => {
SqliteBackedHistory::with_file(history_path.clone(), None, None)
.map(|inner| {
let boxed: Box<dyn ReedlineHistory> = Box::new(inner);
boxed
})
.ok(),
};
match history.file_format {
HistoryFileFormat::Plaintext => Ok(history_reader
.and_then(|h| {
h.search(SearchQuery::everything(SearchDirection::Forward, None))
.ok()
})
.map(move |entries| {
entries.into_iter().enumerate().map(move |(idx, entry)| {
Value::record(
record! {
"command" => Value::string(entry.command_line, head),
"index" => Value::int(idx as i64, head),
},
head,
)
})
})
.ok_or(ShellError::FileNotFound {
file: history_path.display().to_string(),
span: head,
})?
.into_pipeline_data(head, signals)),
HistoryFileFormat::Sqlite => Ok(history_reader
.and_then(|h| {
h.search(SearchQuery::everything(SearchDirection::Forward, None))
.ok()
})
.map(move |entries| {
entries.into_iter().enumerate().map(move |(idx, entry)| {
create_history_record(idx, entry, long, head)
})
})
.ok_or(ShellError::FileNotFound {
file: history_path.display().to_string(),
span: head,
})?
.into_pipeline_data(head, signals)),
}
.ok()
}
} else {
Err(ShellError::ConfigDirNotFound { span: Some(head) })
HistoryFileFormat::Plaintext => {
FileBackedHistory::with_file(history.max_size as usize, history_path.clone())
.map(|inner| {
let boxed: Box<dyn ReedlineHistory> = Box::new(inner);
boxed
})
.ok()
}
};
match history.file_format {
HistoryFileFormat::Plaintext => Ok(history_reader
.and_then(|h| {
h.search(SearchQuery::everything(SearchDirection::Forward, None))
.ok()
})
.map(move |entries| {
entries.into_iter().enumerate().map(move |(idx, entry)| {
Value::record(
record! {
"command" => Value::string(entry.command_line, head),
"index" => Value::int(idx as i64, head),
},
head,
)
})
})
.ok_or(ShellError::FileNotFound {
file: history_path.display().to_string(),
span: head,
})?
.into_pipeline_data(head, signals)),
HistoryFileFormat::Sqlite => Ok(history_reader
.and_then(|h| {
h.search(SearchQuery::everything(SearchDirection::Forward, None))
.ok()
})
.map(move |entries| {
entries
.into_iter()
.enumerate()
.map(move |(idx, entry)| create_history_record(idx, entry, long, head))
})
.ok_or(ShellError::FileNotFound {
file: history_path.display().to_string(),
span: head,
})?
.into_pipeline_data(head, signals)),
}
}

View File

@ -12,7 +12,7 @@ pub trait Completer {
&mut self,
working_set: &StateWorkingSet,
stack: &Stack,
prefix: Vec<u8>,
prefix: &[u8],
span: Span,
offset: usize,
pos: usize,

View File

@ -158,7 +158,7 @@ impl Completer for CommandCompletion {
&mut self,
working_set: &StateWorkingSet,
_stack: &Stack,
prefix: Vec<u8>,
prefix: &[u8],
span: Span,
offset: usize,
pos: usize,
@ -195,7 +195,7 @@ impl Completer for CommandCompletion {
};
if !subcommands.is_empty() {
return sort_suggestions(&String::from_utf8_lossy(&prefix), subcommands, options);
return sort_suggestions(&String::from_utf8_lossy(prefix), subcommands, options);
}
let config = working_set.get_config();
@ -220,7 +220,7 @@ impl Completer for CommandCompletion {
vec![]
};
sort_suggestions(&String::from_utf8_lossy(&prefix), commands, options)
sort_suggestions(&String::from_utf8_lossy(prefix), commands, options)
}
}

View File

@ -1,6 +1,6 @@
use crate::completions::{
CommandCompletion, Completer, CompletionOptions, CustomCompletion, DirectoryCompletion,
DotNuCompletion, FileCompletion, FlagCompletion, VariableCompletion,
DotNuCompletion, FileCompletion, FlagCompletion, OperatorCompletion, VariableCompletion,
};
use nu_color_config::{color_record_to_nustyle, lookup_ansi_color_style};
use nu_engine::eval_block;
@ -25,7 +25,7 @@ impl NuCompleter {
pub fn new(engine_state: Arc<EngineState>, stack: Arc<Stack>) -> Self {
Self {
engine_state,
stack: Stack::with_parent(stack).reset_out_dest().capture(),
stack: Stack::with_parent(stack).reset_out_dest().collect_value(),
}
}
@ -38,7 +38,7 @@ impl NuCompleter {
&self,
completer: &mut T,
working_set: &StateWorkingSet,
prefix: Vec<u8>,
prefix: &[u8],
new_span: Span,
offset: usize,
pos: usize,
@ -55,7 +55,7 @@ impl NuCompleter {
completer.fetch(
working_set,
&self.stack,
prefix.clone(),
prefix,
new_span,
offset,
pos,
@ -170,23 +170,38 @@ impl NuCompleter {
let new_span = Span::new(flat.0.start, flat.0.end - 1);
// Parses the prefix. Completion should look up to the cursor position, not after.
let mut prefix = working_set.get_span_contents(flat.0).to_vec();
let mut prefix = working_set.get_span_contents(flat.0);
let index = pos - flat.0.start;
prefix.drain(index..);
prefix = &prefix[..index];
// Variables completion
if prefix.starts_with(b"$") || most_left_var.is_some() {
let mut completer =
let mut variable_names_completer =
VariableCompletion::new(most_left_var.unwrap_or((vec![], vec![])));
return self.process_completion(
&mut completer,
let mut variable_completions = self.process_completion(
&mut variable_names_completer,
&working_set,
prefix,
new_span,
fake_offset,
pos,
);
let mut variable_operations_completer =
OperatorCompletion::new(pipeline_element.expr.clone());
let mut variable_operations_completions = self.process_completion(
&mut variable_operations_completer,
&working_set,
prefix,
new_span,
fake_offset,
pos,
);
variable_completions.append(&mut variable_operations_completions);
return variable_completions;
}
// Flags completion
@ -196,7 +211,7 @@ impl NuCompleter {
let result = self.process_completion(
&mut completer,
&working_set,
prefix.clone(),
prefix,
new_span,
fake_offset,
pos,
@ -262,6 +277,26 @@ impl NuCompleter {
} else if prev_expr_str == b"ls" {
let mut completer = FileCompletion::new();
return self.process_completion(
&mut completer,
&working_set,
prefix,
new_span,
fake_offset,
pos,
);
} else if matches!(
previous_expr.1,
FlatShape::Float
| FlatShape::Int
| FlatShape::String
| FlatShape::List
| FlatShape::Bool
| FlatShape::Variable(_)
) {
let mut completer =
OperatorCompletion::new(pipeline_element.expr.clone());
return self.process_completion(
&mut completer,
&working_set,
@ -327,7 +362,7 @@ impl NuCompleter {
let mut out: Vec<_> = self.process_completion(
&mut completer,
&working_set,
prefix.clone(),
prefix,
new_span,
fake_offset,
pos,
@ -533,6 +568,11 @@ mod completer_tests {
let mut completer = NuCompleter::new(engine_state.into(), Arc::new(Stack::new()));
let dataset = [
("1 bit-sh", true, "b", vec!["bit-shl", "bit-shr"]),
("1.0 bit-sh", false, "b", vec![]),
("1 m", true, "m", vec!["mod"]),
("1.0 m", true, "m", vec!["mod"]),
("\"a\" s", true, "s", vec!["starts-with"]),
("sudo", false, "", Vec::new()),
("sudo l", true, "l", vec!["ls", "let", "lines", "loop"]),
(" sudo", false, "", Vec::new()),

View File

@ -180,7 +180,7 @@ pub fn complete_item(
&& engine_state.config.use_ansi_coloring)
.then(|| {
let ls_colors_env_str = match stack.get_env_var(engine_state, "LS_COLORS") {
Some(v) => env_to_string("LS_COLORS", &v, engine_state, stack).ok(),
Some(v) => env_to_string("LS_COLORS", v, engine_state, stack).ok(),
None => None,
};
get_ls_colors(ls_colors_env_str)
@ -267,8 +267,10 @@ pub fn escape_path(path: String, dir: bool) -> String {
let filename_contaminated = !dir && path.contains(['\'', '"', ' ', '#', '(', ')']);
let dirname_contaminated = dir && path.contains(['\'', '"', ' ', '#']);
let maybe_flag = path.starts_with('-');
let maybe_variable = path.starts_with('$');
let maybe_number = path.parse::<f64>().is_ok();
if filename_contaminated || dirname_contaminated || maybe_flag || maybe_number {
if filename_contaminated || dirname_contaminated || maybe_flag || maybe_variable || maybe_number
{
format!("`{path}`")
} else {
path
@ -333,7 +335,7 @@ pub fn sort_completions<T>(
} else {
matcher = matcher.ignore_case();
};
items.sort_by(|a, b| {
items.sort_unstable_by(|a, b| {
let a_str = get_value(a);
let b_str = get_value(b);
let a_score = matcher.fuzzy_match(a_str, prefix).unwrap_or_default();
@ -341,7 +343,7 @@ pub fn sort_completions<T>(
b_score.cmp(&a_score).then(a_str.cmp(b_str))
});
} else {
items.sort_by(|a, b| get_value(a).cmp(get_value(b)));
items.sort_unstable_by(|a, b| get_value(a).cmp(get_value(b)));
}
items

View File

@ -7,7 +7,7 @@ use nu_protocol::{
ast::{Argument, Call, Expr, Expression},
debugger::WithoutDebug,
engine::{Stack, StateWorkingSet},
CompletionSort, PipelineData, Span, Type, Value,
CompletionSort, DeclId, PipelineData, Span, Type, Value,
};
use nu_utils::IgnoreCaseExt;
use std::collections::HashMap;
@ -16,12 +16,12 @@ use super::completion_common::sort_suggestions;
pub struct CustomCompletion {
stack: Stack,
decl_id: usize,
decl_id: DeclId,
line: String,
}
impl CustomCompletion {
pub fn new(stack: Stack, decl_id: usize, line: String) -> Self {
pub fn new(stack: Stack, decl_id: DeclId, line: String) -> Self {
Self {
stack,
decl_id,
@ -35,7 +35,7 @@ impl Completer for CustomCompletion {
&mut self,
working_set: &StateWorkingSet,
_stack: &Stack,
prefix: Vec<u8>,
prefix: &[u8],
span: Span,
offset: usize,
pos: usize,
@ -126,8 +126,8 @@ impl Completer for CustomCompletion {
let options = custom_completion_options
.as_ref()
.unwrap_or(completion_options);
let suggestions = filter(&prefix, suggestions, options);
sort_suggestions(&String::from_utf8_lossy(&prefix), suggestions, options)
let suggestions = filter(prefix, suggestions, options);
sort_suggestions(&String::from_utf8_lossy(prefix), suggestions, options)
}
}

View File

@ -26,13 +26,13 @@ impl Completer for DirectoryCompletion {
&mut self,
working_set: &StateWorkingSet,
stack: &Stack,
prefix: Vec<u8>,
prefix: &[u8],
span: Span,
offset: usize,
_pos: usize,
options: &CompletionOptions,
) -> Vec<SemanticSuggestion> {
let AdjustView { prefix, span, .. } = adjust_if_intermediate(&prefix, working_set, span);
let AdjustView { prefix, span, .. } = adjust_if_intermediate(prefix, working_set, span);
// Filter only the folders
#[allow(deprecated)]

View File

@ -22,13 +22,13 @@ impl Completer for DotNuCompletion {
&mut self,
working_set: &StateWorkingSet,
stack: &Stack,
prefix: Vec<u8>,
prefix: &[u8],
span: Span,
offset: usize,
_pos: usize,
options: &CompletionOptions,
) -> Vec<SemanticSuggestion> {
let prefix_str = String::from_utf8_lossy(&prefix).replace('`', "");
let prefix_str = String::from_utf8_lossy(prefix).replace('`', "");
let mut search_dirs: Vec<String> = vec![];
// If prefix_str is only a word we want to search in the current dir

View File

@ -27,7 +27,7 @@ impl Completer for FileCompletion {
&mut self,
working_set: &StateWorkingSet,
stack: &Stack,
prefix: Vec<u8>,
prefix: &[u8],
span: Span,
offset: usize,
_pos: usize,
@ -37,7 +37,7 @@ impl Completer for FileCompletion {
prefix,
span,
readjusted,
} = adjust_if_intermediate(&prefix, working_set, span);
} = adjust_if_intermediate(prefix, working_set, span);
#[allow(deprecated)]
let items: Vec<_> = complete_item(

View File

@ -24,7 +24,7 @@ impl Completer for FlagCompletion {
&mut self,
working_set: &StateWorkingSet,
_stack: &Stack,
prefix: Vec<u8>,
prefix: &[u8],
span: Span,
offset: usize,
_pos: usize,
@ -44,7 +44,7 @@ impl Completer for FlagCompletion {
short.encode_utf8(&mut named);
named.insert(0, b'-');
if options.match_algorithm.matches_u8(&named, &prefix) {
if options.match_algorithm.matches_u8(&named, prefix) {
output.push(SemanticSuggestion {
suggestion: Suggestion {
value: String::from_utf8_lossy(&named).to_string(),
@ -70,7 +70,7 @@ impl Completer for FlagCompletion {
named.insert(0, b'-');
named.insert(0, b'-');
if options.match_algorithm.matches_u8(&named, &prefix) {
if options.match_algorithm.matches_u8(&named, prefix) {
output.push(SemanticSuggestion {
suggestion: Suggestion {
value: String::from_utf8_lossy(&named).to_string(),
@ -88,7 +88,7 @@ impl Completer for FlagCompletion {
}
}
return sort_suggestions(&String::from_utf8_lossy(&prefix), output, options);
return sort_suggestions(&String::from_utf8_lossy(prefix), output, options);
}
vec![]

View File

@ -8,6 +8,7 @@ mod directory_completions;
mod dotnu_completions;
mod file_completions;
mod flag_completions;
mod operator_completions;
mod variable_completions;
pub use base::{Completer, SemanticSuggestion, SuggestionKind};
@ -19,4 +20,5 @@ pub use directory_completions::DirectoryCompletion;
pub use dotnu_completions::DotNuCompletion;
pub use file_completions::{file_path_completion, matches, FileCompletion};
pub use flag_completions::FlagCompletion;
pub use operator_completions::OperatorCompletion;
pub use variable_completions::VariableCompletion;

View File

@ -0,0 +1,180 @@
use crate::completions::{
Completer, CompletionOptions, MatchAlgorithm, SemanticSuggestion, SuggestionKind,
};
use nu_protocol::{
ast::{Expr, Expression},
engine::{Stack, StateWorkingSet},
Span, Type,
};
use reedline::Suggestion;
#[derive(Clone)]
pub struct OperatorCompletion {
previous_expr: Expression,
}
impl OperatorCompletion {
pub fn new(previous_expr: Expression) -> Self {
OperatorCompletion { previous_expr }
}
}
impl Completer for OperatorCompletion {
fn fetch(
&mut self,
working_set: &StateWorkingSet,
_stack: &Stack,
_prefix: &[u8],
span: Span,
offset: usize,
_pos: usize,
_options: &CompletionOptions,
) -> Vec<SemanticSuggestion> {
//Check if int, float, or string
let partial = std::str::from_utf8(working_set.get_span_contents(span)).unwrap_or("");
let op = match &self.previous_expr.expr {
Expr::BinaryOp(x, _, _) => &x.expr,
_ => {
return vec![];
}
};
let possible_operations = match op {
Expr::Int(_) => vec![
("+", "Add (Plus)"),
("-", "Subtract (Minus)"),
("*", "Multiply"),
("/", "Divide"),
("==", "Equal to"),
("!=", "Not equal to"),
("//", "Floor division"),
("<", "Less than"),
(">", "Greater than"),
("<=", "Less than or equal to"),
(">=", "Greater than or equal to"),
("mod", "Floor division remainder (Modulo)"),
("**", "Power of"),
("bit-or", "Bitwise OR"),
("bit-xor", "Bitwise exclusive OR"),
("bit-and", "Bitwise AND"),
("bit-shl", "Bitwise shift left"),
("bit-shr", "Bitwise shift right"),
("in", "Is a member of (doesn't use regex)"),
("not-in", "Is not a member of (doesn't use regex)"),
(
"++",
"Appends two lists, a list and a value, two strings, or two binary values",
),
],
Expr::String(_) => vec![
("=~", "Contains regex match"),
("!~", "Does not contain regex match"),
(
"++",
"Appends two lists, a list and a value, two strings, or two binary values",
),
("in", "Is a member of (doesn't use regex)"),
("not-in", "Is not a member of (doesn't use regex)"),
("starts-with", "Starts with"),
("ends-with", "Ends with"),
],
Expr::Float(_) => vec![
("+", "Add (Plus)"),
("-", "Subtract (Minus)"),
("*", "Multiply"),
("/", "Divide"),
("==", "Equal to"),
("!=", "Not equal to"),
("//", "Floor division"),
("<", "Less than"),
(">", "Greater than"),
("<=", "Less than or equal to"),
(">=", "Greater than or equal to"),
("mod", "Floor division remainder (Modulo)"),
("**", "Power of"),
("in", "Is a member of (doesn't use regex)"),
("not-in", "Is not a member of (doesn't use regex)"),
(
"++",
"Appends two lists, a list and a value, two strings, or two binary values",
),
],
Expr::Bool(_) => vec![
(
"and",
"Both values are true (short-circuits when first value is false)",
),
(
"or",
"Either value is true (short-circuits when first value is true)",
),
("xor", "One value is true and the other is false"),
("not", "Negates a value or expression"),
("in", "Is a member of (doesn't use regex)"),
("not-in", "Is not a member of (doesn't use regex)"),
(
"++",
"Appends two lists, a list and a value, two strings, or two binary values",
),
],
Expr::FullCellPath(path) => match path.head.expr {
Expr::List(_) => vec![(
"++",
"Appends two lists, a list and a value, two strings, or two binary values",
)],
Expr::Var(id) => get_variable_completions(id, working_set),
_ => vec![],
},
_ => vec![],
};
let match_algorithm = MatchAlgorithm::Prefix;
let input_fuzzy_search =
|(operator, _): &(&str, &str)| match_algorithm.matches_str(operator, partial);
possible_operations
.into_iter()
.filter(input_fuzzy_search)
.map(move |x| SemanticSuggestion {
suggestion: Suggestion {
value: x.0.to_string(),
description: Some(x.1.to_string()),
span: reedline::Span::new(span.start - offset, span.end - offset),
append_whitespace: true,
..Suggestion::default()
},
kind: Some(SuggestionKind::Command(
nu_protocol::engine::CommandType::Builtin,
)),
})
.collect()
}
}
pub fn get_variable_completions<'a>(
id: nu_protocol::Id<nu_protocol::marker::Var>,
working_set: &StateWorkingSet,
) -> Vec<(&'a str, &'a str)> {
let var = working_set.get_variable(id);
if !var.mutable {
return vec![];
}
match var.ty {
Type::List(_) | Type::String | Type::Binary => vec![
(
"++=",
"Appends a list, a value, a string, or a binary value to a variable.",
),
("=", "Assigns a value to a variable."),
],
Type::Int | Type::Float => vec![
("=", "Assigns a value to a variable."),
("+=", "Adds a value to a variable."),
("-=", "Subtracts a value from a variable."),
("*=", "Multiplies a variable by a value"),
("/=", "Divides a variable by a value."),
],
_ => vec![],
}
}

View File

@ -27,7 +27,7 @@ impl Completer for VariableCompletion {
&mut self,
working_set: &StateWorkingSet,
stack: &Stack,
prefix: Vec<u8>,
prefix: &[u8],
span: Span,
offset: usize,
_pos: usize,
@ -42,7 +42,7 @@ impl Completer for VariableCompletion {
end: span.end - offset,
};
let sublevels_count = self.var_context.1.len();
let prefix_str = String::from_utf8_lossy(&prefix);
let prefix_str = String::from_utf8_lossy(prefix);
// Completions for the given variable
if !var_str.is_empty() {
@ -66,7 +66,7 @@ impl Completer for VariableCompletion {
if options.match_algorithm.matches_u8_insensitive(
options.case_sensitive,
suggestion.suggestion.value.as_bytes(),
&prefix,
prefix,
) {
output.push(suggestion);
}
@ -80,7 +80,7 @@ impl Completer for VariableCompletion {
if options.match_algorithm.matches_u8_insensitive(
options.case_sensitive,
env_var.0.as_bytes(),
&prefix,
prefix,
) {
output.push(SemanticSuggestion {
suggestion: Suggestion {
@ -111,7 +111,7 @@ impl Completer for VariableCompletion {
if options.match_algorithm.matches_u8_insensitive(
options.case_sensitive,
suggestion.suggestion.value.as_bytes(),
&prefix,
prefix,
) {
output.push(suggestion);
}
@ -133,7 +133,7 @@ impl Completer for VariableCompletion {
if options.match_algorithm.matches_u8_insensitive(
options.case_sensitive,
suggestion.suggestion.value.as_bytes(),
&prefix,
prefix,
) {
output.push(suggestion);
}
@ -149,7 +149,7 @@ impl Completer for VariableCompletion {
if options.match_algorithm.matches_u8_insensitive(
options.case_sensitive,
builtin.as_bytes(),
&prefix,
prefix,
) {
output.push(SemanticSuggestion {
suggestion: Suggestion {
@ -173,7 +173,7 @@ impl Completer for VariableCompletion {
if options.match_algorithm.matches_u8_insensitive(
options.case_sensitive,
v.0,
&prefix,
prefix,
) {
output.push(SemanticSuggestion {
suggestion: Suggestion {
@ -201,7 +201,7 @@ impl Completer for VariableCompletion {
if options.match_algorithm.matches_u8_insensitive(
options.case_sensitive,
v.0,
&prefix,
prefix,
) {
output.push(SemanticSuggestion {
suggestion: Suggestion {

View File

@ -5,7 +5,7 @@ use nu_path::canonicalize_with;
use nu_protocol::{engine::StateWorkingSet, ParseError, PluginRegistryFile, Spanned};
use nu_protocol::{
engine::{EngineState, Stack},
report_shell_error, HistoryFileFormat, PipelineData,
report_shell_error, PipelineData,
};
#[cfg(feature = "plugin")]
use nu_utils::perf;
@ -16,15 +16,8 @@ const PLUGIN_FILE: &str = "plugin.msgpackz";
#[cfg(feature = "plugin")]
const OLD_PLUGIN_FILE: &str = "plugin.nu";
const HISTORY_FILE_TXT: &str = "history.txt";
const HISTORY_FILE_SQLITE: &str = "history.sqlite3";
#[cfg(feature = "plugin")]
pub fn read_plugin_file(
engine_state: &mut EngineState,
plugin_file: Option<Spanned<String>>,
storage_path: &str,
) {
pub fn read_plugin_file(engine_state: &mut EngineState, plugin_file: Option<Spanned<String>>) {
use nu_protocol::ShellError;
use std::path::Path;
@ -52,7 +45,7 @@ pub fn read_plugin_file(
let mut start_time = std::time::Instant::now();
// Reading signatures from plugin registry file
// The plugin.msgpackz file stores the parsed signature collected from each registered plugin
add_plugin_file(engine_state, plugin_file.clone(), storage_path);
add_plugin_file(engine_state, plugin_file.clone());
perf!(
"add plugin file to engine_state",
start_time,
@ -70,8 +63,7 @@ pub fn read_plugin_file(
log::warn!("Plugin file not found: {}", plugin_path.display());
// Try migration of an old plugin file if this wasn't a custom plugin file
if plugin_file.is_none() && migrate_old_plugin_file(engine_state, storage_path)
{
if plugin_file.is_none() && migrate_old_plugin_file(engine_state) {
let Ok(file) = std::fs::File::open(&plugin_path) else {
log::warn!("Failed to load newly migrated plugin file");
return;
@ -159,11 +151,7 @@ pub fn read_plugin_file(
}
#[cfg(feature = "plugin")]
pub fn add_plugin_file(
engine_state: &mut EngineState,
plugin_file: Option<Spanned<String>>,
storage_path: &str,
) {
pub fn add_plugin_file(engine_state: &mut EngineState, plugin_file: Option<Spanned<String>>) {
use std::path::Path;
use nu_protocol::report_parse_error;
@ -189,9 +177,8 @@ pub fn add_plugin_file(
),
);
}
} else if let Some(mut plugin_path) = nu_path::config_dir() {
} else if let Some(plugin_path) = nu_path::nu_config_dir() {
// Path to store plugins signatures
plugin_path.push(storage_path);
let mut plugin_path =
canonicalize_with(&plugin_path, &cwd).unwrap_or(plugin_path.into());
plugin_path.push(PLUGIN_FILE);
@ -228,33 +215,15 @@ pub fn eval_config_contents(
engine_state.file = prev_file;
// Merge the environment in case env vars changed in the config
match engine_state.cwd(Some(stack)) {
Ok(cwd) => {
if let Err(e) = engine_state.merge_env(stack, cwd) {
report_shell_error(engine_state, &e);
}
}
Err(e) => {
report_shell_error(engine_state, &e);
}
if let Err(e) = engine_state.merge_env(stack) {
report_shell_error(engine_state, &e);
}
}
}
}
pub(crate) fn get_history_path(storage_path: &str, mode: HistoryFileFormat) -> Option<PathBuf> {
nu_path::config_dir().map(|mut history_path| {
history_path.push(storage_path);
history_path.push(match mode {
HistoryFileFormat::Plaintext => HISTORY_FILE_TXT,
HistoryFileFormat::Sqlite => HISTORY_FILE_SQLITE,
});
history_path.into()
})
}
#[cfg(feature = "plugin")]
pub fn migrate_old_plugin_file(engine_state: &EngineState, storage_path: &str) -> bool {
pub fn migrate_old_plugin_file(engine_state: &EngineState) -> bool {
use nu_protocol::{
PluginExample, PluginIdentity, PluginRegistryItem, PluginRegistryItemData, PluginSignature,
ShellError,
@ -267,10 +236,9 @@ pub fn migrate_old_plugin_file(engine_state: &EngineState, storage_path: &str) -
return false;
};
let Some(config_dir) = nu_path::config_dir().and_then(|mut dir| {
dir.push(storage_path);
nu_path::canonicalize_with(dir, &cwd).ok()
}) else {
let Some(config_dir) =
nu_path::nu_config_dir().and_then(|dir| nu_path::canonicalize_with(dir, &cwd).ok())
else {
return false;
};

View File

@ -21,7 +21,6 @@ pub use config_files::eval_config_contents;
pub use eval_cmds::{evaluate_commands, EvaluateCommandsOpts};
pub use eval_file::evaluate_file;
pub use menus::NuHelpCompleter;
pub use nu_cmd_base::util::get_init_cwd;
pub use nu_highlight::NuHighlight;
pub use print::Print;
pub use prompt::NushellPrompt;

View File

@ -2,7 +2,7 @@ use nu_engine::eval_block;
use nu_protocol::{
debugger::WithoutDebug,
engine::{EngineState, Stack},
IntoPipelineData, Span, Value,
BlockId, IntoPipelineData, Span, Value,
};
use reedline::{menu_functions::parse_selection_char, Completer, Suggestion};
use std::sync::Arc;
@ -10,7 +10,7 @@ use std::sync::Arc;
const SELECTION_CHAR: char = '!';
pub struct NuMenuCompleter {
block_id: usize,
block_id: BlockId,
span: Span,
stack: Stack,
engine_state: Arc<EngineState>,
@ -19,7 +19,7 @@ pub struct NuMenuCompleter {
impl NuMenuCompleter {
pub fn new(
block_id: usize,
block_id: BlockId,
span: Span,
stack: Stack,
engine_state: Arc<EngineState>,
@ -28,7 +28,7 @@ impl NuMenuCompleter {
Self {
block_id,
span,
stack: stack.reset_out_dest().capture(),
stack: stack.reset_out_dest().collect_value(),
engine_state,
only_buffer_difference,
}

View File

@ -1,4 +1,5 @@
use nu_engine::command_prelude::*;
use nu_protocol::ByteStreamSource;
#[derive(Clone)]
pub struct Print;
@ -50,7 +51,7 @@ Since this command has no output, there is no point in piping it with other comm
engine_state: &EngineState,
stack: &mut Stack,
call: &Call,
input: PipelineData,
mut input: PipelineData,
) -> Result<PipelineData, ShellError> {
let args: Vec<Value> = call.rest(engine_state, stack, 0)?;
let no_newline = call.has_flag(engine_state, stack, "no-newline")?;
@ -69,6 +70,11 @@ Since this command has no output, there is no point in piping it with other comm
}
}
} else if !input.is_nothing() {
if let PipelineData::ByteStream(stream, _) = &mut input {
if let ByteStreamSource::Child(child) = stream.source_mut() {
child.ignore_error(true);
}
}
if raw {
input.print_raw(engine_state, no_newline, to_stderr)?;
} else {

View File

@ -1,10 +1,7 @@
use crate::prompt_update::{
POST_PROMPT_MARKER, PRE_PROMPT_MARKER, VSCODE_POST_PROMPT_MARKER, VSCODE_PRE_PROMPT_MARKER,
};
use nu_protocol::{
engine::{EngineState, Stack},
Value,
};
use nu_protocol::engine::{EngineState, Stack};
#[cfg(windows)]
use nu_utils::enable_vt_processing;
use reedline::{
@ -124,8 +121,11 @@ impl Prompt for NushellPrompt {
.replace('\n', "\r\n");
if self.shell_integration_osc633 {
if self.stack.get_env_var(&self.engine_state, "TERM_PROGRAM")
== Some(Value::test_string("vscode"))
if self
.stack
.get_env_var(&self.engine_state, "TERM_PROGRAM")
.and_then(|v| v.as_str().ok())
== Some("vscode")
{
// We're in vscode and we have osc633 enabled
format!("{VSCODE_PRE_PROMPT_MARKER}{prompt}{VSCODE_POST_PROMPT_MARKER}").into()

View File

@ -68,7 +68,7 @@ fn get_prompt_string(
.get_env_var(engine_state, prompt)
.and_then(|v| match v {
Value::Closure { val, .. } => {
let result = ClosureEvalOnce::new(engine_state, stack, *val)
let result = ClosureEvalOnce::new(engine_state, stack, val.as_ref().clone())
.run_with_input(PipelineData::Empty);
trace!(
@ -119,7 +119,11 @@ pub(crate) fn update_prompt(
// Now that we have the prompt string lets ansify it.
// <133 A><prompt><133 B><command><133 C><command output>
let left_prompt_string = if config.shell_integration.osc633 {
if stack.get_env_var(engine_state, "TERM_PROGRAM") == Some(Value::test_string("vscode")) {
if stack
.get_env_var(engine_state, "TERM_PROGRAM")
.and_then(|v| v.as_str().ok())
== Some("vscode")
{
// We're in vscode and we have osc633 enabled
Some(format!(
"{VSCODE_PRE_PROMPT_MARKER}{configured_left_prompt_string}{VSCODE_POST_PROMPT_MARKER}"

View File

@ -5,11 +5,10 @@ use nu_color_config::{color_record_to_nustyle, lookup_ansi_color_style};
use nu_engine::eval_block;
use nu_parser::parse;
use nu_protocol::{
create_menus,
debugger::WithoutDebug,
engine::{EngineState, Stack, StateWorkingSet},
extract_value, Config, EditBindings, ParsedKeybinding, ParsedMenu, PipelineData, Record,
ShellError, Span, Value,
extract_value, Config, EditBindings, FromValue, ParsedKeybinding, ParsedMenu, PipelineData,
Record, ShellError, Span, Type, Value,
};
use reedline::{
default_emacs_keybindings, default_vi_insert_keybindings, default_vi_normal_keybindings,
@ -36,6 +35,41 @@ const DEFAULT_COMPLETION_MENU: &str = r#"
}
}"#;
const DEFAULT_IDE_COMPLETION_MENU: &str = r#"
{
name: ide_completion_menu
only_buffer_difference: false
marker: "| "
type: {
layout: ide
min_completion_width: 0,
max_completion_width: 50,
max_completion_height: 10, # will be limited by the available lines in the terminal
padding: 0,
border: true,
cursor_offset: 0,
description_mode: "prefer_right"
min_description_width: 0
max_description_width: 50
max_description_height: 10
description_offset: 1
# If true, the cursor pos will be corrected, so the suggestions match up with the typed text
#
# C:\> str
# str join
# str trim
# str split
correct_cursor_pos: false
}
style: {
text: green
selected_text: { attr: r }
description_text: yellow
match_text: { attr: u }
selected_match_text: { attr: ur }
}
}"#;
const DEFAULT_HISTORY_MENU: &str = r#"
{
name: history_menu
@ -95,6 +129,7 @@ pub(crate) fn add_menus(
// Checking if the default menus have been added from the config file
let default_menus = [
("completion_menu", DEFAULT_COMPLETION_MENU),
("ide_completion_menu", DEFAULT_IDE_COMPLETION_MENU),
("history_menu", DEFAULT_HISTORY_MENU),
("help_menu", DEFAULT_HELP_MENU),
];
@ -122,7 +157,7 @@ pub(crate) fn add_menus(
engine_state.merge_delta(delta)?;
let mut temp_stack = Stack::new().capture();
let mut temp_stack = Stack::new().collect_value();
let input = PipelineData::Empty;
menu_eval_results.push(eval_block::<WithoutDebug>(
&engine_state,
@ -137,15 +172,13 @@ pub(crate) fn add_menus(
for res in menu_eval_results.into_iter() {
if let PipelineData::Value(value, None) = res {
for menu in create_menus(&value)? {
line_editor = add_menu(
line_editor,
&menu,
new_engine_state_ref.clone(),
stack,
config.clone(),
)?;
}
line_editor = add_menu(
line_editor,
&ParsedMenu::from_value(value)?,
new_engine_state_ref.clone(),
stack,
config.clone(),
)?;
}
}
@ -168,22 +201,22 @@ fn add_menu(
"list" => add_list_menu(line_editor, menu, engine_state, stack, config),
"ide" => add_ide_menu(line_editor, menu, engine_state, stack, config),
"description" => add_description_menu(line_editor, menu, engine_state, stack, config),
_ => Err(ShellError::UnsupportedConfigValue {
expected: "columnar, list, ide or description".to_string(),
value: menu.r#type.to_abbreviated_string(&config),
span: menu.r#type.span(),
str => Err(ShellError::InvalidValue {
valid: "'columnar', 'list', 'ide', or 'description'".into(),
actual: format!("'{str}'"),
span,
}),
}
} else {
Err(ShellError::UnsupportedConfigValue {
expected: "only record type".to_string(),
value: menu.r#type.to_abbreviated_string(&config),
span: menu.r#type.span(),
Err(ShellError::RuntimeTypeMismatch {
expected: Type::record(),
actual: menu.r#type.get_type(),
span,
})
}
}
fn get_style(record: &Record, name: &str, span: Span) -> Option<Style> {
fn get_style(record: &Record, name: &'static str, span: Span) -> Option<Style> {
extract_value(name, record, span)
.ok()
.map(|text| match text {
@ -262,30 +295,23 @@ pub(crate) fn add_columnar_menu(
let only_buffer_difference = menu.only_buffer_difference.as_bool()?;
columnar_menu = columnar_menu.with_only_buffer_difference(only_buffer_difference);
let span = menu.source.span();
match &menu.source {
Value::Nothing { .. } => {
Ok(line_editor.with_menu(ReedlineMenu::EngineCompleter(Box::new(columnar_menu))))
}
Value::Closure { val, .. } => {
let menu_completer = NuMenuCompleter::new(
val.block_id,
span,
stack.captures_to_stack(val.captures.clone()),
engine_state,
only_buffer_difference,
);
Ok(line_editor.with_menu(ReedlineMenu::WithCompleter {
menu: Box::new(columnar_menu),
completer: Box::new(menu_completer),
}))
}
_ => Err(ShellError::UnsupportedConfigValue {
expected: "block or omitted value".to_string(),
value: menu.source.to_abbreviated_string(config),
let completer = if let Some(closure) = &menu.source {
let menu_completer = NuMenuCompleter::new(
closure.block_id,
span,
}),
}
stack.captures_to_stack(closure.captures.clone()),
engine_state,
only_buffer_difference,
);
ReedlineMenu::WithCompleter {
menu: Box::new(columnar_menu),
completer: Box::new(menu_completer),
}
} else {
ReedlineMenu::EngineCompleter(Box::new(columnar_menu))
};
Ok(line_editor.with_menu(completer))
}
// Adds a search menu to the line editor
@ -318,30 +344,23 @@ pub(crate) fn add_list_menu(
let only_buffer_difference = menu.only_buffer_difference.as_bool()?;
list_menu = list_menu.with_only_buffer_difference(only_buffer_difference);
let span = menu.source.span();
match &menu.source {
Value::Nothing { .. } => {
Ok(line_editor.with_menu(ReedlineMenu::HistoryMenu(Box::new(list_menu))))
let completer = if let Some(closure) = &menu.source {
let menu_completer = NuMenuCompleter::new(
closure.block_id,
span,
stack.captures_to_stack(closure.captures.clone()),
engine_state,
only_buffer_difference,
);
ReedlineMenu::WithCompleter {
menu: Box::new(list_menu),
completer: Box::new(menu_completer),
}
Value::Closure { val, .. } => {
let menu_completer = NuMenuCompleter::new(
val.block_id,
span,
stack.captures_to_stack(val.captures.clone()),
engine_state,
only_buffer_difference,
);
Ok(line_editor.with_menu(ReedlineMenu::WithCompleter {
menu: Box::new(list_menu),
completer: Box::new(menu_completer),
}))
}
_ => Err(ShellError::UnsupportedConfigValue {
expected: "block or omitted value".to_string(),
value: menu.source.to_abbreviated_string(&config),
span: menu.source.span(),
}),
}
} else {
ReedlineMenu::HistoryMenu(Box::new(list_menu))
};
Ok(line_editor.with_menu(completer))
}
// Adds an IDE menu to the line editor
@ -416,9 +435,9 @@ pub(crate) fn add_ide_menu(
vertical,
)
} else {
return Err(ShellError::UnsupportedConfigValue {
expected: "bool or record".to_string(),
value: border.to_abbreviated_string(&config),
return Err(ShellError::RuntimeTypeMismatch {
expected: Type::custom("bool or record"),
actual: border.get_type(),
span: border.span(),
});
}
@ -439,10 +458,10 @@ pub(crate) fn add_ide_menu(
"left" => ide_menu.with_description_mode(DescriptionMode::Left),
"right" => ide_menu.with_description_mode(DescriptionMode::Right),
"prefer_right" => ide_menu.with_description_mode(DescriptionMode::PreferRight),
_ => {
return Err(ShellError::UnsupportedConfigValue {
expected: "\"left\", \"right\" or \"prefer_right\"".to_string(),
value: description_mode.to_abbreviated_string(&config),
str => {
return Err(ShellError::InvalidValue {
valid: "'left', 'right', or 'prefer_right'".into(),
actual: format!("'{str}'"),
span: description_mode.span(),
});
}
@ -499,30 +518,23 @@ pub(crate) fn add_ide_menu(
let only_buffer_difference = menu.only_buffer_difference.as_bool()?;
ide_menu = ide_menu.with_only_buffer_difference(only_buffer_difference);
let span = menu.source.span();
match &menu.source {
Value::Nothing { .. } => {
Ok(line_editor.with_menu(ReedlineMenu::EngineCompleter(Box::new(ide_menu))))
}
Value::Closure { val, .. } => {
let menu_completer = NuMenuCompleter::new(
val.block_id,
span,
stack.captures_to_stack(val.captures.clone()),
engine_state,
only_buffer_difference,
);
Ok(line_editor.with_menu(ReedlineMenu::WithCompleter {
menu: Box::new(ide_menu),
completer: Box::new(menu_completer),
}))
}
_ => Err(ShellError::UnsupportedConfigValue {
expected: "block or omitted value".to_string(),
value: menu.source.to_abbreviated_string(&config),
let completer = if let Some(closure) = &menu.source {
let menu_completer = NuMenuCompleter::new(
closure.block_id,
span,
}),
}
stack.captures_to_stack(closure.captures.clone()),
engine_state,
only_buffer_difference,
);
ReedlineMenu::WithCompleter {
menu: Box::new(ide_menu),
completer: Box::new(menu_completer),
}
} else {
ReedlineMenu::EngineCompleter(Box::new(ide_menu))
};
Ok(line_editor.with_menu(completer))
}
// Adds a description menu to the line editor
@ -587,34 +599,27 @@ pub(crate) fn add_description_menu(
let only_buffer_difference = menu.only_buffer_difference.as_bool()?;
description_menu = description_menu.with_only_buffer_difference(only_buffer_difference);
let span = menu.source.span();
match &menu.source {
Value::Nothing { .. } => {
let completer = Box::new(NuHelpCompleter::new(engine_state, config));
Ok(line_editor.with_menu(ReedlineMenu::WithCompleter {
menu: Box::new(description_menu),
completer,
}))
let completer = if let Some(closure) = &menu.source {
let menu_completer = NuMenuCompleter::new(
closure.block_id,
span,
stack.captures_to_stack(closure.captures.clone()),
engine_state,
only_buffer_difference,
);
ReedlineMenu::WithCompleter {
menu: Box::new(description_menu),
completer: Box::new(menu_completer),
}
Value::Closure { val, .. } => {
let menu_completer = NuMenuCompleter::new(
val.block_id,
span,
stack.captures_to_stack(val.captures.clone()),
engine_state,
only_buffer_difference,
);
Ok(line_editor.with_menu(ReedlineMenu::WithCompleter {
menu: Box::new(description_menu),
completer: Box::new(menu_completer),
}))
} else {
let menu_completer = NuHelpCompleter::new(engine_state, config);
ReedlineMenu::WithCompleter {
menu: Box::new(description_menu),
completer: Box::new(menu_completer),
}
_ => Err(ShellError::UnsupportedConfigValue {
expected: "closure or omitted value".to_string(),
value: menu.source.to_abbreviated_string(&config),
span: menu.source.span(),
}),
}
};
Ok(line_editor.with_menu(completer))
}
fn add_menu_keybindings(keybindings: &mut Keybindings) {
@ -629,6 +634,16 @@ fn add_menu_keybindings(keybindings: &mut Keybindings) {
]),
);
keybindings.add_binding(
KeyModifiers::CONTROL,
KeyCode::Char(' '),
ReedlineEvent::UntilFound(vec![
ReedlineEvent::Menu("ide_completion_menu".to_string()),
ReedlineEvent::MenuNext,
ReedlineEvent::Edit(vec![EditCommand::Complete]),
]),
);
keybindings.add_binding(
KeyModifiers::SHIFT,
KeyCode::BackTab,
@ -728,9 +743,9 @@ fn add_keybinding(
"emacs" => add_parsed_keybinding(emacs_keybindings, keybinding, config),
"vi_insert" => add_parsed_keybinding(insert_keybindings, keybinding, config),
"vi_normal" => add_parsed_keybinding(normal_keybindings, keybinding, config),
m => Err(ShellError::UnsupportedConfigValue {
expected: "emacs, vi_insert or vi_normal".to_string(),
value: m.to_string(),
str => Err(ShellError::InvalidValue {
valid: "'emacs', 'vi_insert', or 'vi_normal'".into(),
actual: format!("'{str}'"),
span,
}),
},
@ -748,9 +763,9 @@ fn add_keybinding(
Ok(())
}
v => Err(ShellError::UnsupportedConfigValue {
expected: "string or list of strings".to_string(),
value: v.to_abbreviated_string(config),
v => Err(ShellError::RuntimeTypeMismatch {
expected: Type::custom("string or list<string>"),
actual: v.get_type(),
span: v.span(),
}),
}
@ -761,91 +776,107 @@ fn add_parsed_keybinding(
keybinding: &ParsedKeybinding,
config: &Config,
) -> Result<(), ShellError> {
let modifier = match keybinding
.modifier
.to_expanded_string("", config)
.to_ascii_lowercase()
.as_str()
{
"control" => KeyModifiers::CONTROL,
"shift" => KeyModifiers::SHIFT,
"alt" => KeyModifiers::ALT,
"none" => KeyModifiers::NONE,
"shift_alt" | "alt_shift" => KeyModifiers::SHIFT | KeyModifiers::ALT,
"control_shift" | "shift_control" => KeyModifiers::CONTROL | KeyModifiers::SHIFT,
"control_alt" | "alt_control" => KeyModifiers::CONTROL | KeyModifiers::ALT,
"control_alt_shift" | "control_shift_alt" => {
KeyModifiers::CONTROL | KeyModifiers::ALT | KeyModifiers::SHIFT
}
_ => {
return Err(ShellError::UnsupportedConfigValue {
expected: "CONTROL, SHIFT, ALT or NONE".to_string(),
value: keybinding.modifier.to_abbreviated_string(config),
span: keybinding.modifier.span(),
})
}
let Ok(modifier_str) = keybinding.modifier.as_str() else {
return Err(ShellError::RuntimeTypeMismatch {
expected: Type::String,
actual: keybinding.modifier.get_type(),
span: keybinding.modifier.span(),
});
};
let keycode = match keybinding
.keycode
.to_expanded_string("", config)
.to_ascii_lowercase()
.as_str()
{
"backspace" => KeyCode::Backspace,
"enter" => KeyCode::Enter,
c if c.starts_with("char_") => {
let mut char_iter = c.chars().skip(5);
let pos1 = char_iter.next();
let pos2 = char_iter.next();
let char = if let (Some(char), None) = (pos1, pos2) {
char
} else {
return Err(ShellError::UnsupportedConfigValue {
expected: "char_<CHAR: unicode codepoint>".to_string(),
value: c.to_string(),
span: keybinding.keycode.span(),
});
};
KeyCode::Char(char)
let mut modifier = KeyModifiers::NONE;
if !str::eq_ignore_ascii_case(modifier_str, "none") {
for part in modifier_str.split('_') {
match part.to_ascii_lowercase().as_str() {
"control" => modifier |= KeyModifiers::CONTROL,
"shift" => modifier |= KeyModifiers::SHIFT,
"alt" => modifier |= KeyModifiers::ALT,
"super" => modifier |= KeyModifiers::SUPER,
"hyper" => modifier |= KeyModifiers::HYPER,
"meta" => modifier |= KeyModifiers::META,
_ => {
return Err(ShellError::InvalidValue {
valid: "'control', 'shift', 'alt', 'super', 'hyper', 'meta', or 'none'"
.into(),
actual: format!("'{part}'"),
span: keybinding.modifier.span(),
});
}
}
}
"space" => KeyCode::Char(' '),
"down" => KeyCode::Down,
"up" => KeyCode::Up,
"left" => KeyCode::Left,
"right" => KeyCode::Right,
"home" => KeyCode::Home,
"end" => KeyCode::End,
"pageup" => KeyCode::PageUp,
"pagedown" => KeyCode::PageDown,
"tab" => KeyCode::Tab,
"backtab" => KeyCode::BackTab,
"delete" => KeyCode::Delete,
"insert" => KeyCode::Insert,
c if c.starts_with('f') => {
let fn_num: u8 = c[1..]
}
let Ok(keycode) = keybinding.keycode.as_str() else {
return Err(ShellError::RuntimeTypeMismatch {
expected: Type::String,
actual: keybinding.keycode.get_type(),
span: keybinding.keycode.span(),
});
};
let keycode_lower = keycode.to_ascii_lowercase();
let keycode = if let Some(rest) = keycode_lower.strip_prefix("char_") {
let error = |valid: &str, actual: &str| ShellError::InvalidValue {
valid: valid.into(),
actual: actual.into(),
span: keybinding.keycode.span(),
};
let mut char_iter = rest.chars();
let char = match (char_iter.next(), char_iter.next()) {
(Some(char), None) => char,
(Some('u'), Some(_)) => {
// This will never panic as we know there are at least two symbols
let Ok(code_point) = u32::from_str_radix(&rest[1..], 16) else {
return Err(error("a valid hex code", keycode));
};
char::from_u32(code_point).ok_or(error("a valid Unicode code point", keycode))?
}
_ => return Err(error("'char_<char>' or 'char_u<hex code>'", keycode)),
};
KeyCode::Char(char)
} else {
match keycode_lower.as_str() {
"backspace" => KeyCode::Backspace,
"enter" => KeyCode::Enter,
"space" => KeyCode::Char(' '),
"down" => KeyCode::Down,
"up" => KeyCode::Up,
"left" => KeyCode::Left,
"right" => KeyCode::Right,
"home" => KeyCode::Home,
"end" => KeyCode::End,
"pageup" => KeyCode::PageUp,
"pagedown" => KeyCode::PageDown,
"tab" => KeyCode::Tab,
"backtab" => KeyCode::BackTab,
"delete" => KeyCode::Delete,
"insert" => KeyCode::Insert,
c if c.starts_with('f') => c[1..]
.parse()
.ok()
.filter(|num| matches!(num, 1..=20))
.ok_or(ShellError::UnsupportedConfigValue {
expected: "(f1|f2|...|f20)".to_string(),
value: format!("unknown function key: {c}"),
.filter(|num| (1..=20).contains(num))
.map(KeyCode::F)
.ok_or(ShellError::InvalidValue {
valid: "'f1', 'f2', ..., or 'f20'".into(),
actual: format!("'{keycode}'"),
span: keybinding.keycode.span(),
})?;
KeyCode::F(fn_num)
}
"null" => KeyCode::Null,
"esc" | "escape" => KeyCode::Esc,
_ => {
return Err(ShellError::UnsupportedConfigValue {
expected: "crossterm KeyCode".to_string(),
value: keybinding.keycode.to_abbreviated_string(config),
span: keybinding.keycode.span(),
})
})?,
"null" => KeyCode::Null,
"esc" | "escape" => KeyCode::Esc,
_ => {
return Err(ShellError::InvalidValue {
valid: "a crossterm KeyCode".into(),
actual: format!("'{keycode}'"),
span: keybinding.keycode.span(),
});
}
}
};
if let Some(event) = parse_event(&keybinding.event, config)? {
keybindings.add_binding(modifier, keycode, event);
} else {
@ -867,8 +898,8 @@ impl<'config> EventType<'config> {
.map(Self::Send)
.or_else(|_| extract_value("edit", record, span).map(Self::Edit))
.or_else(|_| extract_value("until", record, span).map(Self::Until))
.map_err(|_| ShellError::MissingConfigValue {
missing_value: "send, edit or until".to_string(),
.map_err(|_| ShellError::MissingRequiredColumn {
column: "'send', 'edit', or 'until'",
span,
})
}
@ -906,9 +937,9 @@ fn parse_event(value: &Value, config: &Config) -> Result<Option<ReedlineEvent>,
.iter()
.map(|value| match parse_event(value, config) {
Ok(inner) => match inner {
None => Err(ShellError::UnsupportedConfigValue {
expected: "List containing valid events".to_string(),
value: "Nothing value (null)".to_string(),
None => Err(ShellError::RuntimeTypeMismatch {
expected: Type::custom("record or table"),
actual: value.get_type(),
span: value.span(),
}),
Some(event) => Ok(event),
@ -919,9 +950,9 @@ fn parse_event(value: &Value, config: &Config) -> Result<Option<ReedlineEvent>,
Ok(Some(ReedlineEvent::UntilFound(events)))
}
v => Err(ShellError::UnsupportedConfigValue {
expected: "list of events".to_string(),
value: v.to_abbreviated_string(config),
v => Err(ShellError::RuntimeTypeMismatch {
expected: Type::list(Type::Any),
actual: v.get_type(),
span: v.span(),
}),
},
@ -931,9 +962,9 @@ fn parse_event(value: &Value, config: &Config) -> Result<Option<ReedlineEvent>,
.iter()
.map(|value| match parse_event(value, config) {
Ok(inner) => match inner {
None => Err(ShellError::UnsupportedConfigValue {
expected: "List containing valid events".to_string(),
value: "Nothing value (null)".to_string(),
None => Err(ShellError::RuntimeTypeMismatch {
expected: Type::custom("record or table"),
actual: value.get_type(),
span: value.span(),
}),
Some(event) => Ok(event),
@ -945,9 +976,9 @@ fn parse_event(value: &Value, config: &Config) -> Result<Option<ReedlineEvent>,
Ok(Some(ReedlineEvent::Multiple(events)))
}
Value::Nothing { .. } => Ok(None),
v => Err(ShellError::UnsupportedConfigValue {
expected: "record or list of records, null to unbind key".to_string(),
value: v.to_abbreviated_string(config),
v => Err(ShellError::RuntimeTypeMismatch {
expected: Type::custom("record, table, or nothing"),
actual: v.get_type(),
span: v.span(),
}),
}
@ -996,12 +1027,12 @@ fn event_from_record(
let cmd = extract_value("cmd", record, span)?;
ReedlineEvent::ExecuteHostCommand(cmd.to_expanded_string("", config))
}
v => {
return Err(ShellError::UnsupportedConfigValue {
expected: "Reedline event".to_string(),
value: v.to_string(),
str => {
return Err(ShellError::InvalidValue {
valid: "a reedline event".into(),
actual: format!("'{str}'"),
span,
})
});
}
};
@ -1094,7 +1125,7 @@ fn edit_from_record(
}
"insertchar" => {
let value = extract_value("value", record, span)?;
let char = extract_char(value, config)?;
let char = extract_char(value)?;
EditCommand::InsertChar(char)
}
"insertstring" => {
@ -1131,17 +1162,17 @@ fn edit_from_record(
"redo" => EditCommand::Redo,
"cutrightuntil" => {
let value = extract_value("value", record, span)?;
let char = extract_char(value, config)?;
let char = extract_char(value)?;
EditCommand::CutRightUntil(char)
}
"cutrightbefore" => {
let value = extract_value("value", record, span)?;
let char = extract_char(value, config)?;
let char = extract_char(value)?;
EditCommand::CutRightBefore(char)
}
"moverightuntil" => {
let value = extract_value("value", record, span)?;
let char = extract_char(value, config)?;
let char = extract_char(value)?;
let select = extract_value("select", record, span)
.and_then(|value| value.as_bool())
.unwrap_or(false);
@ -1149,7 +1180,7 @@ fn edit_from_record(
}
"moverightbefore" => {
let value = extract_value("value", record, span)?;
let char = extract_char(value, config)?;
let char = extract_char(value)?;
let select = extract_value("select", record, span)
.and_then(|value| value.as_bool())
.unwrap_or(false);
@ -1157,17 +1188,17 @@ fn edit_from_record(
}
"cutleftuntil" => {
let value = extract_value("value", record, span)?;
let char = extract_char(value, config)?;
let char = extract_char(value)?;
EditCommand::CutLeftUntil(char)
}
"cutleftbefore" => {
let value = extract_value("value", record, span)?;
let char = extract_char(value, config)?;
let char = extract_char(value)?;
EditCommand::CutLeftBefore(char)
}
"moveleftuntil" => {
let value = extract_value("value", record, span)?;
let char = extract_char(value, config)?;
let char = extract_char(value)?;
let select = extract_value("select", record, span)
.and_then(|value| value.as_bool())
.unwrap_or(false);
@ -1175,7 +1206,7 @@ fn edit_from_record(
}
"moveleftbefore" => {
let value = extract_value("value", record, span)?;
let char = extract_char(value, config)?;
let char = extract_char(value)?;
let select = extract_value("select", record, span)
.and_then(|value| value.as_bool())
.unwrap_or(false);
@ -1192,28 +1223,36 @@ fn edit_from_record(
#[cfg(feature = "system-clipboard")]
"pastesystem" => EditCommand::PasteSystem,
"selectall" => EditCommand::SelectAll,
e => {
return Err(ShellError::UnsupportedConfigValue {
expected: "reedline EditCommand".to_string(),
value: e.to_string(),
str => {
return Err(ShellError::InvalidValue {
valid: "a reedline EditCommand".into(),
actual: format!("'{str}'"),
span,
})
});
}
};
Ok(edit)
}
fn extract_char(value: &Value, config: &Config) -> Result<char, ShellError> {
let span = value.span();
value
.to_expanded_string("", config)
.chars()
.next()
.ok_or_else(|| ShellError::MissingConfigValue {
missing_value: "char to insert".to_string(),
span,
fn extract_char(value: &Value) -> Result<char, ShellError> {
if let Ok(str) = value.as_str() {
let mut chars = str.chars();
match (chars.next(), chars.next()) {
(Some(c), None) => Ok(c),
_ => Err(ShellError::InvalidValue {
valid: "a single character".into(),
actual: format!("'{str}'"),
span: value.span(),
}),
}
} else {
Err(ShellError::RuntimeTypeMismatch {
expected: Type::String,
actual: value.get_type(),
span: value.span(),
})
}
}
#[cfg(test)]
@ -1342,7 +1381,7 @@ mod test {
let span = Span::test_data();
let b = EventType::try_from_record(&event, span);
assert!(matches!(b, Err(ShellError::MissingConfigValue { .. })));
assert!(matches!(b, Err(ShellError::MissingRequiredColumn { .. })));
}
#[test]

View File

@ -16,10 +16,7 @@ use crate::{
use crossterm::cursor::SetCursorStyle;
use log::{error, trace, warn};
use miette::{ErrReport, IntoDiagnostic, Result};
use nu_cmd_base::{
hook::eval_hook,
util::{get_editor, get_guaranteed_cwd},
};
use nu_cmd_base::{hook::eval_hook, util::get_editor};
use nu_color_config::StyleComputer;
#[allow(deprecated)]
use nu_engine::{convert_env_values, current_dir_str, env_to_strings};
@ -53,7 +50,6 @@ use sysinfo::System;
pub fn evaluate_repl(
engine_state: &mut EngineState,
stack: Stack,
nushell_path: &str,
prerun_command: Option<Spanned<String>>,
load_std_lib: Option<Spanned<String>>,
entire_start_time: Instant,
@ -100,7 +96,7 @@ pub fn evaluate_repl(
unique_stack.set_last_exit_code(0, Span::unknown());
let mut line_editor = get_line_editor(engine_state, nushell_path, use_color)?;
let mut line_editor = get_line_editor(engine_state, use_color)?;
let temp_file = temp_dir().join(format!("{}.nu", uuid::Uuid::new_v4()));
if let Some(s) = prerun_command {
@ -112,8 +108,7 @@ pub fn evaluate_repl(
PipelineData::empty(),
false,
);
let cwd = get_guaranteed_cwd(engine_state, &unique_stack);
engine_state.merge_env(&mut unique_stack, cwd)?;
engine_state.merge_env(&mut unique_stack)?;
}
let hostname = System::host_name();
@ -135,16 +130,13 @@ pub fn evaluate_repl(
// escape a few things because this says so
// https://code.visualstudio.com/docs/terminal/shell-integration#_vs-code-custom-sequences-osc-633-st
let cmd_text = line_editor.current_buffer_contents().to_string();
let len = cmd_text.len();
let mut cmd_text_chars = cmd_text[0..len].chars();
let mut replaced_cmd_text = String::with_capacity(len);
let replaced_cmd_text = cmd_text
.chars()
.map(|c| match c {
'\n' => '\x0a',
'\r' => '\x0d',
'\x1b' => '\x1b',
_ => c,
})
.collect();
while let Some(c) = unescape_for_vscode(&mut cmd_text_chars) {
replaced_cmd_text.push(c);
}
run_shell_integration_osc633(
engine_state,
@ -163,7 +155,7 @@ pub fn evaluate_repl(
eval_source(
engine_state,
&mut unique_stack,
r#"use std banner; banner"#.as_bytes(),
r#"banner"#.as_bytes(),
"show_banner",
PipelineData::empty(),
false,
@ -220,7 +212,7 @@ pub fn evaluate_repl(
}
Err(_) => {
// line_editor is lost in the error case so reconstruct a new one
line_editor = get_line_editor(engine_state, nushell_path, use_color)?;
line_editor = get_line_editor(engine_state, use_color)?;
}
}
}
@ -228,11 +220,29 @@ pub fn evaluate_repl(
Ok(())
}
fn get_line_editor(
engine_state: &mut EngineState,
nushell_path: &str,
use_color: bool,
) -> Result<Reedline> {
fn unescape_for_vscode(text: &mut std::str::Chars) -> Option<char> {
match text.next() {
Some('\\') => match text.next() {
Some('0') => Some('\x00'), // NUL '\0' (null character)
Some('a') => Some('\x07'), // BEL '\a' (bell)
Some('b') => Some('\x08'), // BS '\b' (backspace)
Some('t') => Some('\x09'), // HT '\t' (horizontal tab)
Some('n') => Some('\x0a'), // LF '\n' (new line)
Some('v') => Some('\x0b'), // VT '\v' (vertical tab)
Some('f') => Some('\x0c'), // FF '\f' (form feed)
Some('r') => Some('\x0d'), // CR '\r' (carriage ret)
Some(';') => Some('\x3b'), // semi-colon
Some('\\') => Some('\x5c'), // backslash
Some('e') => Some('\x1b'), // escape
Some(c) => Some(c),
None => None,
},
Some(c) => Some(c),
None => None,
}
}
fn get_line_editor(engine_state: &mut EngineState, use_color: bool) -> Result<Reedline> {
let mut start_time = std::time::Instant::now();
let mut line_editor = Reedline::create();
@ -243,7 +253,7 @@ fn get_line_editor(
if let Some(history) = engine_state.history_config() {
start_time = std::time::Instant::now();
line_editor = setup_history(nushell_path, engine_state, line_editor, history)?;
line_editor = setup_history(engine_state, line_editor, history)?;
perf!("setup history", start_time, use_color);
}
@ -280,12 +290,10 @@ fn loop_iteration(ctx: LoopContext) -> (bool, Stack, Reedline) {
hostname,
} = ctx;
let cwd = get_guaranteed_cwd(engine_state, &stack);
let mut start_time = std::time::Instant::now();
// Before doing anything, merge the environment from the previous REPL iteration into the
// permanent state.
if let Err(err) = engine_state.merge_env(&mut stack, cwd) {
if let Err(err) = engine_state.merge_env(&mut stack) {
report_shell_error(engine_state, &err);
}
// Check whether $env.NU_DISABLE_IR is set, so that the user can change it in the REPL
@ -363,7 +371,11 @@ fn loop_iteration(ctx: LoopContext) -> (bool, Stack, Reedline) {
.to_string_lossy()
.to_string(),
))
.with_cursor_config(cursor_config);
.with_cursor_config(cursor_config)
.with_visual_selection_style(nu_ansi_term::Style {
is_reverse: true,
..Default::default()
});
perf!("reedline builder", start_time, use_color);
@ -518,8 +530,10 @@ fn loop_iteration(ctx: LoopContext) -> (bool, Stack, Reedline) {
drop(repl);
if shell_integration_osc633 {
if stack.get_env_var(engine_state, "TERM_PROGRAM")
== Some(Value::test_string("vscode"))
if stack
.get_env_var(engine_state, "TERM_PROGRAM")
.and_then(|v| v.as_str().ok())
== Some("vscode")
{
start_time = Instant::now();
@ -841,7 +855,7 @@ fn do_auto_cd(
let shells = stack.get_env_var(engine_state, "NUSHELL_SHELLS");
let mut shells = if let Some(v) = shells {
v.into_list().unwrap_or_else(|_| vec![cwd])
v.clone().into_list().unwrap_or_else(|_| vec![cwd])
} else {
vec![cwd]
};
@ -1033,7 +1047,11 @@ fn run_shell_integration_osc633(
if let Ok(path) = current_dir_str(engine_state, stack) {
// Supported escape sequences of Microsoft's Visual Studio Code (vscode)
// https://code.visualstudio.com/docs/terminal/shell-integration#_supported-escape-sequences
if stack.get_env_var(engine_state, "TERM_PROGRAM") == Some(Value::test_string("vscode")) {
if stack
.get_env_var(engine_state, "TERM_PROGRAM")
.and_then(|v| v.as_str().ok())
== Some("vscode")
{
let start_time = Instant::now();
// If we're in vscode, run their specific ansi escape sequence.
@ -1098,7 +1116,6 @@ fn flush_engine_state_repl_buffer(engine_state: &mut EngineState, line_editor: &
/// Setup history management for Reedline
///
fn setup_history(
nushell_path: &str,
engine_state: &mut EngineState,
line_editor: Reedline,
history: HistoryConfig,
@ -1110,7 +1127,7 @@ fn setup_history(
None
};
if let Some(path) = crate::config_files::get_history_path(nushell_path, history.file_format) {
if let Some(path) = history.file_path() {
return update_line_editor_history(
engine_state,
path,
@ -1231,7 +1248,11 @@ fn get_command_finished_marker(
.and_then(|e| e.as_i64().ok());
if shell_integration_osc633 {
if stack.get_env_var(engine_state, "TERM_PROGRAM") == Some(Value::test_string("vscode")) {
if stack
.get_env_var(engine_state, "TERM_PROGRAM")
.and_then(|v| v.as_str().ok())
== Some("vscode")
{
// We're in vscode and we have osc633 enabled
format!(
"{}{}{}",
@ -1280,7 +1301,11 @@ fn run_finaliziation_ansi_sequence(
) {
if shell_integration_osc633 {
// Only run osc633 if we are in vscode
if stack.get_env_var(engine_state, "TERM_PROGRAM") == Some(Value::test_string("vscode")) {
if stack
.get_env_var(engine_state, "TERM_PROGRAM")
.and_then(|v| v.as_str().ok())
== Some("vscode")
{
let start_time = Instant::now();
run_ansi_sequence(&get_command_finished_marker(
@ -1378,8 +1403,7 @@ fn trailing_slash_looks_like_path() {
fn are_session_ids_in_sync() {
let engine_state = &mut EngineState::new();
let history = engine_state.history_config().unwrap();
let history_path =
crate::config_files::get_history_path("nushell", history.file_format).unwrap();
let history_path = history.file_path().unwrap();
let line_editor = reedline::Reedline::create();
let history_session_id = reedline::Reedline::create_history_session_id();
let line_editor = update_line_editor_history(

View File

@ -18,11 +18,11 @@ use support::{
#[fixture]
fn completer() -> NuCompleter {
// Create a new engine
let (dir, _, mut engine, mut stack) = new_engine();
let (_, _, mut engine, mut stack) = new_engine();
// Add record value as example
let record = "def tst [--mod -s] {}";
assert!(support::merge_input(record.as_bytes(), &mut engine, &mut stack, dir).is_ok());
assert!(support::merge_input(record.as_bytes(), &mut engine, &mut stack).is_ok());
// Instantiate a new completer
NuCompleter::new(Arc::new(engine), Arc::new(stack))
@ -31,11 +31,12 @@ fn completer() -> NuCompleter {
#[fixture]
fn completer_strings() -> NuCompleter {
// Create a new engine
let (dir, _, mut engine, mut stack) = new_engine();
let (_, _, mut engine, mut stack) = new_engine();
// Add record value as example
let record = r#"def animals [] { ["cat", "dog", "eel" ] }
def my-command [animal: string@animals] { print $animal }"#;
assert!(support::merge_input(record.as_bytes(), &mut engine, &mut stack, dir).is_ok());
assert!(support::merge_input(record.as_bytes(), &mut engine, &mut stack).is_ok());
// Instantiate a new completer
NuCompleter::new(Arc::new(engine), Arc::new(stack))
@ -44,7 +45,7 @@ fn completer_strings() -> NuCompleter {
#[fixture]
fn extern_completer() -> NuCompleter {
// Create a new engine
let (dir, _, mut engine, mut stack) = new_engine();
let (_, _, mut engine, mut stack) = new_engine();
// Add record value as example
let record = r#"
@ -55,7 +56,7 @@ fn extern_completer() -> NuCompleter {
-b: string@animals
]
"#;
assert!(support::merge_input(record.as_bytes(), &mut engine, &mut stack, dir).is_ok());
assert!(support::merge_input(record.as_bytes(), &mut engine, &mut stack).is_ok());
// Instantiate a new completer
NuCompleter::new(Arc::new(engine), Arc::new(stack))
@ -64,7 +65,7 @@ fn extern_completer() -> NuCompleter {
#[fixture]
fn completer_strings_with_options() -> NuCompleter {
// Create a new engine
let (dir, _, mut engine, mut stack) = new_engine();
let (_, _, mut engine, mut stack) = new_engine();
// Add record value as example
let record = r#"
# To test that the config setting has no effect on the custom completions
@ -81,7 +82,7 @@ fn completer_strings_with_options() -> NuCompleter {
}
}
def my-command [animal: string@animals] { print $animal }"#;
assert!(support::merge_input(record.as_bytes(), &mut engine, &mut stack, dir).is_ok());
assert!(support::merge_input(record.as_bytes(), &mut engine, &mut stack).is_ok());
// Instantiate a new completer
NuCompleter::new(Arc::new(engine), Arc::new(stack))
@ -90,7 +91,7 @@ fn completer_strings_with_options() -> NuCompleter {
#[fixture]
fn custom_completer() -> NuCompleter {
// Create a new engine
let (dir, _, mut engine, mut stack) = new_engine();
let (_, _, mut engine, mut stack) = new_engine();
// Add record value as example
let record = r#"
@ -104,7 +105,7 @@ fn custom_completer() -> NuCompleter {
completer: $external_completer
}
"#;
assert!(support::merge_input(record.as_bytes(), &mut engine, &mut stack, dir).is_ok());
assert!(support::merge_input(record.as_bytes(), &mut engine, &mut stack).is_ok());
// Instantiate a new completer
NuCompleter::new(Arc::new(engine), Arc::new(stack))
@ -113,7 +114,7 @@ fn custom_completer() -> NuCompleter {
#[fixture]
fn subcommand_completer() -> NuCompleter {
// Create a new engine
let (dir, _, mut engine, mut stack) = new_engine();
let (_, _, mut engine, mut stack) = new_engine();
let commands = r#"
$env.config.completions.algorithm = "fuzzy"
@ -123,7 +124,7 @@ fn subcommand_completer() -> NuCompleter {
def "foo aabcrr" [] {}
def food [] {}
"#;
assert!(support::merge_input(commands.as_bytes(), &mut engine, &mut stack, dir).is_ok());
assert!(support::merge_input(commands.as_bytes(), &mut engine, &mut stack).is_ok());
// Instantiate a new completer
NuCompleter::new(Arc::new(engine), Arc::new(stack))
@ -133,13 +134,13 @@ fn subcommand_completer() -> NuCompleter {
#[fixture]
fn fuzzy_alpha_sort_completer() -> NuCompleter {
// Create a new engine
let (dir, _, mut engine, mut stack) = new_engine();
let (_, _, mut engine, mut stack) = new_engine();
let config = r#"
$env.config.completions.algorithm = "fuzzy"
$env.config.completions.sort = "alphabetical"
"#;
assert!(support::merge_input(config.as_bytes(), &mut engine, &mut stack, dir).is_ok());
assert!(support::merge_input(config.as_bytes(), &mut engine, &mut stack).is_ok());
// Instantiate a new completer
NuCompleter::new(Arc::new(engine), Arc::new(stack))
@ -942,7 +943,7 @@ fn flag_completions() {
// Test completions for the 'ls' flags
let suggestions = completer.complete("ls -", 4);
assert_eq!(16, suggestions.len());
assert_eq!(18, suggestions.len());
let expected: Vec<String> = vec![
"--all".into(),
@ -953,6 +954,7 @@ fn flag_completions() {
"--long".into(),
"--mime-type".into(),
"--short-names".into(),
"--threads".into(),
"-D".into(),
"-a".into(),
"-d".into(),
@ -961,6 +963,7 @@ fn flag_completions() {
"-l".into(),
"-m".into(),
"-s".into(),
"-t".into(),
];
// Match results
@ -1194,11 +1197,11 @@ fn folder_with_directorycompletions_do_not_collapse_dots() {
#[test]
fn variables_completions() {
// Create a new engine
let (dir, _, mut engine, mut stack) = new_engine();
let (_, _, mut engine, mut stack) = new_engine();
// Add record value as example
let record = "let actor = { name: 'Tom Hardy', age: 44 }";
assert!(support::merge_input(record.as_bytes(), &mut engine, &mut stack, dir).is_ok());
assert!(support::merge_input(record.as_bytes(), &mut engine, &mut stack).is_ok());
// Instantiate a new completer
let mut completer = NuCompleter::new(Arc::new(engine), Arc::new(stack));
@ -1309,11 +1312,11 @@ fn variables_completions() {
#[test]
fn alias_of_command_and_flags() {
let (dir, _, mut engine, mut stack) = new_engine();
let (_, _, mut engine, mut stack) = new_engine();
// Create an alias
let alias = r#"alias ll = ls -l"#;
assert!(support::merge_input(alias.as_bytes(), &mut engine, &mut stack, dir).is_ok());
assert!(support::merge_input(alias.as_bytes(), &mut engine, &mut stack).is_ok());
let mut completer = NuCompleter::new(Arc::new(engine), Arc::new(stack));
@ -1328,11 +1331,11 @@ fn alias_of_command_and_flags() {
#[test]
fn alias_of_basic_command() {
let (dir, _, mut engine, mut stack) = new_engine();
let (_, _, mut engine, mut stack) = new_engine();
// Create an alias
let alias = r#"alias ll = ls "#;
assert!(support::merge_input(alias.as_bytes(), &mut engine, &mut stack, dir).is_ok());
assert!(support::merge_input(alias.as_bytes(), &mut engine, &mut stack).is_ok());
let mut completer = NuCompleter::new(Arc::new(engine), Arc::new(stack));
@ -1347,14 +1350,14 @@ fn alias_of_basic_command() {
#[test]
fn alias_of_another_alias() {
let (dir, _, mut engine, mut stack) = new_engine();
let (_, _, mut engine, mut stack) = new_engine();
// Create an alias
let alias = r#"alias ll = ls -la"#;
assert!(support::merge_input(alias.as_bytes(), &mut engine, &mut stack, dir.clone()).is_ok());
assert!(support::merge_input(alias.as_bytes(), &mut engine, &mut stack).is_ok());
// Create the second alias
let alias = r#"alias lf = ll -f"#;
assert!(support::merge_input(alias.as_bytes(), &mut engine, &mut stack, dir).is_ok());
assert!(support::merge_input(alias.as_bytes(), &mut engine, &mut stack).is_ok());
let mut completer = NuCompleter::new(Arc::new(engine), Arc::new(stack));
@ -1371,7 +1374,7 @@ fn run_external_completion(completer: &str, input: &str) -> Vec<Suggestion> {
let completer = format!("$env.config.completions.external.completer = {completer}");
// Create a new engine
let (dir, _, mut engine_state, mut stack) = new_engine();
let (_, _, mut engine_state, mut stack) = new_engine();
let (block, delta) = {
let mut working_set = StateWorkingSet::new(&engine_state);
let block = parse(&mut working_set, None, completer.as_bytes(), false);
@ -1387,7 +1390,7 @@ fn run_external_completion(completer: &str, input: &str) -> Vec<Suggestion> {
);
// Merge environment into the permanent state
assert!(engine_state.merge_env(&mut stack, &dir).is_ok());
assert!(engine_state.merge_env(&mut stack).is_ok());
// Instantiate a new completer
let mut completer = NuCompleter::new(Arc::new(engine_state), Arc::new(stack));
@ -1576,11 +1579,11 @@ fn sort_fuzzy_completions_in_alphabetical_order(mut fuzzy_alpha_sort_completer:
#[ignore = "was reverted, still needs fixing"]
#[rstest]
fn alias_offset_bug_7648() {
let (dir, _, mut engine, mut stack) = new_engine();
let (_, _, mut engine, mut stack) = new_engine();
// Create an alias
let alias = r#"alias ea = ^$env.EDITOR /tmp/test.s"#;
assert!(support::merge_input(alias.as_bytes(), &mut engine, &mut stack, dir).is_ok());
assert!(support::merge_input(alias.as_bytes(), &mut engine, &mut stack).is_ok());
let mut completer = NuCompleter::new(Arc::new(engine), Arc::new(stack));
@ -1595,11 +1598,11 @@ fn alias_offset_bug_7648() {
#[ignore = "was reverted, still needs fixing"]
#[rstest]
fn alias_offset_bug_7754() {
let (dir, _, mut engine, mut stack) = new_engine();
let (_, _, mut engine, mut stack) = new_engine();
// Create an alias
let alias = r#"alias ll = ls -l"#;
assert!(support::merge_input(alias.as_bytes(), &mut engine, &mut stack, dir).is_ok());
assert!(support::merge_input(alias.as_bytes(), &mut engine, &mut stack).is_ok());
let mut completer = NuCompleter::new(Arc::new(engine), Arc::new(stack));

View File

@ -63,7 +63,7 @@ pub fn new_engine() -> (AbsolutePathBuf, String, EngineState, Stack) {
);
// Merge environment into the permanent state
let merge_result = engine_state.merge_env(&mut stack, &dir);
let merge_result = engine_state.merge_env(&mut stack);
assert!(merge_result.is_ok());
(dir, dir_str, engine_state, stack)
@ -109,7 +109,7 @@ pub fn new_dotnu_engine() -> (AbsolutePathBuf, String, EngineState, Stack) {
);
// Merge environment into the permanent state
let merge_result = engine_state.merge_env(&mut stack, &dir);
let merge_result = engine_state.merge_env(&mut stack);
assert!(merge_result.is_ok());
(dir, dir_str, engine_state, stack)
@ -144,7 +144,7 @@ pub fn new_quote_engine() -> (AbsolutePathBuf, String, EngineState, Stack) {
);
// Merge environment into the permanent state
let merge_result = engine_state.merge_env(&mut stack, &dir);
let merge_result = engine_state.merge_env(&mut stack);
assert!(merge_result.is_ok());
(dir, dir_str, engine_state, stack)
@ -179,7 +179,7 @@ pub fn new_partial_engine() -> (AbsolutePathBuf, String, EngineState, Stack) {
);
// Merge environment into the permanent state
let merge_result = engine_state.merge_env(&mut stack, &dir);
let merge_result = engine_state.merge_env(&mut stack);
assert!(merge_result.is_ok());
(dir, dir_str, engine_state, stack)
@ -223,7 +223,6 @@ pub fn merge_input(
input: &[u8],
engine_state: &mut EngineState,
stack: &mut Stack,
dir: AbsolutePathBuf,
) -> Result<(), ShellError> {
let (block, delta) = {
let mut working_set = StateWorkingSet::new(engine_state);
@ -246,5 +245,5 @@ pub fn merge_input(
.is_ok());
// Merge environment into the permanent state
engine_state.merge_env(stack, &dir)
engine_state.merge_env(stack)
}

View File

@ -5,7 +5,7 @@ edition = "2021"
license = "MIT"
name = "nu-cmd-base"
repository = "https://github.com/nushell/nushell/tree/main/crates/nu-cmd-base"
version = "0.98.0"
version = "0.99.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@ -13,10 +13,10 @@ version = "0.98.0"
workspace = true
[dependencies]
nu-engine = { path = "../nu-engine", version = "0.98.0" }
nu-parser = { path = "../nu-parser", version = "0.98.0" }
nu-path = { path = "../nu-path", version = "0.98.0" }
nu-protocol = { path = "../nu-protocol", version = "0.98.0" }
nu-engine = { path = "../nu-engine", version = "0.99.0" }
nu-parser = { path = "../nu-parser", version = "0.99.0" }
nu-path = { path = "../nu-path", version = "0.99.0" }
nu-protocol = { path = "../nu-protocol", version = "0.99.0" }
indexmap = { workspace = true }
miette = { workspace = true }

View File

@ -1,4 +1,3 @@
use crate::util::get_guaranteed_cwd;
use miette::Result;
use nu_engine::{eval_block, eval_block_with_early_return};
use nu_parser::parse;
@ -19,17 +18,12 @@ pub fn eval_env_change_hook(
match hook {
Value::Record { val, .. } => {
for (env_name, hook_value) in &*val {
let before = engine_state
.previous_env_vars
.get(env_name)
.cloned()
.unwrap_or_default();
let after = stack
.get_env_var(engine_state, env_name)
.unwrap_or_default();
let before = engine_state.previous_env_vars.get(env_name);
let after = stack.get_env_var(engine_state, env_name);
if before != after {
let before = before.cloned().unwrap_or_default();
let after = after.cloned().unwrap_or_default();
eval_hook(
engine_state,
stack,
@ -40,7 +34,7 @@ pub fn eval_env_change_hook(
)?;
Arc::make_mut(&mut engine_state.previous_env_vars)
.insert(env_name.to_string(), after);
.insert(env_name.clone(), after);
}
}
}
@ -92,11 +86,12 @@ pub fn eval_hook(
);
if let Some(err) = working_set.parse_errors.first() {
report_parse_error(&working_set, err);
return Err(ShellError::UnsupportedConfigValue {
expected: "valid source code".into(),
value: "source code with syntax errors".into(),
span,
return Err(ShellError::GenericError {
error: format!("Failed to run {hook_name} hook"),
msg: "source code has errors".into(),
span: Some(span),
help: None,
inner: Vec::new(),
});
}
@ -167,10 +162,10 @@ pub fn eval_hook(
{
val
} else {
return Err(ShellError::UnsupportedConfigValue {
expected: "boolean output".to_string(),
value: "other PipelineData variant".to_string(),
span: other_span,
return Err(ShellError::RuntimeTypeMismatch {
expected: Type::Bool,
actual: pipeline_data.get_type(),
span: pipeline_data.span().unwrap_or(other_span),
});
}
}
@ -179,9 +174,9 @@ pub fn eval_hook(
}
}
} else {
return Err(ShellError::UnsupportedConfigValue {
expected: "block".to_string(),
value: format!("{}", condition.get_type()),
return Err(ShellError::RuntimeTypeMismatch {
expected: Type::Closure,
actual: condition.get_type(),
span: other_span,
});
}
@ -224,11 +219,12 @@ pub fn eval_hook(
);
if let Some(err) = working_set.parse_errors.first() {
report_parse_error(&working_set, err);
return Err(ShellError::UnsupportedConfigValue {
expected: "valid source code".into(),
value: "source code with syntax errors".into(),
span: source_span,
return Err(ShellError::GenericError {
error: format!("Failed to run {hook_name} hook"),
msg: "source code has errors".into(),
span: Some(span),
help: None,
inner: Vec::new(),
});
}
@ -263,9 +259,9 @@ pub fn eval_hook(
run_hook(engine_state, stack, val, input, arguments, source_span)?;
}
other => {
return Err(ShellError::UnsupportedConfigValue {
expected: "block or string".to_string(),
value: format!("{}", other.get_type()),
return Err(ShellError::RuntimeTypeMismatch {
expected: Type::custom("string or closure"),
actual: other.get_type(),
span: source_span,
});
}
@ -276,16 +272,15 @@ pub fn eval_hook(
output = run_hook(engine_state, stack, val, input, arguments, span)?;
}
other => {
return Err(ShellError::UnsupportedConfigValue {
expected: "string, block, record, or list of commands".into(),
value: format!("{}", other.get_type()),
return Err(ShellError::RuntimeTypeMismatch {
expected: Type::custom("string, closure, record, or list"),
actual: other.get_type(),
span: other.span(),
});
}
}
let cwd = get_guaranteed_cwd(engine_state, stack);
engine_state.merge_env(stack, cwd)?;
engine_state.merge_env(stack)?;
Ok(output)
}

View File

@ -1,30 +1,9 @@
use nu_path::AbsolutePathBuf;
use nu_protocol::{
engine::{EngineState, Stack},
Range, ShellError, Span, Value,
};
use std::ops::Bound;
pub fn get_init_cwd() -> AbsolutePathBuf {
std::env::current_dir()
.ok()
.and_then(|path| AbsolutePathBuf::try_from(path).ok())
.or_else(|| {
std::env::var("PWD")
.ok()
.and_then(|path| AbsolutePathBuf::try_from(path).ok())
})
.or_else(nu_path::home_dir)
.expect("Failed to get current working directory")
}
pub fn get_guaranteed_cwd(engine_state: &EngineState, stack: &Stack) -> AbsolutePathBuf {
engine_state
.cwd(Some(stack))
.ok()
.unwrap_or_else(get_init_cwd)
}
type MakeRangeError = fn(&str, Span) -> ShellError;
/// Returns a inclusive pair of boundary in given `range`.

View File

@ -5,7 +5,7 @@ edition = "2021"
license = "MIT"
name = "nu-cmd-extra"
repository = "https://github.com/nushell/nushell/tree/main/crates/nu-cmd-extra"
version = "0.98.0"
version = "0.99.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@ -16,13 +16,13 @@ bench = false
workspace = true
[dependencies]
nu-cmd-base = { path = "../nu-cmd-base", version = "0.98.0" }
nu-engine = { path = "../nu-engine", version = "0.98.0" }
nu-json = { version = "0.98.0", path = "../nu-json" }
nu-parser = { path = "../nu-parser", version = "0.98.0" }
nu-pretty-hex = { version = "0.98.0", path = "../nu-pretty-hex" }
nu-protocol = { path = "../nu-protocol", version = "0.98.0" }
nu-utils = { path = "../nu-utils", version = "0.98.0" }
nu-cmd-base = { path = "../nu-cmd-base", version = "0.99.0" }
nu-engine = { path = "../nu-engine", version = "0.99.0" }
nu-json = { version = "0.99.0", path = "../nu-json" }
nu-parser = { path = "../nu-parser", version = "0.99.0" }
nu-pretty-hex = { version = "0.99.0", path = "../nu-pretty-hex" }
nu-protocol = { path = "../nu-protocol", version = "0.99.0" }
nu-utils = { path = "../nu-utils", version = "0.99.0" }
# Potential dependencies for extras
heck = { workspace = true }
@ -36,6 +36,6 @@ v_htmlescape = { workspace = true }
itertools = { workspace = true }
[dev-dependencies]
nu-cmd-lang = { path = "../nu-cmd-lang", version = "0.98.0" }
nu-command = { path = "../nu-command", version = "0.98.0" }
nu-test-support = { path = "../nu-test-support", version = "0.98.0" }
nu-cmd-lang = { path = "../nu-cmd-lang", version = "0.99.0" }
nu-command = { path = "../nu-command", version = "0.99.0" }
nu-test-support = { path = "../nu-test-support", version = "0.99.0" }

View File

@ -6,7 +6,7 @@ repository = "https://github.com/nushell/nushell/tree/main/crates/nu-cmd-lang"
edition = "2021"
license = "MIT"
name = "nu-cmd-lang"
version = "0.98.0"
version = "0.99.0"
[lib]
bench = false
@ -15,16 +15,16 @@ bench = false
workspace = true
[dependencies]
nu-engine = { path = "../nu-engine", version = "0.98.0" }
nu-parser = { path = "../nu-parser", version = "0.98.0" }
nu-protocol = { path = "../nu-protocol", version = "0.98.0" }
nu-utils = { path = "../nu-utils", version = "0.98.0" }
nu-engine = { path = "../nu-engine", version = "0.99.0" }
nu-parser = { path = "../nu-parser", version = "0.99.0" }
nu-protocol = { path = "../nu-protocol", version = "0.99.0" }
nu-utils = { path = "../nu-utils", version = "0.99.0" }
itertools = { workspace = true }
shadow-rs = { version = "0.34", default-features = false }
shadow-rs = { version = "0.35", default-features = false }
[build-dependencies]
shadow-rs = { version = "0.34", default-features = false }
shadow-rs = { version = "0.35", default-features = false }
[features]
mimalloc = []

View File

@ -147,6 +147,7 @@ impl Command for Do {
None
};
child.ignore_error(false);
child.wait()?;
let mut child = ChildProcess::from_raw(None, None, None, span);
@ -166,10 +167,13 @@ impl Command for Do {
}
Ok(PipelineData::ByteStream(mut stream, metadata))
if ignore_program_errors
&& !matches!(caller_stack.stdout(), OutDest::Pipe | OutDest::Capture) =>
&& !matches!(
caller_stack.stdout(),
OutDest::Pipe | OutDest::PipeSeparate | OutDest::Value
) =>
{
if let ByteStreamSource::Child(child) = stream.source_mut() {
child.set_exit_code(0)
child.ignore_error(true);
}
Ok(PipelineData::ByteStream(stream, metadata))
}

View File

@ -63,7 +63,7 @@ impl Command for HideEnv {
fn examples(&self) -> Vec<Example> {
vec![Example {
description: "Hide an environment variable",
example: r#"$env.HZ_ENV_ABC = 1; hide-env HZ_ENV_ABC; 'HZ_ENV_ABC' in (env).name"#,
example: r#"$env.HZ_ENV_ABC = 1; hide-env HZ_ENV_ABC; 'HZ_ENV_ABC' in $env"#,
result: Some(Value::test_bool(false)),
}]
}

View File

@ -1,5 +1,5 @@
use nu_engine::command_prelude::*;
use nu_protocol::{engine::StateWorkingSet, OutDest};
use nu_protocol::{engine::StateWorkingSet, ByteStreamSource, OutDest};
#[derive(Clone)]
pub struct Ignore;
@ -32,8 +32,13 @@ impl Command for Ignore {
_engine_state: &EngineState,
_stack: &mut Stack,
_call: &Call,
input: PipelineData,
mut input: PipelineData,
) -> Result<PipelineData, ShellError> {
if let PipelineData::ByteStream(stream, _) = &mut input {
if let ByteStreamSource::Child(child) = stream.source_mut() {
child.ignore_error(true);
}
}
input.drain()?;
Ok(PipelineData::empty())
}

View File

@ -63,7 +63,7 @@ impl Command for Let {
let block = engine_state.get_block(block_id);
let eval_block = get_eval_block(engine_state);
let stack = &mut stack.start_capture();
let stack = &mut stack.start_collect_value();
let pipeline_data = eval_block(engine_state, stack, block, input)?;
let value = pipeline_data.into_value(call.head)?;

View File

@ -63,7 +63,7 @@ impl Command for Mut {
let block = engine_state.get_block(block_id);
let eval_block = get_eval_block(engine_state);
let stack = &mut stack.start_capture();
let stack = &mut stack.start_collect_value();
let pipeline_data = eval_block(engine_state, stack, block, input)?;
let value = pipeline_data.into_value(call.head)?;

View File

@ -2,7 +2,7 @@ use nu_engine::{
command_prelude::*, find_in_dirs_env, get_dirs_var_from_call, get_eval_block, redirect_env,
};
use nu_parser::trim_quotes_str;
use nu_protocol::{ast::Expr, engine::CommandType};
use nu_protocol::{ast::Expr, engine::CommandType, ModuleId};
use std::path::Path;
@ -64,7 +64,7 @@ impl Command for OverlayUse {
let mut name_arg: Spanned<String> = call.req(engine_state, caller_stack, 0)?;
name_arg.item = trim_quotes_str(&name_arg.item).to_string();
let maybe_origin_module_id =
let maybe_origin_module_id: Option<ModuleId> =
if let Some(overlay_expr) = call.get_parser_info(caller_stack, "overlay_expr") {
if let Expr::Overlay(module_id) = &overlay_expr.expr {
*module_id

View File

@ -63,7 +63,7 @@ impl Command for Try {
let eval_block = get_eval_block(engine_state);
let result = eval_block(engine_state, stack, try_block, input)
.and_then(|pipeline| pipeline.write_to_out_dests(engine_state, stack));
.and_then(|pipeline| pipeline.drain_to_out_dests(engine_state, stack));
match result {
Err(err) => run_catch(err, head, catch_block, engine_state, stack, eval_block),

View File

@ -126,7 +126,7 @@ pub fn eval_block(
cwd: &std::path::Path,
engine_state: &EngineState,
) -> Value {
let mut stack = Stack::new().capture();
let mut stack = Stack::new().collect_value();
stack.add_env_var("PWD".to_string(), Value::test_string(cwd.to_string_lossy()));
@ -143,13 +143,13 @@ pub fn check_example_evaluates_to_expected_output(
cwd: &std::path::Path,
engine_state: &mut Box<EngineState>,
) {
let mut stack = Stack::new().capture();
let mut stack = Stack::new().collect_value();
// Set up PWD
stack.add_env_var("PWD".to_string(), Value::test_string(cwd.to_string_lossy()));
engine_state
.merge_env(&mut stack, cwd)
.merge_env(&mut stack)
.expect("Error merging environment");
let empty_input = PipelineData::empty();

View File

@ -5,7 +5,7 @@ edition = "2021"
license = "MIT"
name = "nu-cmd-plugin"
repository = "https://github.com/nushell/nushell/tree/main/crates/nu-cmd-plugin"
version = "0.98.0"
version = "0.99.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@ -13,10 +13,10 @@ version = "0.98.0"
workspace = true
[dependencies]
nu-engine = { path = "../nu-engine", version = "0.98.0" }
nu-path = { path = "../nu-path", version = "0.98.0" }
nu-protocol = { path = "../nu-protocol", version = "0.98.0", features = ["plugin"] }
nu-plugin-engine = { path = "../nu-plugin-engine", version = "0.98.0" }
nu-engine = { path = "../nu-engine", version = "0.99.0" }
nu-path = { path = "../nu-path", version = "0.99.0" }
nu-protocol = { path = "../nu-protocol", version = "0.99.0", features = ["plugin"] }
nu-plugin-engine = { path = "../nu-plugin-engine", version = "0.99.0" }
itertools = { workspace = true }

View File

@ -1,10 +1,9 @@
use crate::util::{get_plugin_dirs, modify_plugin_file};
use nu_engine::command_prelude::*;
use nu_plugin_engine::{GetPlugin, PersistentPlugin};
use nu_protocol::{PluginGcConfig, PluginIdentity, PluginRegistryItem, RegisteredPlugin};
use std::sync::Arc;
use crate::util::{get_plugin_dirs, modify_plugin_file};
#[derive(Clone)]
pub struct PluginAdd;
@ -31,7 +30,7 @@ impl Command for PluginAdd {
)
.required(
"filename",
SyntaxShape::Filepath,
SyntaxShape::String,
"Path to the executable for the plugin",
)
.category(Category::Plugin)
@ -81,7 +80,6 @@ apparent the next time `nu` is next launched with that plugin registry file.
) -> Result<PipelineData, ShellError> {
let filename: Spanned<String> = call.req(engine_state, stack, 0)?;
let shell: Option<Spanned<String>> = call.get_flag(engine_state, stack, "shell")?;
let cwd = engine_state.cwd(Some(stack))?;
// Check the current directory, or fall back to NU_PLUGIN_DIRS

View File

@ -95,8 +95,9 @@ pub(crate) fn get_plugin_dirs(
let working_set = StateWorkingSet::new(engine_state);
let value = working_set
.find_variable(b"$NU_PLUGIN_DIRS")
.and_then(|var_id| working_set.get_constant(var_id).ok().cloned())
.or_else(|| stack.get_env_var(engine_state, "NU_PLUGIN_DIRS"));
.and_then(|var_id| working_set.get_constant(var_id).ok())
.or_else(|| stack.get_env_var(engine_state, "NU_PLUGIN_DIRS"))
.cloned(); // TODO: avoid this clone
// Get all of the strings in the list, if possible
value

View File

@ -5,7 +5,7 @@ repository = "https://github.com/nushell/nushell/tree/main/crates/nu-color-confi
edition = "2021"
license = "MIT"
name = "nu-color-config"
version = "0.98.0"
version = "0.99.0"
[lib]
bench = false
@ -14,12 +14,12 @@ bench = false
workspace = true
[dependencies]
nu-protocol = { path = "../nu-protocol", version = "0.98.0" }
nu-engine = { path = "../nu-engine", version = "0.98.0" }
nu-json = { path = "../nu-json", version = "0.98.0" }
nu-protocol = { path = "../nu-protocol", version = "0.99.0" }
nu-engine = { path = "../nu-engine", version = "0.99.0" }
nu-json = { path = "../nu-json", version = "0.99.0" }
nu-ansi-term = { workspace = true }
serde = { workspace = true, features = ["derive"] }
[dev-dependencies]
nu-test-support = { path = "../nu-test-support", version = "0.98.0" }
nu-test-support = { path = "../nu-test-support", version = "0.99.0" }

View File

@ -2,9 +2,8 @@ use crate::{color_record_to_nustyle, lookup_ansi_color_style, text_style::Alignm
use nu_ansi_term::{Color, Style};
use nu_engine::ClosureEvalOnce;
use nu_protocol::{
cli_error::CliError,
engine::{Closure, EngineState, Stack, StateWorkingSet},
Span, Value,
engine::{Closure, EngineState, Stack},
report_shell_error, Span, Value,
};
use std::{
collections::HashMap,
@ -70,14 +69,8 @@ impl<'a> StyleComputer<'a> {
_ => Style::default(),
}
}
// This is basically a copy of nu_cli::report_error(), but that isn't usable due to
// dependencies. While crudely spitting out a bunch of errors like this is not ideal,
// currently hook closure errors behave roughly the same.
Err(e) => {
eprintln!(
"Error: {:?}",
CliError(&e, &StateWorkingSet::new(self.engine_state))
);
Err(err) => {
report_shell_error(self.engine_state, &err);
Style::default()
}
}

View File

@ -5,7 +5,7 @@ edition = "2021"
license = "MIT"
name = "nu-command"
repository = "https://github.com/nushell/nushell/tree/main/crates/nu-command"
version = "0.98.0"
version = "0.99.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@ -16,21 +16,21 @@ bench = false
workspace = true
[dependencies]
nu-cmd-base = { path = "../nu-cmd-base", version = "0.98.0" }
nu-color-config = { path = "../nu-color-config", version = "0.98.0" }
nu-engine = { path = "../nu-engine", version = "0.98.0" }
nu-glob = { path = "../nu-glob", version = "0.98.0" }
nu-json = { path = "../nu-json", version = "0.98.0" }
nu-parser = { path = "../nu-parser", version = "0.98.0" }
nu-path = { path = "../nu-path", version = "0.98.0" }
nu-pretty-hex = { path = "../nu-pretty-hex", version = "0.98.0" }
nu-protocol = { path = "../nu-protocol", version = "0.98.0" }
nu-system = { path = "../nu-system", version = "0.98.0" }
nu-table = { path = "../nu-table", version = "0.98.0" }
nu-term-grid = { path = "../nu-term-grid", version = "0.98.0" }
nu-utils = { path = "../nu-utils", version = "0.98.0" }
nu-cmd-base = { path = "../nu-cmd-base", version = "0.99.0" }
nu-color-config = { path = "../nu-color-config", version = "0.99.0" }
nu-engine = { path = "../nu-engine", version = "0.99.0" }
nu-glob = { path = "../nu-glob", version = "0.99.0" }
nu-json = { path = "../nu-json", version = "0.99.0" }
nu-parser = { path = "../nu-parser", version = "0.99.0" }
nu-path = { path = "../nu-path", version = "0.99.0" }
nu-pretty-hex = { path = "../nu-pretty-hex", version = "0.99.0" }
nu-protocol = { path = "../nu-protocol", version = "0.99.0" }
nu-system = { path = "../nu-system", version = "0.99.0" }
nu-table = { path = "../nu-table", version = "0.99.0" }
nu-term-grid = { path = "../nu-term-grid", version = "0.99.0" }
nu-utils = { path = "../nu-utils", version = "0.99.0" }
nu-ansi-term = { workspace = true }
nuon = { path = "../nuon", version = "0.98.0" }
nuon = { path = "../nuon", version = "0.99.0" }
alphanumeric-sort = { workspace = true }
base64 = { workspace = true }
@ -139,8 +139,8 @@ sqlite = ["rusqlite"]
trash-support = ["trash"]
[dev-dependencies]
nu-cmd-lang = { path = "../nu-cmd-lang", version = "0.98.0" }
nu-test-support = { path = "../nu-test-support", version = "0.98.0" }
nu-cmd-lang = { path = "../nu-cmd-lang", version = "0.99.0" }
nu-test-support = { path = "../nu-test-support", version = "0.99.0" }
dirs = { workspace = true }
mockito = { workspace = true, default-features = false }

View File

@ -183,6 +183,7 @@ mod test {
use nu_protocol::{
ast::{CellPath, PathMember},
engine::Closure,
BlockId,
};
use std::collections::HashSet;
@ -244,7 +245,7 @@ mod test {
Value::list(vec![Value::bool(true, span)], span),
Value::closure(
Closure {
block_id: 0,
block_id: BlockId::new(0),
captures: Vec::new(),
},
span,

View File

@ -108,7 +108,7 @@ impl Command for Fill {
},
Example {
description:
"Fill a filesize on the left side to a width of 5 with the character '0'",
"Fill a filesize on both sides to a width of 10 with the character '0'",
example: "1kib | fill --alignment middle --character '0' --width 10",
result: Some(Value::string("0001024000", Span::test_data())),
},

View File

@ -32,7 +32,11 @@ impl Command for IntoValue {
}
fn description(&self) -> &str {
"Infer nushell datatype for each cell."
"Infer Nushell datatype for each cell."
}
fn search_terms(&self) -> Vec<&str> {
vec!["convert", "conversion"]
}
fn examples(&self) -> Vec<Example> {

View File

@ -271,7 +271,7 @@ pub fn debug_string_without_formatting(value: &Value) -> String {
.join(" ")
),
//TODO: It would be good to drill deeper into closures.
Value::Closure { val, .. } => format!("<Closure {}>", val.block_id),
Value::Closure { val, .. } => format!("<Closure {}>", val.block_id.get()),
Value::Nothing { .. } => String::new(),
Value::Error { error, .. } => format!("{error:?}"),
Value::Binary { val, .. } => format!("{val:?}"),

View File

@ -152,7 +152,7 @@ fn truncate_data(
let left_space = expected_width - width;
let has_space_for_truncation_column = left_space > PAD;
if !has_space_for_truncation_column {
peak_count -= 1;
peak_count = peak_count.saturating_sub(1);
}
remove_columns(data, peak_count);
@ -201,11 +201,18 @@ mod util {
Value::Record { val: record, .. } => {
let (cols, vals): (Vec<_>, Vec<_>) = record.into_owned().into_iter().unzip();
(
cols,
vec![vals
match cols.is_empty() {
true => vec![String::from("")],
false => cols,
},
match vals
.into_iter()
.map(|s| debug_string_without_formatting(&s))
.collect()],
.collect::<Vec<String>>()
{
vals if vals.is_empty() => vec![],
vals => vec![vals],
},
)
}
Value::List { vals, .. } => {

View File

@ -1,4 +1,5 @@
use nu_engine::command_prelude::*;
use nu_protocol::{BlockId, DeclId};
#[derive(Clone)]
pub struct ViewIr;
@ -86,7 +87,8 @@ the declaration may not be in scope.
let decl_id = val
.try_into()
.ok()
.filter(|id| *id < engine_state.num_decls())
.map(DeclId::new)
.filter(|id| id.get() < engine_state.num_decls())
.ok_or_else(|| ShellError::IncorrectValue {
msg: "not a valid decl id".into(),
val_span: target.span(),
@ -102,11 +104,15 @@ the declaration may not be in scope.
})?
}
// Block by ID - often shows up in IR
Value::Int { val, .. } => val.try_into().map_err(|_| ShellError::IncorrectValue {
msg: "not a valid block id".into(),
val_span: target.span(),
call_span: call.head,
})?,
Value::Int { val, .. } => {
val.try_into()
.map(BlockId::new)
.map_err(|_| ShellError::IncorrectValue {
msg: "not a valid block id".into(),
val_span: target.span(),
call_span: call.head,
})?
}
// Pass through errors
Value::Error { error, .. } => return Err(*error),
_ => {
@ -119,7 +125,7 @@ the declaration may not be in scope.
let Some(block) = engine_state.try_get_block(block_id) else {
return Err(ShellError::GenericError {
error: format!("Unknown block ID: {block_id}"),
error: format!("Unknown block ID: {}", block_id.get()),
msg: "ensure the block ID is correct and try again".into(),
span: Some(target.span()),
help: None,

View File

@ -1,5 +1,5 @@
use nu_engine::command_prelude::*;
use nu_protocol::Config;
use nu_protocol::{Config, DataSource, PipelineMetadata};
use std::fmt::Write;
@ -32,7 +32,7 @@ impl Command for ViewSource {
let arg: Value = call.req(engine_state, stack, 0)?;
let arg_span = arg.span();
match arg {
let source = match arg {
Value::String { val, .. } => {
if let Some(decl_id) = engine_state.find_decl(val.as_bytes(), &[]) {
// arg is a command
@ -193,7 +193,13 @@ impl Command for ViewSource {
})
}
}
}
};
source.map(|x| {
x.set_metadata(Some(PipelineMetadata {
data_source: DataSource::None,
content_type: Some("application/x-nuscript".into()),
}))
})
}
fn examples(&self) -> Vec<Example> {

View File

@ -46,7 +46,6 @@ pub fn add_shell_command_context(mut engine_state: EngineState) -> EngineState {
First,
Flatten,
Get,
Group,
GroupBy,
Headers,
Insert,
@ -188,8 +187,6 @@ pub fn add_shell_command_context(mut engine_state: EngineState) -> EngineState {
EncodeBase32Hex,
DecodeBase64,
EncodeBase64,
DecodeBase64Old,
EncodeBase64Old,
DetectColumns,
Parse,
Split,

View File

@ -45,13 +45,9 @@ impl Command for ConfigReset {
let only_env = call.has_flag(engine_state, stack, "env")?;
let no_backup = call.has_flag(engine_state, stack, "without-backup")?;
let span = call.head;
let mut config_path = match nu_path::config_dir() {
Some(path) => path,
None => {
return Err(ShellError::ConfigDirNotFound { span: None });
}
let Some(config_path) = nu_path::nu_config_dir() else {
return Err(ShellError::ConfigDirNotFound { span: None });
};
config_path.push("nushell");
if !only_env {
let mut nu_config = config_path.clone();
nu_config.push("config.nu");

View File

@ -2,7 +2,7 @@ use nu_engine::{
command_prelude::*, find_in_dirs_env, get_dirs_var_from_call, get_eval_block_with_early_return,
redirect_env,
};
use nu_protocol::engine::CommandType;
use nu_protocol::{engine::CommandType, BlockId};
use std::path::PathBuf;
/// Source a file for environment variables.
@ -50,6 +50,7 @@ impl Command for SourceEnv {
// Note: this hidden positional is the block_id that corresponded to the 0th position
// it is put here by the parser
let block_id: i64 = call.req_parser_info(engine_state, caller_stack, "block_id")?;
let block_id = BlockId::new(block_id as usize);
// Set the currently evaluated directory (file-relative PWD)
let file_path = if let Some(path) = find_in_dirs_env(
@ -78,7 +79,7 @@ impl Command for SourceEnv {
);
// Evaluate the block
let block = engine_state.get_block(block_id as usize).clone();
let block = engine_state.get_block(block_id).clone();
let mut callee_stack = caller_stack
.gather_captures(engine_state, &block.captures)
.reset_pipes();

View File

@ -1,4 +1,3 @@
use nu_cmd_base::util::get_init_cwd;
use nu_engine::command_prelude::*;
use nu_utils::filesystem::{have_permission, PermissionResult};
@ -41,12 +40,14 @@ impl Command for Cd {
let physical = call.has_flag(engine_state, stack, "physical")?;
let path_val: Option<Spanned<String>> = call.opt(engine_state, stack, 0)?;
// If getting PWD failed, default to the initial directory. This way, the
// user can use `cd` to recover PWD to a good state.
// If getting PWD failed, default to the home directory. The user can
// use `cd` to reset PWD to a good state.
let cwd = engine_state
.cwd(Some(stack))
.ok()
.unwrap_or_else(get_init_cwd);
.or_else(nu_path::home_dir)
.map(|path| path.into_std_path_buf())
.unwrap_or_default();
let path_val = {
if let Some(path) = path_val {
@ -65,7 +66,7 @@ impl Command for Cd {
if let Some(oldpwd) = stack.get_env_var(engine_state, "OLDPWD") {
oldpwd.to_path()?
} else {
cwd.into()
cwd
}
} else {
// Trim whitespace from the end of path.
@ -106,7 +107,7 @@ impl Command for Cd {
// Set OLDPWD.
// We're using `Stack::get_env_var()` instead of `EngineState::cwd()` to avoid a conversion roundtrip.
if let Some(oldpwd) = stack.get_env_var(engine_state, "PWD") {
stack.add_env_var("OLDPWD".into(), oldpwd)
stack.add_env_var("OLDPWD".into(), oldpwd.clone())
}
match have_permission(&path) {

View File

@ -169,10 +169,16 @@ impl Command for Glob {
});
}
// below we have to check / instead of MAIN_SEPARATOR because glob uses / as separator
// using a glob like **\*.rs should fail because it's not a valid glob pattern
let folder_depth = if let Some(depth) = depth {
depth
} else {
} else if glob_pattern.contains("**") {
usize::MAX
} else if glob_pattern.contains('/') {
glob_pattern.split('/').count() + 1
} else {
1
};
let (prefix, glob) = match WaxGlob::new(&glob_pattern) {

View File

@ -8,11 +8,14 @@ use nu_glob::MatchOptions;
use nu_path::{expand_path_with, expand_to_real_path};
use nu_protocol::{DataSource, NuGlob, PipelineMetadata, Signals};
use pathdiff::diff_paths;
use rayon::prelude::*;
#[cfg(unix)]
use std::os::unix::fs::PermissionsExt;
use std::{
path::PathBuf,
sync::mpsc,
sync::{Arc, Mutex},
time::{SystemTime, UNIX_EPOCH},
};
@ -28,6 +31,7 @@ struct Args {
du: bool,
directory: bool,
use_mime_type: bool,
use_threads: bool,
call_span: Span,
}
@ -75,6 +79,7 @@ impl Command for Ls {
Some('D'),
)
.switch("mime-type", "Show mime-type in type column instead of 'file' (based on filenames only; files' contents are not examined)", Some('m'))
.switch("threads", "Use multiple threads to list contents. Output will be non-deterministic.", Some('t'))
.category(Category::FileSystem)
}
@ -92,6 +97,7 @@ impl Command for Ls {
let du = call.has_flag(engine_state, stack, "du")?;
let directory = call.has_flag(engine_state, stack, "directory")?;
let use_mime_type = call.has_flag(engine_state, stack, "mime-type")?;
let use_threads = call.has_flag(engine_state, stack, "threads")?;
let call_span = call.head;
#[allow(deprecated)]
let cwd = current_dir(engine_state, stack)?;
@ -104,6 +110,7 @@ impl Command for Ls {
du,
directory,
use_mime_type,
use_threads,
call_span,
};
@ -114,22 +121,24 @@ impl Command for Ls {
Some(pattern_arg)
};
match input_pattern_arg {
None => Ok(ls_for_one_pattern(None, args, engine_state.signals(), cwd)?
.into_pipeline_data_with_metadata(
call_span,
engine_state.signals().clone(),
PipelineMetadata {
data_source: DataSource::Ls,
content_type: None,
},
)),
None => Ok(
ls_for_one_pattern(None, args, engine_state.signals().clone(), cwd)?
.into_pipeline_data_with_metadata(
call_span,
engine_state.signals().clone(),
PipelineMetadata {
data_source: DataSource::Ls,
content_type: None,
},
),
),
Some(pattern) => {
let mut result_iters = vec![];
for pat in pattern {
result_iters.push(ls_for_one_pattern(
Some(pat),
args,
engine_state.signals(),
engine_state.signals().clone(),
cwd.clone(),
)?)
}
@ -213,9 +222,27 @@ impl Command for Ls {
fn ls_for_one_pattern(
pattern_arg: Option<Spanned<NuGlob>>,
args: Args,
signals: &Signals,
signals: Signals,
cwd: PathBuf,
) -> Result<Box<dyn Iterator<Item = Value> + Send>, ShellError> {
) -> Result<PipelineData, ShellError> {
fn create_pool(num_threads: usize) -> Result<rayon::ThreadPool, ShellError> {
match rayon::ThreadPoolBuilder::new()
.num_threads(num_threads)
.build()
{
Err(e) => Err(e).map_err(|e| ShellError::GenericError {
error: "Error creating thread pool".into(),
msg: e.to_string(),
span: Some(Span::unknown()),
help: None,
inner: vec![],
}),
Ok(pool) => Ok(pool),
}
}
let (tx, rx) = mpsc::channel();
let Args {
all,
long,
@ -224,6 +251,7 @@ fn ls_for_one_pattern(
du,
directory,
use_mime_type,
use_threads,
call_span,
} = args;
let pattern_arg = {
@ -281,7 +309,7 @@ fn ls_for_one_pattern(
});
}
if is_empty_dir(&tmp_expanded) {
return Ok(Box::new(vec![].into_iter()));
return Ok(Value::test_nothing().into_pipeline_data());
}
just_read_dir = !(pat.item.is_expand() && pat.item.as_ref().contains(GLOB_CHARS));
}
@ -300,7 +328,7 @@ fn ls_for_one_pattern(
if directory {
(NuGlob::Expand(".".to_string()), false)
} else if is_empty_dir(&cwd) {
return Ok(Box::new(vec![].into_iter()));
return Ok(Value::test_nothing().into_pipeline_data());
} else {
(NuGlob::Expand("*".to_string()), false)
}
@ -338,92 +366,130 @@ fn ls_for_one_pattern(
});
}
let mut hidden_dirs = vec![];
let hidden_dirs = Arc::new(Mutex::new(Vec::new()));
let signals = signals.clone();
Ok(Box::new(paths_peek.filter_map(move |x| match x {
Ok(path) => {
let metadata = match std::fs::symlink_metadata(&path) {
Ok(metadata) => Some(metadata),
Err(_) => None,
};
if path_contains_hidden_folder(&path, &hidden_dirs) {
return None;
}
let signals_clone = signals.clone();
if !all && !hidden_dir_specified && is_hidden_dir(&path) {
if path.is_dir() {
hidden_dirs.push(path);
}
return None;
}
let pool = if use_threads {
let count = std::thread::available_parallelism()?.get();
create_pool(count)?
} else {
create_pool(1)?
};
let display_name = if short_names {
path.file_name().map(|os| os.to_string_lossy().to_string())
} else if full_paths || absolute_path {
Some(path.to_string_lossy().to_string())
} else if let Some(prefix) = &prefix {
if let Ok(remainder) = path.strip_prefix(prefix) {
if directory {
// When the path is the same as the cwd, path_diff should be "."
let path_diff = if let Some(path_diff_not_dot) = diff_paths(&path, &cwd) {
let path_diff_not_dot = path_diff_not_dot.to_string_lossy();
if path_diff_not_dot.is_empty() {
".".to_string()
pool.install(|| {
paths_peek
.par_bridge()
.filter_map(move |x| match x {
Ok(path) => {
let metadata = match std::fs::symlink_metadata(&path) {
Ok(metadata) => Some(metadata),
Err(_) => None,
};
let hidden_dir_clone = Arc::clone(&hidden_dirs);
let mut hidden_dir_mutex = hidden_dir_clone
.lock()
.expect("Unable to acquire lock for hidden_dirs");
if path_contains_hidden_folder(&path, &hidden_dir_mutex) {
return None;
}
if !all && !hidden_dir_specified && is_hidden_dir(&path) {
if path.is_dir() {
hidden_dir_mutex.push(path);
drop(hidden_dir_mutex);
}
return None;
}
let display_name = if short_names {
path.file_name().map(|os| os.to_string_lossy().to_string())
} else if full_paths || absolute_path {
Some(path.to_string_lossy().to_string())
} else if let Some(prefix) = &prefix {
if let Ok(remainder) = path.strip_prefix(prefix) {
if directory {
// When the path is the same as the cwd, path_diff should be "."
let path_diff =
if let Some(path_diff_not_dot) = diff_paths(&path, &cwd) {
let path_diff_not_dot = path_diff_not_dot.to_string_lossy();
if path_diff_not_dot.is_empty() {
".".to_string()
} else {
path_diff_not_dot.to_string()
}
} else {
path.to_string_lossy().to_string()
};
Some(path_diff)
} else {
path_diff_not_dot.to_string()
let new_prefix = if let Some(pfx) = diff_paths(prefix, &cwd) {
pfx
} else {
prefix.to_path_buf()
};
Some(new_prefix.join(remainder).to_string_lossy().to_string())
}
} else {
path.to_string_lossy().to_string()
};
Some(path_diff)
Some(path.to_string_lossy().to_string())
}
} else {
let new_prefix = if let Some(pfx) = diff_paths(prefix, &cwd) {
pfx
} else {
prefix.to_path_buf()
};
Some(new_prefix.join(remainder).to_string_lossy().to_string())
Some(path.to_string_lossy().to_string())
}
} else {
Some(path.to_string_lossy().to_string())
}
} else {
Some(path.to_string_lossy().to_string())
}
.ok_or_else(|| ShellError::GenericError {
error: format!("Invalid file name: {:}", path.to_string_lossy()),
msg: "invalid file name".into(),
span: Some(call_span),
help: None,
inner: vec![],
});
.ok_or_else(|| ShellError::GenericError {
error: format!("Invalid file name: {:}", path.to_string_lossy()),
msg: "invalid file name".into(),
span: Some(call_span),
help: None,
inner: vec![],
});
match display_name {
Ok(name) => {
let entry = dir_entry_dict(
&path,
&name,
metadata.as_ref(),
call_span,
long,
du,
&signals,
use_mime_type,
args.full_paths,
);
match entry {
Ok(value) => Some(value),
match display_name {
Ok(name) => {
let entry = dir_entry_dict(
&path,
&name,
metadata.as_ref(),
call_span,
long,
du,
&signals_clone,
use_mime_type,
args.full_paths,
);
match entry {
Ok(value) => Some(value),
Err(err) => Some(Value::error(err, call_span)),
}
}
Err(err) => Some(Value::error(err, call_span)),
}
}
Err(err) => Some(Value::error(err, call_span)),
}
}
Err(err) => Some(Value::error(err, call_span)),
})))
})
.try_for_each(|stream| {
tx.send(stream).map_err(|e| ShellError::GenericError {
error: "Error streaming data".into(),
msg: e.to_string(),
span: Some(call_span),
help: None,
inner: vec![],
})
})
})
.map_err(|err| ShellError::GenericError {
error: "Unable to create a rayon pool".into(),
msg: err.to_string(),
span: Some(call_span),
help: None,
inner: vec![],
})?;
Ok(rx
.into_iter()
.into_pipeline_data(call_span, signals.clone()))
}
fn permission_denied(dir: impl AsRef<Path>) -> bool {

View File

@ -12,6 +12,7 @@ use std::{
io::{self, BufRead, BufReader, Read, Write},
path::{Path, PathBuf},
thread,
time::{Duration, Instant},
};
#[derive(Clone)]
@ -182,6 +183,8 @@ impl Command for Save {
}
(None, None) => {}
};
child.wait()?;
}
}
@ -270,7 +273,7 @@ impl Command for Save {
}
fn pipe_redirection(&self) -> (Option<OutDest>, Option<OutDest>) {
(Some(OutDest::Capture), Some(OutDest::Capture))
(Some(OutDest::PipeSeparate), Some(OutDest::PipeSeparate))
}
}
@ -480,7 +483,7 @@ fn stream_to_file(
let mut bar = progress_bar::NuProgressBar::new(known_size);
// TODO: reduce the number of progress bar updates?
let mut last_update = Instant::now();
let mut reader = BufReader::new(source);
@ -497,7 +500,10 @@ fn stream_to_file(
let len = buf.len();
reader.consume(len);
bytes_processed += len as u64;
bar.update_bar(bytes_processed);
if last_update.elapsed() >= Duration::from_millis(75) {
bar.update_bar(bytes_processed);
last_update = Instant::now();
}
}
Err(e) if e.kind() == io::ErrorKind::Interrupted => continue,
Err(e) => break Err(e),

View File

@ -58,9 +58,8 @@ impl Command for Start {
open_path(url.as_str(), engine_state, stack, path.span)?;
} else {
// try to distinguish between file not found and opening url without prefix
if let Ok(canon_path) =
canonicalize_with(path_no_whitespace, std::env::current_dir()?.as_path())
{
let cwd = engine_state.cwd(Some(stack))?;
if let Ok(canon_path) = canonicalize_with(path_no_whitespace, cwd) {
open_path(canon_path, engine_state, stack, path.span)?;
} else {
// open crate does not allow opening URL without prefix

View File

@ -1,132 +0,0 @@
use nu_engine::command_prelude::*;
use nu_protocol::{report_shell_warning, ValueIterator};
#[derive(Clone)]
pub struct Group;
impl Command for Group {
fn name(&self) -> &str {
"group"
}
fn signature(&self) -> Signature {
Signature::build("group")
// TODO: It accepts Table also, but currently there is no Table
// example. Perhaps Table should be a subtype of List, in which case
// the current signature would suffice even when a Table example
// exists.
.input_output_types(vec![(
Type::List(Box::new(Type::Any)),
Type::List(Box::new(Type::List(Box::new(Type::Any)))),
)])
.required("group_size", SyntaxShape::Int, "The size of each group.")
.category(Category::Filters)
}
fn description(&self) -> &str {
"Groups input into groups of `group_size`."
}
fn examples(&self) -> Vec<Example> {
let stream_test_1 = vec![
Value::list(
vec![Value::test_int(1), Value::test_int(2)],
Span::test_data(),
),
Value::list(
vec![Value::test_int(3), Value::test_int(4)],
Span::test_data(),
),
];
vec![Example {
example: "[1 2 3 4] | group 2",
description: "Group the a list by pairs",
result: Some(Value::list(stream_test_1, Span::test_data())),
}]
}
fn run(
&self,
engine_state: &EngineState,
stack: &mut Stack,
call: &Call,
input: PipelineData,
) -> Result<PipelineData, ShellError> {
let head = call.head;
report_shell_warning(
engine_state,
&ShellError::Deprecated {
old_command: "group".into(),
new_suggestion: "the new `chunks` command".into(),
span: head,
url: "`help chunks`".into(),
},
);
let group_size: Spanned<usize> = call.req(engine_state, stack, 0)?;
let metadata = input.metadata();
let each_group_iterator = EachGroupIterator {
group_size: group_size.item,
input: Box::new(input.into_iter()),
span: head,
};
Ok(each_group_iterator.into_pipeline_data_with_metadata(
head,
engine_state.signals().clone(),
metadata,
))
}
}
struct EachGroupIterator {
group_size: usize,
input: ValueIterator,
span: Span,
}
impl Iterator for EachGroupIterator {
type Item = Value;
fn next(&mut self) -> Option<Self::Item> {
let mut group = vec![];
let mut current_count = 0;
loop {
let item = self.input.next();
match item {
Some(v) => {
group.push(v);
current_count += 1;
if current_count >= self.group_size {
break;
}
}
None => break,
}
}
if group.is_empty() {
return None;
}
Some(Value::list(group, self.span))
}
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_examples() {
use crate::test_examples;
test_examples(Group {})
}
}

View File

@ -38,21 +38,21 @@ repeating this process with row 1, and so on."#
fn examples(&self) -> Vec<Example> {
vec![
Example {
example: "[a b c] | wrap name | merge ( [1 2 3] | wrap index )",
description: "Add an 'index' column to the input table",
example: "[a b c] | wrap name | merge ( [47 512 618] | wrap id )",
description: "Add an 'id' column to the input table",
result: Some(Value::list(
vec![
Value::test_record(record! {
"name" => Value::test_string("a"),
"index" => Value::test_int(1),
"id" => Value::test_int(47),
}),
Value::test_record(record! {
"name" => Value::test_string("b"),
"index" => Value::test_int(2),
"id" => Value::test_int(512),
}),
Value::test_record(record! {
"name" => Value::test_string("c"),
"index" => Value::test_int(3),
"id" => Value::test_int(618),
}),
],
Span::test_data(),

View File

@ -15,7 +15,6 @@ mod find;
mod first;
mod flatten;
mod get;
mod group;
mod group_by;
mod headers;
mod insert;
@ -73,7 +72,6 @@ pub use find::Find;
pub use first::First;
pub use flatten::Flatten;
pub use get::Get;
pub use group::Group;
pub use group_by::GroupBy;
pub use headers::Headers;
pub use insert::Insert;

View File

@ -1,8 +1,7 @@
use alphanumeric_sort::compare_str;
use nu_engine::command_prelude::*;
use nu_protocol::ast::PathMember;
use nu_utils::IgnoreCaseExt;
use std::cmp::Ordering;
use crate::Comparator;
#[derive(Clone)]
pub struct Sort;
@ -14,10 +13,13 @@ impl Command for Sort {
fn signature(&self) -> nu_protocol::Signature {
Signature::build("sort")
.input_output_types(vec![(
Type::List(Box::new(Type::Any)),
Type::List(Box::new(Type::Any)),
), (Type::record(), Type::record()),])
.input_output_types(vec![
(
Type::List(Box::new(Type::Any)),
Type::List(Box::new(Type::Any))
),
(Type::record(), Type::record())
])
.switch("reverse", "Sort in reverse order", Some('r'))
.switch(
"ignore-case",
@ -45,67 +47,66 @@ impl Command for Sort {
vec![
Example {
example: "[2 0 1] | sort",
description: "sort the list by increasing value",
result: Some(Value::list(
vec![Value::test_int(0), Value::test_int(1), Value::test_int(2)],
Span::test_data(),
)),
description: "Sort the list by increasing value",
result: Some(Value::test_list(vec![
Value::test_int(0),
Value::test_int(1),
Value::test_int(2),
])),
},
Example {
example: "[2 0 1] | sort --reverse",
description: "sort the list by decreasing value",
result: Some(Value::list(
vec![Value::test_int(2), Value::test_int(1), Value::test_int(0)],
Span::test_data(),
)),
description: "Sort the list by decreasing value",
result: Some(Value::test_list(vec![
Value::test_int(2),
Value::test_int(1),
Value::test_int(0),
])),
},
Example {
example: "[betty amy sarah] | sort",
description: "sort a list of strings",
result: Some(Value::list(
vec![
Value::test_string("amy"),
Value::test_string("betty"),
Value::test_string("sarah"),
],
Span::test_data(),
)),
description: "Sort a list of strings",
result: Some(Value::test_list(vec![
Value::test_string("amy"),
Value::test_string("betty"),
Value::test_string("sarah"),
])),
},
Example {
example: "[betty amy sarah] | sort --reverse",
description: "sort a list of strings in reverse",
result: Some(Value::list(
vec![
Value::test_string("sarah"),
Value::test_string("betty"),
Value::test_string("amy"),
],
Span::test_data(),
)),
description: "Sort a list of strings in reverse",
result: Some(Value::test_list(vec![
Value::test_string("sarah"),
Value::test_string("betty"),
Value::test_string("amy"),
])),
},
Example {
description: "Sort strings (case-insensitive)",
example: "[airplane Truck Car] | sort -i",
result: Some(Value::list(
vec![
Value::test_string("airplane"),
Value::test_string("Car"),
Value::test_string("Truck"),
],
Span::test_data(),
)),
result: Some(Value::test_list(vec![
Value::test_string("airplane"),
Value::test_string("Car"),
Value::test_string("Truck"),
])),
},
Example {
description: "Sort strings (reversed case-insensitive)",
example: "[airplane Truck Car] | sort -i -r",
result: Some(Value::list(
vec![
Value::test_string("Truck"),
Value::test_string("Car"),
Value::test_string("airplane"),
],
Span::test_data(),
)),
result: Some(Value::test_list(vec![
Value::test_string("Truck"),
Value::test_string("Car"),
Value::test_string("airplane"),
])),
},
Example {
description: "Sort alphanumeric strings in natural order",
example: "[foo1 foo10 foo9] | sort -n",
result: Some(Value::test_list(vec![
Value::test_string("foo1"),
Value::test_string("foo9"),
Value::test_string("foo10"),
])),
},
Example {
description: "Sort record by key (case-insensitive)",
@ -134,233 +135,65 @@ impl Command for Sort {
call: &Call,
input: PipelineData,
) -> Result<PipelineData, ShellError> {
let head = call.head;
let reverse = call.has_flag(engine_state, stack, "reverse")?;
let insensitive = call.has_flag(engine_state, stack, "ignore-case")?;
let natural = call.has_flag(engine_state, stack, "natural")?;
let sort_by_value = call.has_flag(engine_state, stack, "values")?;
let metadata = input.metadata();
let span = input.span().unwrap_or(call.head);
match input {
// Records have two sorting methods, toggled by presence or absence of -v
PipelineData::Value(Value::Record { val, .. }, ..) => {
let sort_by_value = call.has_flag(engine_state, stack, "values")?;
let record = sort_record(
let value = input.into_value(span)?;
let sorted: Value = match value {
Value::Record { val, .. } => {
// Records have two sorting methods, toggled by presence or absence of -v
let record = crate::sort_record(
val.into_owned(),
span,
sort_by_value,
reverse,
insensitive,
natural,
);
Ok(record.into_pipeline_data())
)?;
Value::record(record, span)
}
// Other values are sorted here
PipelineData::Value(v, ..)
if !matches!(v, Value::List { .. } | Value::Range { .. }) =>
{
Ok(v.into_pipeline_data())
}
pipe_data => {
let mut vec: Vec<_> = pipe_data.into_iter().collect();
sort(&mut vec, head, insensitive, natural)?;
value @ Value::List { .. } => {
// If we have a table specifically, then we want to sort along each column.
// Record's PartialOrd impl dictates that columns are compared in alphabetical order,
// so we have to explicitly compare by each column.
let r#type = value.get_type();
let mut vec = value.into_list().expect("matched list above");
if let Type::Table(cols) = r#type {
let columns: Vec<Comparator> = cols
.iter()
.map(|col| vec![PathMember::string(col.0.clone(), false, Span::unknown())])
.map(|members| CellPath { members })
.map(Comparator::CellPath)
.collect();
crate::sort_by(&mut vec, columns, span, insensitive, natural)?;
} else {
crate::sort(&mut vec, insensitive, natural)?;
}
if reverse {
vec.reverse()
}
let iter = vec.into_iter();
Ok(iter.into_pipeline_data_with_metadata(
head,
engine_state.signals().clone(),
metadata,
))
Value::list(vec, span)
}
}
}
}
fn sort_record(
record: Record,
rec_span: Span,
sort_by_value: bool,
reverse: bool,
insensitive: bool,
natural: bool,
) -> Value {
let mut input_pairs: Vec<(String, Value)> = record.into_iter().collect();
input_pairs.sort_by(|a, b| {
// Extract the data (if sort_by_value) or the column names for comparison
let left_res = if sort_by_value {
match &a.1 {
Value::String { val, .. } => val.clone(),
val => {
if let Ok(val) = val.coerce_string() {
val
} else {
// Values that can't be turned to strings are disregarded by the sort
// (same as in sort_utils.rs)
return Ordering::Equal;
}
}
Value::Nothing { .. } => {
return Err(ShellError::PipelineEmpty {
dst_span: value.span(),
})
}
} else {
a.0.clone()
};
let right_res = if sort_by_value {
match &b.1 {
Value::String { val, .. } => val.clone(),
val => {
if let Ok(val) = val.coerce_string() {
val
} else {
// Values that can't be turned to strings are disregarded by the sort
// (same as in sort_utils.rs)
return Ordering::Equal;
}
}
_ => {
return Err(ShellError::PipelineMismatch {
exp_input_type: "record or list".to_string(),
dst_span: call.head,
src_span: value.span(),
})
}
} else {
b.0.clone()
};
// Fold case if case-insensitive
let left = if insensitive {
left_res.to_folded_case()
} else {
left_res
};
let right = if insensitive {
right_res.to_folded_case()
} else {
right_res
};
if natural {
compare_str(left, right)
} else {
left.cmp(&right)
}
});
if reverse {
input_pairs.reverse();
Ok(sorted.into_pipeline_data_with_metadata(metadata))
}
Value::record(input_pairs.into_iter().collect(), rec_span)
}
pub fn sort(
vec: &mut [Value],
span: Span,
insensitive: bool,
natural: bool,
) -> Result<(), ShellError> {
match vec.first() {
Some(Value::Record { val, .. }) => {
let columns: Vec<String> = val.columns().cloned().collect();
vec.sort_by(|a, b| process(a, b, &columns, span, insensitive, natural));
}
_ => {
vec.sort_by(|a, b| {
let span_a = a.span();
let span_b = b.span();
if insensitive {
let folded_left = match a {
Value::String { val, .. } => Value::string(val.to_folded_case(), span_a),
_ => a.clone(),
};
let folded_right = match b {
Value::String { val, .. } => Value::string(val.to_folded_case(), span_b),
_ => b.clone(),
};
if natural {
match (
folded_left.coerce_into_string(),
folded_right.coerce_into_string(),
) {
(Ok(left), Ok(right)) => compare_str(left, right),
_ => Ordering::Equal,
}
} else {
folded_left
.partial_cmp(&folded_right)
.unwrap_or(Ordering::Equal)
}
} else if natural {
match (a.coerce_str(), b.coerce_str()) {
(Ok(left), Ok(right)) => compare_str(left, right),
_ => Ordering::Equal,
}
} else {
a.partial_cmp(b).unwrap_or(Ordering::Equal)
}
});
}
}
Ok(())
}
pub fn process(
left: &Value,
right: &Value,
columns: &[String],
span: Span,
insensitive: bool,
natural: bool,
) -> Ordering {
for column in columns {
let left_value = left.get_data_by_key(column);
let left_res = match left_value {
Some(left_res) => left_res,
None => Value::nothing(span),
};
let right_value = right.get_data_by_key(column);
let right_res = match right_value {
Some(right_res) => right_res,
None => Value::nothing(span),
};
let result = if insensitive {
let span_left = left_res.span();
let span_right = right_res.span();
let folded_left = match left_res {
Value::String { val, .. } => Value::string(val.to_folded_case(), span_left),
_ => left_res,
};
let folded_right = match right_res {
Value::String { val, .. } => Value::string(val.to_folded_case(), span_right),
_ => right_res,
};
if natural {
match (
folded_left.coerce_into_string(),
folded_right.coerce_into_string(),
) {
(Ok(left), Ok(right)) => compare_str(left, right),
_ => Ordering::Equal,
}
} else {
folded_left
.partial_cmp(&folded_right)
.unwrap_or(Ordering::Equal)
}
} else {
left_res.partial_cmp(&right_res).unwrap_or(Ordering::Equal)
};
if result != Ordering::Equal {
return result;
}
}
Ordering::Equal
}
#[cfg(test)]

View File

@ -1,4 +1,6 @@
use nu_engine::command_prelude::*;
use nu_engine::{command_prelude::*, ClosureEval};
use crate::Comparator;
#[derive(Clone)]
pub struct SortBy;
@ -18,24 +20,37 @@ impl Command for SortBy {
(Type::record(), Type::table()),
(Type::table(), Type::table()),
])
.rest("columns", SyntaxShape::Any, "The column(s) to sort by.")
.rest(
"comparator",
SyntaxShape::OneOf(vec![
SyntaxShape::CellPath,
SyntaxShape::Closure(Some(vec![SyntaxShape::Any])), // key closure
SyntaxShape::Closure(Some(vec![SyntaxShape::Any, SyntaxShape::Any])), // custom closure
]),
"The cell path(s) or closure(s) to compare elements by.",
)
.switch("reverse", "Sort in reverse order", Some('r'))
.switch(
"ignore-case",
"Sort string-based columns case-insensitively",
"Sort string-based data case-insensitively",
Some('i'),
)
.switch(
"natural",
"Sort alphanumeric string-based columns naturally (1, 9, 10, 99, 100, ...)",
"Sort alphanumeric string-based data naturally (1, 9, 10, 99, 100, ...)",
Some('n'),
)
.switch(
"custom",
"Use closures to specify a custom sort order, rather than to compute a comparison key",
Some('c'),
)
.allow_variants_without_examples(true)
.category(Category::Filters)
}
fn description(&self) -> &str {
"Sort by the given columns, in increasing order."
"Sort by the given cell path or closure."
}
fn examples(&self) -> Vec<Example> {
@ -68,6 +83,41 @@ impl Command for SortBy {
}),
])),
},
Example {
description: "Sort by a nested value",
example: "[[name info]; [Cairo {founded: 969}] [Kyoto {founded: 794}]] | sort-by info.founded",
result: Some(Value::test_list(vec![
Value::test_record(record! {
"name" => Value::test_string("Kyoto"),
"info" => Value::test_record(
record! { "founded" => Value::test_int(794) },
)}),
Value::test_record(record! {
"name" => Value::test_string("Cairo"),
"info" => Value::test_record(
record! { "founded" => Value::test_int(969) },
)})
])),
},
Example {
description: "Sort by the last value in a list",
example: "[[2 50] [10 1]] | sort-by { last }",
result: Some(Value::test_list(vec![
Value::test_list(vec![Value::test_int(10), Value::test_int(1)]),
Value::test_list(vec![Value::test_int(2), Value::test_int(50)])
]))
},
Example {
description: "Sort in a custom order",
example: "[7 3 2 8 4] | sort-by -c {|a, b| $a < $b}",
result: Some(Value::test_list(vec![
Value::test_int(2),
Value::test_int(3),
Value::test_int(4),
Value::test_int(7),
Value::test_int(8),
]))
}
]
}
@ -79,39 +129,60 @@ impl Command for SortBy {
input: PipelineData,
) -> Result<PipelineData, ShellError> {
let head = call.head;
let columns: Vec<String> = call.rest(engine_state, stack, 0)?;
let comparator_vals: Vec<Value> = call.rest(engine_state, stack, 0)?;
let reverse = call.has_flag(engine_state, stack, "reverse")?;
let insensitive = call.has_flag(engine_state, stack, "ignore-case")?;
let natural = call.has_flag(engine_state, stack, "natural")?;
let custom = call.has_flag(engine_state, stack, "custom")?;
let metadata = input.metadata();
let mut vec: Vec<_> = input.into_iter_strict(head)?.collect();
if columns.is_empty() {
if comparator_vals.is_empty() {
return Err(ShellError::MissingParameter {
param_name: "columns".into(),
param_name: "comparator".into(),
span: head,
});
}
crate::sort(&mut vec, columns, head, insensitive, natural)?;
let comparators = comparator_vals
.into_iter()
.map(|val| match val {
Value::CellPath { val, .. } => Ok(Comparator::CellPath(val)),
Value::Closure { val, .. } => {
let closure_eval = ClosureEval::new(engine_state, stack, *val);
if custom {
Ok(Comparator::CustomClosure(closure_eval))
} else {
Ok(Comparator::KeyClosure(closure_eval))
}
}
_ => Err(ShellError::TypeMismatch {
err_message: "Cannot sort using a value which is not a cell path or closure"
.into(),
span: val.span(),
}),
})
.collect::<Result<_, _>>()?;
crate::sort_by(&mut vec, comparators, head, insensitive, natural)?;
if reverse {
vec.reverse()
}
let iter = vec.into_iter();
Ok(iter.into_pipeline_data_with_metadata(head, engine_state.signals().clone(), metadata))
let val = Value::list(vec, head);
Ok(val.into_pipeline_data_with_metadata(metadata))
}
}
#[cfg(test)]
mod test {
use crate::{test_examples_with_commands, Last};
use super::*;
#[test]
fn test_examples() {
use crate::test_examples;
test_examples(SortBy {})
test_examples_with_commands(SortBy {}, &[&Last]);
}
}

View File

@ -158,12 +158,12 @@ use it in your pipeline."#
let tee_thread = spawn_tee(info.clone(), eval_block)?;
let tee = IoTee::new(stderr, tee_thread);
match stack.stderr() {
OutDest::Pipe | OutDest::Capture => {
OutDest::Pipe | OutDest::PipeSeparate | OutDest::Value => {
child.stderr = Some(ChildPipe::Tee(Box::new(tee)));
Ok(None)
}
OutDest::Null => copy_on_thread(tee, io::sink(), &info).map(Some),
OutDest::Inherit => {
OutDest::Print | OutDest::Inherit => {
copy_on_thread(tee, io::stderr(), &info).map(Some)
}
OutDest::File(file) => {
@ -176,12 +176,14 @@ use it in your pipeline."#
if let Some(stdout) = child.stdout.take() {
match stack.stdout() {
OutDest::Pipe | OutDest::Capture => {
OutDest::Pipe | OutDest::PipeSeparate | OutDest::Value => {
child.stdout = Some(stdout);
Ok(())
}
OutDest::Null => copy_pipe(stdout, io::sink(), &info),
OutDest::Inherit => copy_pipe(stdout, io::stdout(), &info),
OutDest::Print | OutDest::Inherit => {
copy_pipe(stdout, io::stdout(), &info)
}
OutDest::File(file) => copy_pipe(stdout, file.as_ref(), &info),
}?;
}
@ -191,14 +193,14 @@ use it in your pipeline."#
let stderr_thread = if let Some(stderr) = child.stderr.take() {
let info = info.clone();
match stack.stderr() {
OutDest::Pipe | OutDest::Capture => {
OutDest::Pipe | OutDest::PipeSeparate | OutDest::Value => {
child.stderr = Some(stderr);
Ok(None)
}
OutDest::Null => {
copy_pipe_on_thread(stderr, io::sink(), &info).map(Some)
}
OutDest::Inherit => {
OutDest::Print | OutDest::Inherit => {
copy_pipe_on_thread(stderr, io::stderr(), &info).map(Some)
}
OutDest::File(file) => {
@ -213,12 +215,12 @@ use it in your pipeline."#
let tee_thread = spawn_tee(info.clone(), eval_block)?;
let tee = IoTee::new(stdout, tee_thread);
match stack.stdout() {
OutDest::Pipe | OutDest::Capture => {
OutDest::Pipe | OutDest::PipeSeparate | OutDest::Value => {
child.stdout = Some(ChildPipe::Tee(Box::new(tee)));
Ok(())
}
OutDest::Null => copy(tee, io::sink(), &info),
OutDest::Inherit => copy(tee, io::stdout(), &info),
OutDest::Print | OutDest::Inherit => copy(tee, io::stdout(), &info),
OutDest::File(file) => copy(tee, file.as_ref(), &info),
}?;
}
@ -280,7 +282,7 @@ use it in your pipeline."#
}
fn pipe_redirection(&self) -> (Option<OutDest>, Option<OutDest>) {
(Some(OutDest::Capture), Some(OutDest::Capture))
(Some(OutDest::PipeSeparate), Some(OutDest::PipeSeparate))
}
}

View File

@ -25,7 +25,7 @@ impl Command for Transpose {
])
.switch(
"header-row",
"treat the first row as column names",
"use the first input column as the table header-row (or keynames when combined with --as-record)",
Some('r'),
)
.switch(

View File

@ -57,31 +57,34 @@ impl Command for Wrap {
vec![
Example {
description: "Wrap a list into a table with a given column name",
example: "[1 2 3] | wrap num",
example: "[ Pachisi Mahjong Catan Carcassonne ] | wrap game",
result: Some(Value::test_list(vec![
Value::test_record(record! {
"num" => Value::test_int(1),
"game" => Value::test_string("Pachisi"),
}),
Value::test_record(record! {
"num" => Value::test_int(2),
"game" => Value::test_string("Mahjong"),
}),
Value::test_record(record! {
"num" => Value::test_int(3),
"game" => Value::test_string("Catan"),
}),
Value::test_record(record! {
"game" => Value::test_string("Carcassonne"),
}),
])),
},
Example {
description: "Wrap a range into a table with a given column name",
example: "1..3 | wrap num",
example: "4..6 | wrap num",
result: Some(Value::test_list(vec![
Value::test_record(record! {
"num" => Value::test_int(1),
"num" => Value::test_int(4),
}),
Value::test_record(record! {
"num" => Value::test_int(2),
"num" => Value::test_int(5),
}),
Value::test_record(record! {
"num" => Value::test_int(3),
"num" => Value::test_int(6),
}),
])),
},

View File

@ -118,7 +118,7 @@ fn local_into_string(value: Value, separator: &str, config: &Config) -> String {
.map(|(x, y)| format!("{}: {}", x, local_into_string(y, ", ", config)))
.collect::<Vec<_>>()
.join(separator),
Value::Closure { val, .. } => format!("<Closure {}>", val.block_id),
Value::Closure { val, .. } => format!("<Closure {}>", val.block_id.get()),
Value::Nothing { .. } => String::new(),
Value::Error { error, .. } => format!("{error:?}"),
Value::Binary { val, .. } => format!("{val:?}"),

View File

@ -49,6 +49,7 @@ where
.category(Category::Hash)
.input_output_types(vec![
(Type::String, Type::Any),
(Type::Binary, Type::Any),
(Type::table(), Type::table()),
(Type::record(), Type::record()),
])

View File

@ -1,5 +1,5 @@
use nu_engine::{command_prelude::*, get_eval_block_with_early_return};
use nu_protocol::engine::CommandType;
use nu_protocol::{engine::CommandType, BlockId};
/// Source a file for environment variables.
#[derive(Clone)]
@ -44,7 +44,8 @@ impl Command for Source {
// Note: this hidden positional is the block_id that corresponded to the 0th position
// it is put here by the parser
let block_id: i64 = call.req_parser_info(engine_state, stack, "block_id")?;
let block = engine_state.get_block(block_id as usize).clone();
let block_id = BlockId::new(block_id as usize);
let block = engine_state.get_block(block_id).clone();
let eval_block_with_early_return = get_eval_block_with_early_return(engine_state);

View File

@ -314,7 +314,7 @@ fn send_form_request(
Value::List { ref vals, .. } => {
if vals.len() % 2 != 0 {
return Err(ShellErrorOrRequestError::ShellError(ShellError::IncorrectValue {
msg: "Body type 'list' for form requests requires paired values. E.g.: [foo, 10]".into(),
msg: "Body type 'list' for form requests requires paired values. E.g.: [foo, 10]".into(),
val_span: body.span(),
call_span: span,
}));
@ -901,6 +901,7 @@ fn retrieve_http_proxy_from_env(engine_state: &EngineState, stack: &mut Stack) -
.or(stack.get_env_var(engine_state, "https_proxy"))
.or(stack.get_env_var(engine_state, "HTTPS_PROXY"))
.or(stack.get_env_var(engine_state, "ALL_PROXY"))
.cloned()
.and_then(|proxy| proxy.coerce_into_string().ok())
}

View File

@ -300,14 +300,14 @@ impl UrlComponents {
return Ok(true);
}
match key {
"host" => Err(ShellError::UnsupportedConfigValue {
expected: "non-empty string".into(),
value: "empty string".into(),
"host" => Err(ShellError::InvalidValue {
valid: "a non-empty string".into(),
actual: format!("'{s}'"),
span: value_span,
}),
"scheme" => Err(ShellError::UnsupportedConfigValue {
expected: "non-empty string".into(),
value: "empty string".into(),
"scheme" => Err(ShellError::InvalidValue {
valid: "a non-empty string".into(),
actual: format!("'{s}'"),
span: value_span,
}),
_ => Ok(false),

View File

@ -2,7 +2,7 @@ use crossterm::event::{
DisableBracketedPaste, DisableFocusChange, DisableMouseCapture, EnableBracketedPaste,
EnableMouseCapture, KeyCode, KeyEventKind, KeyModifiers, MouseEvent, MouseEventKind,
};
use crossterm::terminal;
use crossterm::{execute, terminal};
use nu_engine::command_prelude::*;
use num_traits::AsPrimitive;
@ -81,8 +81,36 @@ There are 4 `key_type` variants:
let head = call.head;
let event_type_filter = get_event_type_filter(engine_state, stack, call, head)?;
let add_raw = call.has_flag(engine_state, stack, "raw")?;
let config = engine_state.get_config();
terminal::enable_raw_mode()?;
if config.use_kitty_protocol {
if let Ok(false) = crossterm::terminal::supports_keyboard_enhancement() {
println!("WARN: The terminal doesn't support use_kitty_protocol config.\r");
}
// enable kitty protocol
//
// Note that, currently, only the following support this protocol:
// * [kitty terminal](https://sw.kovidgoyal.net/kitty/)
// * [foot terminal](https://codeberg.org/dnkl/foot/issues/319)
// * [WezTerm terminal](https://wezfurlong.org/wezterm/config/lua/config/enable_kitty_keyboard.html)
// * [notcurses library](https://github.com/dankamongmen/notcurses/issues/2131)
// * [neovim text editor](https://github.com/neovim/neovim/pull/18181)
// * [kakoune text editor](https://github.com/mawww/kakoune/issues/4103)
// * [dte text editor](https://gitlab.com/craigbarnes/dte/-/issues/138)
// * [ghostty terminal](https://github.com/ghostty-org/ghostty/pull/317)
//
// Refer to https://sw.kovidgoyal.net/kitty/keyboard-protocol/ if you're curious.
let _ = execute!(
stdout(),
crossterm::event::PushKeyboardEnhancementFlags(
crossterm::event::KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES
)
);
}
let console_state = event_type_filter.enable_events()?;
loop {
let event = crossterm::event::read().map_err(|_| ShellError::GenericError {
@ -95,6 +123,13 @@ There are 4 `key_type` variants:
let event = parse_event(head, &event, &event_type_filter, add_raw);
if let Some(event) = event {
terminal::disable_raw_mode()?;
if config.use_kitty_protocol {
let _ = execute!(
std::io::stdout(),
crossterm::event::PopKeyboardEnhancementFlags
);
}
console_state.restore();
return Ok(event.into_pipeline_data());
}

View File

@ -14,7 +14,11 @@ impl Command for SubCommand {
Signature::build("random binary")
.input_output_types(vec![(Type::Nothing, Type::Binary)])
.allow_variants_without_examples(true)
.required("length", SyntaxShape::Int, "Length of the output binary.")
.required(
"length",
SyntaxShape::OneOf(vec![SyntaxShape::Int, SyntaxShape::Filesize]),
"Length of the output binary.",
)
.category(Category::Random)
}
@ -43,11 +47,18 @@ impl Command for SubCommand {
}
fn examples(&self) -> Vec<Example> {
vec![Example {
description: "Generate 16 random bytes",
example: "random binary 16",
result: None,
}]
vec![
Example {
description: "Generate 16 random bytes",
example: "random binary 16",
result: None,
},
Example {
description: "Generate 1 random kilobyte",
example: "random binary 1kb",
result: None,
},
]
}
}

View File

@ -21,7 +21,7 @@ impl Command for SubCommand {
.allow_variants_without_examples(true)
.named(
"length",
SyntaxShape::Int,
SyntaxShape::OneOf(vec![SyntaxShape::Int, SyntaxShape::Filesize]),
"Number of chars (default 25)",
Some('l'),
)
@ -58,6 +58,11 @@ impl Command for SubCommand {
example: "random chars --length 20",
result: None,
},
Example {
description: "Generate one kilobyte of random chars",
example: "random chars --length 1kb",
result: None,
},
]
}
}

View File

@ -1,351 +1,286 @@
use alphanumeric_sort::compare_str;
use nu_engine::column::nonexistent_column;
use nu_protocol::{ShellError, Span, Value};
use nu_engine::ClosureEval;
use nu_protocol::{ast::CellPath, PipelineData, Record, ShellError, Span, Value};
use nu_utils::IgnoreCaseExt;
use std::cmp::Ordering;
// This module includes sorting functionality that is useful in sort-by and elsewhere.
// Eventually it would be nice to find a better home for it; sorting logic is only coupled
// to commands for historical reasons.
/// A specification of sort order for `sort_by`.
///
/// A closure comparator allows the user to return custom ordering to sort by.
/// A cell path comparator uses the value referred to by the cell path as the sorting key.
pub enum Comparator {
KeyClosure(ClosureEval),
CustomClosure(ClosureEval),
CellPath(CellPath),
}
/// Sort a value. This only makes sense for lists and list-like things,
/// so for everything else we just return the value as-is.
/// CustomValues are converted to their base value and then sorted.
pub fn sort_value(
val: &Value,
sort_columns: Vec<String>,
ascending: bool,
insensitive: bool,
natural: bool,
) -> Result<Value, ShellError> {
let span = val.span();
match val {
Value::List { vals, .. } => {
let mut vals = vals.clone();
sort(&mut vals, sort_columns, span, insensitive, natural)?;
/// Sort a slice of `Value`s.
///
/// Sort has the following invariants, in order of precedence:
/// - Null values (Nothing type) are always sorted to the end.
/// - For natural sort, numeric values (numeric strings, ints, and floats) appear first, sorted by numeric value
/// - Values appear by order of `Value`'s `PartialOrd`.
/// - Sorting for values with equal ordering is stable.
///
/// Generally, values of different types are ordered by order of appearance in the `Value` enum.
/// However, this is not always the case. For example, ints and floats will be grouped together since
/// `Value`'s `PartialOrd` defines a non-decreasing ordering between non-decreasing integers and floats.
pub fn sort(vec: &mut [Value], insensitive: bool, natural: bool) -> Result<(), ShellError> {
// allow the comparator function to indicate error
// by mutating this option captured by the closure,
// since sort_by closure must be infallible
let mut compare_err: Option<ShellError> = None;
if !ascending {
vals.reverse();
}
Ok(Value::list(vals, span))
vec.sort_by(|a, b| {
// we've already hit an error, bail out now
if compare_err.is_some() {
return Ordering::Equal;
}
Value::Custom { val, .. } => {
let base_val = val.to_base_value(span)?;
sort_value(&base_val, sort_columns, ascending, insensitive, natural)
}
_ => Ok(val.to_owned()),
compare_values(a, b, insensitive, natural).unwrap_or_else(|err| {
compare_err.get_or_insert(err);
Ordering::Equal
})
});
if let Some(err) = compare_err {
Err(err)
} else {
Ok(())
}
}
/// Sort a value in-place. This is more efficient than sort_value() because it
/// avoids cloning, but it does not work for CustomValues; they are returned as-is.
pub fn sort_value_in_place(
val: &mut Value,
sort_columns: Vec<String>,
ascending: bool,
insensitive: bool,
natural: bool,
) -> Result<(), ShellError> {
let span = val.span();
if let Value::List { vals, .. } = val {
sort(vals, sort_columns, span, insensitive, natural)?;
if !ascending {
vals.reverse();
}
}
Ok(())
}
pub fn sort(
/// Sort a slice of `Value`s by criteria specified by one or multiple `Comparator`s.
pub fn sort_by(
vec: &mut [Value],
sort_columns: Vec<String>,
span: Span,
mut comparators: Vec<Comparator>,
head_span: Span,
insensitive: bool,
natural: bool,
) -> Result<(), ShellError> {
let val_span = vec.first().map(|v| v.span()).unwrap_or(span);
match vec.first() {
Some(Value::Record { val: record, .. }) => {
if sort_columns.is_empty() {
// This uses the same format as the 'requires a column name' error in split_by.rs
return Err(ShellError::GenericError {
error: "expected name".into(),
msg: "requires a column name to sort table data".into(),
span: Some(span),
help: None,
inner: vec![],
});
}
if let Some(nonexistent) = nonexistent_column(&sort_columns, record.columns()) {
return Err(ShellError::CantFindColumn {
col_name: nonexistent,
span: Some(span),
src_span: val_span,
});
}
// check to make sure each value in each column in the record
// that we asked for is a string. So, first collect all the columns
// that we asked for into vals, then later make sure they're all
// strings.
let mut vals = vec![];
for item in vec.iter() {
for col in &sort_columns {
let val = item
.get_data_by_key(col)
.unwrap_or_else(|| Value::nothing(Span::unknown()));
vals.push(val);
}
}
let should_sort_case_insensitively = insensitive
&& vals
.iter()
.all(|x| matches!(x.get_type(), nu_protocol::Type::String));
let should_sort_case_naturally = natural
&& vals
.iter()
.all(|x| matches!(x.get_type(), nu_protocol::Type::String));
vec.sort_by(|a, b| {
compare(
a,
b,
&sort_columns,
span,
should_sort_case_insensitively,
should_sort_case_naturally,
)
});
}
_ => {
vec.sort_by(|a, b| {
if insensitive {
let span_a = a.span();
let span_b = b.span();
let folded_left = match a {
Value::String { val, .. } => Value::string(val.to_folded_case(), span_a),
_ => a.clone(),
};
let folded_right = match b {
Value::String { val, .. } => Value::string(val.to_folded_case(), span_b),
_ => b.clone(),
};
if natural {
match (
folded_left.coerce_into_string(),
folded_right.coerce_into_string(),
) {
(Ok(left), Ok(right)) => compare_str(left, right),
_ => Ordering::Equal,
}
} else {
folded_left
.partial_cmp(&folded_right)
.unwrap_or(Ordering::Equal)
}
} else if natural {
match (a.coerce_str(), b.coerce_str()) {
(Ok(left), Ok(right)) => compare_str(left, right),
_ => Ordering::Equal,
}
} else {
a.partial_cmp(b).unwrap_or(Ordering::Equal)
}
});
}
if comparators.is_empty() {
// This uses the same format as the 'requires a column name' error in split_by.rs
return Err(ShellError::GenericError {
error: "expected name".into(),
msg: "requires a cell path or closure to sort data".into(),
span: Some(head_span),
help: None,
inner: vec![],
});
}
// allow the comparator function to indicate error
// by mutating this option captured by the closure,
// since sort_by closure must be infallible
let mut compare_err: Option<ShellError> = None;
vec.sort_by(|a, b| {
compare_by(
a,
b,
&mut comparators,
head_span,
insensitive,
natural,
&mut compare_err,
)
});
if let Some(err) = compare_err {
Err(err)
} else {
Ok(())
}
Ok(())
}
pub fn compare(
/// Sort a record's key-value pairs.
///
/// Can sort by key or by value.
pub fn sort_record(
record: Record,
sort_by_value: bool,
reverse: bool,
insensitive: bool,
natural: bool,
) -> Result<Record, ShellError> {
let mut input_pairs: Vec<(String, Value)> = record.into_iter().collect();
// allow the comparator function to indicate error
// by mutating this option captured by the closure,
// since sort_by closure must be infallible
let mut compare_err: Option<ShellError> = None;
if sort_by_value {
input_pairs.sort_by(|a, b| {
// we've already hit an error, bail out now
if compare_err.is_some() {
return Ordering::Equal;
}
compare_values(&a.1, &b.1, insensitive, natural).unwrap_or_else(|err| {
compare_err.get_or_insert(err);
Ordering::Equal
})
});
} else {
input_pairs.sort_by(|a, b| compare_strings(&a.0, &b.0, insensitive, natural));
};
if let Some(err) = compare_err {
return Err(err);
}
if reverse {
input_pairs.reverse()
}
Ok(input_pairs.into_iter().collect())
}
pub fn compare_by(
left: &Value,
right: &Value,
columns: &[String],
comparators: &mut [Comparator],
span: Span,
insensitive: bool,
natural: bool,
error: &mut Option<ShellError>,
) -> Ordering {
for column in columns {
let left_value = left.get_data_by_key(column);
let left_res = match left_value {
Some(left_res) => left_res,
None => Value::nothing(span),
};
let right_value = right.get_data_by_key(column);
let right_res = match right_value {
Some(right_res) => right_res,
None => Value::nothing(span),
};
let result = if insensitive {
let span_left = left_res.span();
let span_right = right_res.span();
let folded_left = match left_res {
Value::String { val, .. } => Value::string(val.to_folded_case(), span_left),
_ => left_res,
};
let folded_right = match right_res {
Value::String { val, .. } => Value::string(val.to_folded_case(), span_right),
_ => right_res,
};
if natural {
match (
folded_left.coerce_into_string(),
folded_right.coerce_into_string(),
) {
(Ok(left), Ok(right)) => compare_str(left, right),
_ => Ordering::Equal,
}
} else {
folded_left
.partial_cmp(&folded_right)
.unwrap_or(Ordering::Equal)
// we've already hit an error, bail out now
if error.is_some() {
return Ordering::Equal;
}
for cmp in comparators.iter_mut() {
let result = match cmp {
Comparator::CellPath(cell_path) => {
compare_cell_path(left, right, cell_path, insensitive, natural)
}
} else if natural {
match (
left_res.coerce_into_string(),
right_res.coerce_into_string(),
) {
(Ok(left), Ok(right)) => compare_str(left, right),
_ => Ordering::Equal,
Comparator::KeyClosure(closure) => {
compare_key_closure(left, right, closure, span, insensitive, natural)
}
Comparator::CustomClosure(closure) => {
compare_custom_closure(left, right, closure, span)
}
} else {
left_res.partial_cmp(&right_res).unwrap_or(Ordering::Equal)
};
if result != Ordering::Equal {
return result;
match result {
Ok(Ordering::Equal) => {}
Ok(ordering) => return ordering,
Err(err) => {
// don't bother continuing through the remaining comparators as we've hit an error
// don't overwrite if there's an existing error
error.get_or_insert(err);
return Ordering::Equal;
}
}
}
Ordering::Equal
}
#[cfg(test)]
mod tests {
use super::*;
use nu_protocol::{record, Value};
/// Determines whether a value should be sorted as a string
///
/// If we're natural sorting, we want to sort strings, integers, and floats alphanumerically, so we should string sort.
/// Otherwise, we only want to string sort if both values are strings or globs (to enable case insensitive comparison)
fn should_sort_as_string(val: &Value, natural: bool) -> bool {
matches!(
(val, natural),
(&Value::String { .. }, _)
| (&Value::Glob { .. }, _)
| (&Value::Int { .. }, true)
| (&Value::Float { .. }, true)
)
}
#[test]
fn test_sort_value() {
let val = Value::test_list(vec![
Value::test_record(record! {
"fruit" => Value::test_string("pear"),
"count" => Value::test_int(3),
}),
Value::test_record(record! {
"fruit" => Value::test_string("orange"),
"count" => Value::test_int(7),
}),
Value::test_record(record! {
"fruit" => Value::test_string("apple"),
"count" => Value::test_int(9),
}),
]);
/// Simple wrapper around `should_sort_as_string` to determine if two values
/// should be compared as strings.
fn should_string_compare(left: &Value, right: &Value, natural: bool) -> bool {
should_sort_as_string(left, natural) && should_sort_as_string(right, natural)
}
let sorted_alphabetically =
sort_value(&val, vec!["fruit".to_string()], true, false, false).unwrap();
assert_eq!(
sorted_alphabetically,
Value::test_list(vec![
Value::test_record(record! {
"fruit" => Value::test_string("apple"),
"count" => Value::test_int(9),
}),
Value::test_record(record! {
"fruit" => Value::test_string("orange"),
"count" => Value::test_int(7),
}),
Value::test_record(record! {
"fruit" => Value::test_string("pear"),
"count" => Value::test_int(3),
}),
],)
);
let sorted_by_count_desc =
sort_value(&val, vec!["count".to_string()], false, false, false).unwrap();
assert_eq!(
sorted_by_count_desc,
Value::test_list(vec![
Value::test_record(record! {
"fruit" => Value::test_string("apple"),
"count" => Value::test_int(9),
}),
Value::test_record(record! {
"fruit" => Value::test_string("orange"),
"count" => Value::test_int(7),
}),
Value::test_record(record! {
"fruit" => Value::test_string("pear"),
"count" => Value::test_int(3),
}),
],)
);
}
#[test]
fn test_sort_value_in_place() {
let mut val = Value::test_list(vec![
Value::test_record(record! {
"fruit" => Value::test_string("pear"),
"count" => Value::test_int(3),
}),
Value::test_record(record! {
"fruit" => Value::test_string("orange"),
"count" => Value::test_int(7),
}),
Value::test_record(record! {
"fruit" => Value::test_string("apple"),
"count" => Value::test_int(9),
}),
]);
sort_value_in_place(&mut val, vec!["fruit".to_string()], true, false, false).unwrap();
assert_eq!(
val,
Value::test_list(vec![
Value::test_record(record! {
"fruit" => Value::test_string("apple"),
"count" => Value::test_int(9),
}),
Value::test_record(record! {
"fruit" => Value::test_string("orange"),
"count" => Value::test_int(7),
}),
Value::test_record(record! {
"fruit" => Value::test_string("pear"),
"count" => Value::test_int(3),
}),
],)
);
sort_value_in_place(&mut val, vec!["count".to_string()], false, false, false).unwrap();
assert_eq!(
val,
Value::test_list(vec![
Value::test_record(record! {
"fruit" => Value::test_string("apple"),
"count" => Value::test_int(9),
}),
Value::test_record(record! {
"fruit" => Value::test_string("orange"),
"count" => Value::test_int(7),
}),
Value::test_record(record! {
"fruit" => Value::test_string("pear"),
"count" => Value::test_int(3),
}),
],)
);
pub fn compare_values(
left: &Value,
right: &Value,
insensitive: bool,
natural: bool,
) -> Result<Ordering, ShellError> {
if should_string_compare(left, right, natural) {
Ok(compare_strings(
&left.coerce_str()?,
&right.coerce_str()?,
insensitive,
natural,
))
} else {
Ok(left.partial_cmp(right).unwrap_or(Ordering::Equal))
}
}
pub fn compare_strings(left: &str, right: &str, insensitive: bool, natural: bool) -> Ordering {
fn compare_inner<T>(left: T, right: T, natural: bool) -> Ordering
where
T: AsRef<str> + Ord,
{
if natural {
alphanumeric_sort::compare_str(left, right)
} else {
left.cmp(&right)
}
}
// only allocate a String if necessary for case folding
if insensitive {
compare_inner(left.to_folded_case(), right.to_folded_case(), natural)
} else {
compare_inner(left, right, natural)
}
}
pub fn compare_cell_path(
left: &Value,
right: &Value,
cell_path: &CellPath,
insensitive: bool,
natural: bool,
) -> Result<Ordering, ShellError> {
let left = left.clone().follow_cell_path(&cell_path.members, false)?;
let right = right.clone().follow_cell_path(&cell_path.members, false)?;
compare_values(&left, &right, insensitive, natural)
}
pub fn compare_key_closure(
left: &Value,
right: &Value,
closure_eval: &mut ClosureEval,
span: Span,
insensitive: bool,
natural: bool,
) -> Result<Ordering, ShellError> {
let left_key = closure_eval
.run_with_value(left.clone())?
.into_value(span)?;
let right_key = closure_eval
.run_with_value(right.clone())?
.into_value(span)?;
compare_values(&left_key, &right_key, insensitive, natural)
}
pub fn compare_custom_closure(
left: &Value,
right: &Value,
closure_eval: &mut ClosureEval,
span: Span,
) -> Result<Ordering, ShellError> {
closure_eval
.add_arg(left.clone())
.add_arg(right.clone())
.run_with_input(PipelineData::Value(
Value::list(vec![left.clone(), right.clone()], span),
None,
))
.and_then(|data| data.into_value(span))
.map(|val| {
if val.is_true() {
Ordering::Less
} else {
Ordering::Greater
}
})
}

View File

@ -38,11 +38,11 @@ pub struct DecodeBase64;
impl Command for DecodeBase64 {
fn name(&self) -> &str {
"decode new-base64"
"decode base64"
}
fn signature(&self) -> Signature {
Signature::build("decode new-base64")
Signature::build("decode base64")
.input_output_types(vec![(Type::String, Type::Binary)])
.allow_variants_without_examples(true)
.switch("url", "Decode the URL-safe Base64 version.", None)
@ -62,17 +62,17 @@ impl Command for DecodeBase64 {
vec![
Example {
description: "Decode a Base64 string",
example: r#""U29tZSBEYXRh" | decode new-base64 | decode"#,
example: r#""U29tZSBEYXRh" | decode base64 | decode"#,
result: None,
},
Example {
description: "Decode arbitrary data",
example: r#""/w==" | decode new-base64"#,
example: r#""/w==" | decode base64"#,
result: Some(Value::test_binary(vec![0xFF])),
},
Example {
description: "Decode a URL-safe Base64 string",
example: r#""_w==" | decode new-base64 --url"#,
example: r#""_w==" | decode base64 --url"#,
result: Some(Value::test_binary(vec![0xFF])),
},
]
@ -109,11 +109,11 @@ pub struct EncodeBase64;
impl Command for EncodeBase64 {
fn name(&self) -> &str {
"encode new-base64"
"encode base64"
}
fn signature(&self) -> Signature {
Signature::build("encode new-base64")
Signature::build("encode base64")
.input_output_types(vec![
(Type::String, Type::String),
(Type::Binary, Type::String),
@ -135,17 +135,17 @@ impl Command for EncodeBase64 {
vec![
Example {
description: "Encode a string with Base64",
example: r#""Alphabet from A to Z" | encode new-base64"#,
example: r#""Alphabet from A to Z" | encode base64"#,
result: Some(Value::test_string("QWxwaGFiZXQgZnJvbSBBIHRvIFo=")),
},
Example {
description: "Encode arbitrary data",
example: r#"0x[BE EE FF] | encode new-base64"#,
example: r#"0x[BE EE FF] | encode base64"#,
result: Some(Value::test_string("vu7/")),
},
Example {
description: "Use a URL-safe alphabet",
example: r#"0x[BE EE FF] | encode new-base64 --url"#,
example: r#"0x[BE EE FF] | encode base64 --url"#,
result: Some(Value::test_string("vu7_")),
},
]

View File

@ -1,377 +0,0 @@
use base64::{
alphabet,
engine::{
general_purpose::{NO_PAD, PAD},
GeneralPurpose,
},
Engine,
};
use nu_cmd_base::input_handler::{operate as general_operate, CmdArgument};
use nu_protocol::{
ast::CellPath,
engine::{Call, EngineState},
PipelineData, ShellError, Span, Spanned, Value,
};
pub const CHARACTER_SET_DESC: &str = "specify the character rules for encoding the input.\n\
\tValid values are 'standard', 'standard-no-padding', 'url-safe', 'url-safe-no-padding',\
'binhex', 'bcrypt', 'crypt', 'mutf7'";
#[derive(Clone)]
pub struct Base64Config {
pub character_set: Spanned<String>,
pub action_type: ActionType,
}
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum ActionType {
Encode,
Decode,
}
struct Arguments {
cell_paths: Option<Vec<CellPath>>,
binary: bool,
encoding_config: Base64Config,
}
impl CmdArgument for Arguments {
fn take_cell_paths(&mut self) -> Option<Vec<CellPath>> {
self.cell_paths.take()
}
}
pub(super) struct Base64CommandArguments {
pub(super) character_set: Option<Spanned<String>>,
pub(super) action_type: ActionType,
pub(super) binary: bool,
}
pub fn operate(
engine_state: &EngineState,
call: &Call,
input: PipelineData,
cell_paths: Vec<CellPath>,
args: Base64CommandArguments,
) -> Result<PipelineData, ShellError> {
let head = call.head;
let cell_paths = (!cell_paths.is_empty()).then_some(cell_paths);
// Default the character set to standard if the argument is not specified.
let character_set = match args.character_set {
Some(inner_tag) => inner_tag,
None => Spanned {
item: "standard".to_string(),
span: head, // actually this span is always useless, because default character_set is always valid.
},
};
let args = Arguments {
encoding_config: Base64Config {
character_set,
action_type: args.action_type,
},
binary: args.binary,
cell_paths,
};
general_operate(action, args, input, call.head, engine_state.signals())
}
fn action(
input: &Value,
// only used for `decode` action
args: &Arguments,
command_span: Span,
) -> Value {
let base64_config = &args.encoding_config;
let output_binary = args.binary;
let config_character_set = &base64_config.character_set;
let base64_engine: GeneralPurpose = match config_character_set.item.as_str() {
"standard" => GeneralPurpose::new(&alphabet::STANDARD, PAD),
"standard-no-padding" => GeneralPurpose::new(&alphabet::STANDARD, NO_PAD),
"url-safe" => GeneralPurpose::new(&alphabet::URL_SAFE, PAD),
"url-safe-no-padding" => GeneralPurpose::new(&alphabet::URL_SAFE, NO_PAD),
"bcrypt" => GeneralPurpose::new(&alphabet::BCRYPT, NO_PAD),
"binhex" => GeneralPurpose::new(&alphabet::BIN_HEX, NO_PAD),
"crypt" => GeneralPurpose::new(&alphabet::CRYPT, NO_PAD),
"mutf7" => GeneralPurpose::new(&alphabet::IMAP_MUTF7, NO_PAD),
not_valid => return Value::error (
ShellError::GenericError {
error: "value is not an accepted character set".into(),
msg: format!(
"{not_valid} is not a valid character-set.\nPlease use `help encode base64` to see a list of valid character sets."
),
span: Some(config_character_set.span),
help: None,
inner: vec![],
}, config_character_set.span)
};
let value_span = input.span();
match input {
// Propagate existing errors.
Value::Error { .. } => input.clone(),
Value::Binary { val, .. } => match base64_config.action_type {
ActionType::Encode => {
let mut enc_vec = vec![0; val.len() * 4 / 3 + 4];
let bytes_written = match base64_engine.encode_slice(val, &mut enc_vec) {
Ok(bytes_written) => bytes_written,
Err(e) => {
return Value::error(
ShellError::GenericError {
error: "Error encoding data".into(),
msg: e.to_string(),
span: Some(value_span),
help: None,
inner: vec![],
},
value_span,
)
}
};
enc_vec.truncate(bytes_written);
Value::string(std::str::from_utf8(&enc_vec).unwrap_or(""), command_span)
}
ActionType::Decode => Value::error(
ShellError::UnsupportedInput {
msg: "Binary data can only be encoded".to_string(),
input: "value originates from here".into(),
msg_span: command_span,
input_span: input.span(),
},
command_span,
),
},
Value::String { val, .. } => {
match base64_config.action_type {
ActionType::Encode => {
let mut enc_str = String::new();
base64_engine.encode_string(val, &mut enc_str);
Value::string(enc_str, command_span)
}
ActionType::Decode => {
// for decode, input val may contains invalid new line character, which is ok to omitted them by default.
let val = val.clone();
let val = val.replace("\r\n", "").replace('\n', "");
match base64_engine.decode(val) {
Ok(decoded_value) => {
if output_binary {
Value::binary(decoded_value, command_span)
} else {
match String::from_utf8(decoded_value) {
Ok(string_value) => Value::string(string_value, command_span),
Err(e) => Value::error(
ShellError::GenericError {
error: "base64 payload isn't a valid utf-8 sequence"
.into(),
msg: e.to_string(),
span: Some(value_span),
help: Some(
"consider using the `--binary` flag".to_owned(),
),
inner: vec![],
},
value_span,
),
}
}
}
Err(_) => Value::error(
ShellError::GenericError {
error: "value could not be base64 decoded".into(),
msg: format!(
"invalid base64 input for character set {}",
&config_character_set.item
),
span: Some(command_span),
help: None,
inner: vec![],
},
command_span,
),
}
}
}
}
other => Value::error(
ShellError::TypeMismatch {
err_message: format!("string or binary, not {}", other.get_type()),
span: other.span(),
},
other.span(),
),
}
}
#[cfg(test)]
mod tests {
use super::{action, ActionType, Arguments, Base64Config};
use nu_protocol::{Span, Spanned, Value};
#[test]
fn base64_encode_standard() {
let word = Value::test_string("Some Data Padding");
let expected = Value::test_string("U29tZSBEYXRhIFBhZGRpbmc=");
let actual = action(
&word,
&Arguments {
encoding_config: Base64Config {
character_set: Spanned {
item: "standard".to_string(),
span: Span::test_data(),
},
action_type: ActionType::Encode,
},
binary: true,
cell_paths: None,
},
Span::test_data(),
);
assert_eq!(actual, expected);
}
#[test]
fn base64_encode_standard_no_padding() {
let word = Value::test_string("Some Data Padding");
let expected = Value::test_string("U29tZSBEYXRhIFBhZGRpbmc");
let actual = action(
&word,
&Arguments {
encoding_config: Base64Config {
character_set: Spanned {
item: "standard-no-padding".to_string(),
span: Span::test_data(),
},
action_type: ActionType::Encode,
},
binary: true,
cell_paths: None,
},
Span::test_data(),
);
assert_eq!(actual, expected);
}
#[test]
fn base64_encode_url_safe() {
let word = Value::test_string("this is for url");
let expected = Value::test_string("dGhpcyBpcyBmb3IgdXJs");
let actual = action(
&word,
&Arguments {
encoding_config: Base64Config {
character_set: Spanned {
item: "url-safe".to_string(),
span: Span::test_data(),
},
action_type: ActionType::Encode,
},
binary: true,
cell_paths: None,
},
Span::test_data(),
);
assert_eq!(actual, expected);
}
#[test]
fn base64_decode_binhex() {
let word = Value::test_string(r#"B5"LD@jSCAJJG'9cG!"#);
let expected = Value::binary(b"a binhex test".as_slice(), Span::test_data());
let actual = action(
&word,
&Arguments {
encoding_config: Base64Config {
character_set: Spanned {
item: "binhex".to_string(),
span: Span::test_data(),
},
action_type: ActionType::Decode,
},
binary: true,
cell_paths: None,
},
Span::test_data(),
);
assert_eq!(actual, expected);
}
#[test]
fn base64_decode_binhex_with_new_line_input() {
let word = Value::test_string("B5\"LD@jSC\nAJJG'9cG!");
let expected = Value::binary(b"a binhex test".as_slice(), Span::test_data());
let actual = action(
&word,
&Arguments {
encoding_config: Base64Config {
character_set: Spanned {
item: "binhex".to_string(),
span: Span::test_data(),
},
action_type: ActionType::Decode,
},
binary: true,
cell_paths: None,
},
Span::test_data(),
);
assert_eq!(actual, expected);
}
#[test]
fn base64_encode_binary() {
let word = Value::binary(vec![77, 97, 110], Span::test_data());
let expected = Value::test_string("TWFu");
let actual = action(
&word,
&Arguments {
encoding_config: Base64Config {
character_set: Spanned {
item: "standard".to_string(),
span: Span::test_data(),
},
action_type: ActionType::Encode,
},
binary: true,
cell_paths: None,
},
Span::test_data(),
);
assert_eq!(actual, expected);
}
#[test]
fn base64_decode_binary_expect_error() {
let word = Value::binary(vec![77, 97, 110], Span::test_data());
let actual = action(
&word,
&Arguments {
encoding_config: Base64Config {
character_set: Spanned {
item: "standard".to_string(),
span: Span::test_data(),
},
action_type: ActionType::Decode,
},
binary: true,
cell_paths: None,
},
Span::test_data(),
);
match actual {
Value::Error { .. } => {}
_ => panic!("the result should be Value::Error"),
}
}
}

View File

@ -1,130 +0,0 @@
use super::base64::{operate, ActionType, Base64CommandArguments, CHARACTER_SET_DESC};
use nu_engine::command_prelude::*;
use nu_protocol::report_shell_warning;
#[derive(Clone)]
pub struct DecodeBase64Old;
impl Command for DecodeBase64Old {
fn name(&self) -> &str {
"decode base64"
}
fn signature(&self) -> Signature {
Signature::build("decode base64")
.input_output_types(vec![
(Type::String, Type::Any),
(
Type::List(Box::new(Type::String)),
Type::List(Box::new(Type::Any)),
),
(Type::table(), Type::table()),
(Type::record(), Type::record()),
])
.allow_variants_without_examples(true)
.named(
"character-set",
SyntaxShape::String,
CHARACTER_SET_DESC,
Some('c'),
)
.switch(
"binary",
"Output a binary value instead of decoding payload as UTF-8",
Some('b'),
)
.rest(
"rest",
SyntaxShape::CellPath,
"For a data structure input, decode data at the given cell paths.",
)
.category(Category::Hash)
}
fn description(&self) -> &str {
"Base64 decode a value."
}
fn extra_description(&self) -> &str {
r#"Will attempt to decode binary payload as an UTF-8 string by default. Use the `--binary(-b)` argument to force binary output."#
}
fn examples(&self) -> Vec<Example> {
vec![
Example {
description: "Base64 decode a value and output as UTF-8 string",
example: "'U29tZSBEYXRh' | decode base64",
result: Some(Value::test_string("Some Data")),
},
Example {
description: "Base64 decode a value and output as binary",
example: "'U29tZSBEYXRh' | decode base64 --binary",
result: Some(Value::binary(
[0x53, 0x6f, 0x6d, 0x65, 0x20, 0x44, 0x61, 0x74, 0x61],
Span::test_data(),
)),
},
]
}
fn is_const(&self) -> bool {
true
}
fn run(
&self,
engine_state: &EngineState,
stack: &mut Stack,
call: &Call,
input: PipelineData,
) -> Result<PipelineData, ShellError> {
report_shell_warning(
engine_state,
&ShellError::Deprecated {
old_command: "decode base64".into(),
new_suggestion: "the new `decode new-base64` version".into(),
span: call.head,
url: "`help decode new-base64`".into(),
},
);
let character_set: Option<Spanned<String>> =
call.get_flag(engine_state, stack, "character-set")?;
let binary = call.has_flag(engine_state, stack, "binary")?;
let cell_paths: Vec<CellPath> = call.rest(engine_state, stack, 0)?;
let args = Base64CommandArguments {
action_type: ActionType::Decode,
binary,
character_set,
};
operate(engine_state, call, input, cell_paths, args)
}
fn run_const(
&self,
working_set: &StateWorkingSet,
call: &Call,
input: PipelineData,
) -> Result<PipelineData, ShellError> {
let character_set: Option<Spanned<String>> =
call.get_flag_const(working_set, "character-set")?;
let binary = call.has_flag_const(working_set, "binary")?;
let cell_paths: Vec<CellPath> = call.rest_const(working_set, 0)?;
let args = Base64CommandArguments {
action_type: ActionType::Decode,
binary,
character_set,
};
operate(working_set.permanent(), call, input, cell_paths, args)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_examples() {
crate::test_examples(DecodeBase64Old)
}
}

View File

@ -1,134 +0,0 @@
use super::base64::{operate, ActionType, Base64CommandArguments, CHARACTER_SET_DESC};
use nu_engine::command_prelude::*;
use nu_protocol::report_shell_warning;
#[derive(Clone)]
pub struct EncodeBase64Old;
impl Command for EncodeBase64Old {
fn name(&self) -> &str {
"encode base64"
}
fn signature(&self) -> Signature {
Signature::build("encode base64")
.input_output_types(vec![
(Type::String, Type::String),
(Type::Binary, Type::String),
(
Type::List(Box::new(Type::String)),
Type::List(Box::new(Type::String)),
),
(
Type::List(Box::new(Type::Binary)),
Type::List(Box::new(Type::String)),
),
// Relaxed for heterogeneous list.
// Should be removed as soon as the type system supports better restrictions
(
Type::List(Box::new(Type::Any)),
Type::List(Box::new(Type::String)),
),
(Type::table(), Type::table()),
(Type::record(), Type::record()),
])
.allow_variants_without_examples(true)
.named(
"character-set",
SyntaxShape::String,
CHARACTER_SET_DESC,
Some('c'),
)
.rest(
"rest",
SyntaxShape::CellPath,
"For a data structure input, encode data at the given cell paths.",
)
.category(Category::Hash)
}
fn description(&self) -> &str {
"Encode a string or binary value using Base64."
}
fn examples(&self) -> Vec<Example> {
vec![
Example {
description: "Encode binary data",
example: "0x[09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0] | encode base64",
result: Some(Value::test_string("CfkRAp1041vYQVbFY1aIwA==")),
},
Example {
description: "Encode a string with default settings",
example: "'Some Data' | encode base64",
result: Some(Value::test_string("U29tZSBEYXRh")),
},
Example {
description: "Encode a string with the binhex character set",
example: "'Some Data' | encode base64 --character-set binhex",
result: Some(Value::test_string(r#"8fpYC5"%BA4K"#)),
},
]
}
fn is_const(&self) -> bool {
true
}
fn run(
&self,
engine_state: &EngineState,
stack: &mut Stack,
call: &Call,
input: PipelineData,
) -> Result<PipelineData, ShellError> {
report_shell_warning(
engine_state,
&ShellError::Deprecated {
old_command: "encode base64".into(),
new_suggestion: "the new `encode new-base64` version".into(),
span: call.head,
url: "`help encode new-base64`".into(),
},
);
let character_set: Option<Spanned<String>> =
call.get_flag(engine_state, stack, "character-set")?;
let binary = call.has_flag(engine_state, stack, "binary")?;
let cell_paths: Vec<CellPath> = call.rest(engine_state, stack, 0)?;
let args = Base64CommandArguments {
action_type: ActionType::Encode,
binary,
character_set,
};
operate(engine_state, call, input, cell_paths, args)
}
fn run_const(
&self,
working_set: &StateWorkingSet,
call: &Call,
input: PipelineData,
) -> Result<PipelineData, ShellError> {
let character_set: Option<Spanned<String>> =
call.get_flag_const(working_set, "character-set")?;
let binary = call.has_flag_const(working_set, "binary")?;
let cell_paths: Vec<CellPath> = call.rest_const(working_set, 0)?;
let args = Base64CommandArguments {
action_type: ActionType::Encode,
binary,
character_set,
};
operate(working_set.permanent(), call, input, cell_paths, args)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_examples() {
crate::test_examples(EncodeBase64Old)
}
}

View File

@ -1,11 +1,6 @@
mod base64;
mod decode;
mod decode_base64;
mod encode;
mod encode_base64;
mod encoding;
pub use self::decode::Decode;
pub use self::decode_base64::DecodeBase64Old;
pub use self::encode::Encode;
pub use self::encode_base64::EncodeBase64Old;

View File

@ -88,7 +88,25 @@ impl Command for FormatDate {
) -> Result<PipelineData, ShellError> {
let list = call.has_flag(engine_state, stack, "list")?;
let format = call.opt::<Spanned<String>>(engine_state, stack, 0)?;
run(engine_state, call, input, list, format)
// get the locale first so we can use the proper get_env_var functions since this is a const command
// we can override the locale by setting $env.NU_TEST_LOCALE_OVERRIDE or $env.LC_TIME
let locale = if let Some(loc) = engine_state
.get_env_var(LOCALE_OVERRIDE_ENV_VAR)
.or_else(|| engine_state.get_env_var("LC_TIME"))
{
let locale_str = loc.as_str()?.split('.').next().unwrap_or("en_US");
locale_str.try_into().unwrap_or(Locale::en_US)
} else {
get_system_locale_string()
.map(|l| l.replace('-', "_"))
.unwrap_or_else(|| String::from("en_US"))
.as_str()
.try_into()
.unwrap_or(Locale::en_US)
};
run(engine_state, call, input, list, format, locale)
}
fn run_const(
@ -99,7 +117,25 @@ impl Command for FormatDate {
) -> Result<PipelineData, ShellError> {
let list = call.has_flag_const(working_set, "list")?;
let format = call.opt_const::<Spanned<String>>(working_set, 0)?;
run(working_set.permanent(), call, input, list, format)
// get the locale first so we can use the proper get_env_var functions since this is a const command
// we can override the locale by setting $env.NU_TEST_LOCALE_OVERRIDE or $env.LC_TIME
let locale = if let Some(loc) = working_set
.get_env_var(LOCALE_OVERRIDE_ENV_VAR)
.or_else(|| working_set.get_env_var("LC_TIME"))
{
let locale_str = loc.as_str()?.split('.').next().unwrap_or("en_US");
locale_str.try_into().unwrap_or(Locale::en_US)
} else {
get_system_locale_string()
.map(|l| l.replace('-', "_"))
.unwrap_or_else(|| String::from("en_US"))
.as_str()
.try_into()
.unwrap_or(Locale::en_US)
};
run(working_set.permanent(), call, input, list, format, locale)
}
}
@ -109,6 +145,7 @@ fn run(
input: PipelineData,
list: bool,
format: Option<Spanned<String>>,
locale: Locale,
) -> Result<PipelineData, ShellError> {
let head = call.head;
if list {
@ -124,34 +161,23 @@ fn run(
}
input.map(
move |value| match &format {
Some(format) => format_helper(value, format.item.as_str(), format.span, head),
Some(format) => format_helper(value, format.item.as_str(), format.span, head, locale),
None => format_helper_rfc2822(value, head),
},
engine_state.signals(),
)
}
fn format_from<Tz: TimeZone>(date_time: DateTime<Tz>, formatter: &str, span: Span) -> Value
fn format_from<Tz: TimeZone>(
date_time: DateTime<Tz>,
formatter: &str,
span: Span,
locale: Locale,
) -> Value
where
Tz::Offset: Display,
{
let mut formatter_buf = String::new();
// Format using locale LC_TIME
let locale = if let Ok(l) =
std::env::var(LOCALE_OVERRIDE_ENV_VAR).or_else(|_| std::env::var("LC_TIME"))
{
let locale_str = l.split('.').next().unwrap_or("en_US");
locale_str.try_into().unwrap_or(Locale::en_US)
} else {
// LC_ALL > LC_CTYPE > LANG
// Not locale present, default to en_US
get_system_locale_string()
.map(|l| l.replace('-', "_")) // `chrono::Locale` needs something like `xx_xx`, rather than `xx-xx`
.unwrap_or_else(|| String::from("en_US"))
.as_str()
.try_into()
.unwrap_or(Locale::en_US)
};
let format = date_time.format_localized(formatter, locale);
match formatter_buf.write_fmt(format_args!("{format}")) {
@ -166,14 +192,20 @@ where
}
}
fn format_helper(value: Value, formatter: &str, formatter_span: Span, head_span: Span) -> Value {
fn format_helper(
value: Value,
formatter: &str,
formatter_span: Span,
head_span: Span,
locale: Locale,
) -> Value {
match value {
Value::Date { val, .. } => format_from(val, formatter, formatter_span),
Value::Date { val, .. } => format_from(val, formatter, formatter_span, locale),
Value::String { val, .. } => {
let dt = parse_date_from_string(&val, formatter_span);
match dt {
Ok(x) => format_from(x, formatter, formatter_span),
Ok(x) => format_from(x, formatter, formatter_span, locale),
Err(e) => e,
}
}

View File

@ -156,12 +156,17 @@ impl Command for SubCommand {
result: Some(Value::test_string("my_library.nu")),
},
Example {
description: "Find and replace all occurrences of find string using regular expression",
description: "Find and replace contents with capture group using regular expression, with escapes",
example: "'hello=world' | str replace -r '\\$?(?<varname>.*)=(?<value>.*)' '$$$varname = $value'",
result: Some(Value::test_string("$hello = world")),
},
Example {
description: "Find and replace all occurrences of found string using regular expression",
example: "'abc abc abc' | str replace --all --regex 'b' 'z'",
result: Some(Value::test_string("azc azc azc")),
},
Example {
description: "Find and replace all occurrences of find string in table using regular expression",
description: "Find and replace all occurrences of found string in table using regular expression",
example:
"[[ColA ColB ColC]; [abc abc ads]] | str replace --all --regex 'b' 'z' ColA ColC",
result: Some(Value::test_list (
@ -173,7 +178,7 @@ impl Command for SubCommand {
)),
},
Example {
description: "Find and replace all occurrences of find string in record using regular expression",
description: "Find and replace all occurrences of found string in record using regular expression",
example:
"{ KeyA: abc, KeyB: abc, KeyC: ads } | str replace --all --regex 'b' 'z' KeyA KeyC",
result: Some(Value::test_record(record! {

View File

@ -64,17 +64,19 @@ impl Command for SubCommand {
"bytes" => Value::test_int(38),
"chars" => Value::test_int(38),
"graphemes" => Value::test_int(38),
"unicode-width" => Value::test_int(38),
})),
},
Example {
description: "Counts unicode characters",
example: r#"'今天天气真好' | str stats "#,
example: r#"'今天天气真好' | str stats"#,
result: Some(Value::test_record(record! {
"lines" => Value::test_int(1),
"words" => Value::test_int(6),
"bytes" => Value::test_int(18),
"chars" => Value::test_int(6),
"graphemes" => Value::test_int(6),
"unicode-width" => Value::test_int(12),
})),
},
Example {
@ -86,6 +88,7 @@ impl Command for SubCommand {
"bytes" => Value::test_int(15),
"chars" => Value::test_int(14),
"graphemes" => Value::test_int(13),
"unicode-width" => Value::test_int(13),
})),
},
]
@ -139,6 +142,7 @@ fn counter(contents: &str, span: Span) -> Value {
"bytes" => get_count(&counts, Counter::Bytes, span),
"chars" => get_count(&counts, Counter::CodePoints, span),
"graphemes" => get_count(&counts, Counter::GraphemeClusters, span),
"unicode-width" => get_count(&counts, Counter::UnicodeWidth, span),
};
Value::record(record, span)
@ -208,6 +212,7 @@ impl Count for Counter {
}
Counter::Words => s.unicode_words().count(),
Counter::CodePoints => s.chars().count(),
Counter::UnicodeWidth => unicode_width::UnicodeWidthStr::width(s),
}
}
}
@ -229,15 +234,19 @@ pub enum Counter {
/// Counts unicode code points
CodePoints,
/// Counts the width of the string
UnicodeWidth,
}
/// A convenience array of all counter types.
pub const ALL_COUNTERS: [Counter; 5] = [
pub const ALL_COUNTERS: [Counter; 6] = [
Counter::GraphemeClusters,
Counter::Bytes,
Counter::Lines,
Counter::Words,
Counter::CodePoints,
Counter::UnicodeWidth,
];
impl fmt::Display for Counter {
@ -248,6 +257,7 @@ impl fmt::Display for Counter {
Counter::Lines => "lines",
Counter::Words => "words",
Counter::CodePoints => "codepoints",
Counter::UnicodeWidth => "unicode-width",
};
write!(f, "{s}")
@ -297,6 +307,7 @@ fn test_one_newline() {
correct_counts.insert(Counter::GraphemeClusters, 1);
correct_counts.insert(Counter::Bytes, 1);
correct_counts.insert(Counter::CodePoints, 1);
correct_counts.insert(Counter::UnicodeWidth, 0);
assert_eq!(correct_counts, counts);
}
@ -336,6 +347,7 @@ fn test_count_counts_lines() {
// one more than grapheme clusters because of \r\n
correct_counts.insert(Counter::CodePoints, 24);
correct_counts.insert(Counter::UnicodeWidth, 17);
assert_eq!(correct_counts, counts);
}
@ -353,6 +365,7 @@ fn test_count_counts_words() {
correct_counts.insert(Counter::Bytes, i_can_eat_glass.len());
correct_counts.insert(Counter::Words, 9);
correct_counts.insert(Counter::CodePoints, 50);
correct_counts.insert(Counter::UnicodeWidth, 50);
assert_eq!(correct_counts, counts);
}

View File

@ -93,6 +93,6 @@ impl Command for Complete {
}
fn pipe_redirection(&self) -> (Option<OutDest>, Option<OutDest>) {
(Some(OutDest::Capture), Some(OutDest::Capture))
(Some(OutDest::PipeSeparate), Some(OutDest::PipeSeparate))
}
}

View File

@ -180,12 +180,19 @@ impl Command for External {
}
// Wrap the output into a `PipelineData::ByteStream`.
let child = ChildProcess::new(
let mut child = ChildProcess::new(
child,
merged_stream,
matches!(stderr, OutDest::Pipe),
call.head,
)?;
if matches!(stdout, OutDest::Pipe | OutDest::PipeSeparate)
|| matches!(stderr, OutDest::Pipe | OutDest::PipeSeparate)
{
child.ignore_error(true);
}
Ok(PipelineData::ByteStream(
ByteStream::child(child, call.head),
None,
@ -340,7 +347,7 @@ fn write_pipeline_data(
} else if let PipelineData::Value(Value::Binary { val, .. }, ..) = data {
writer.write_all(&val)?;
} else {
stack.start_capture();
stack.start_collect_value();
// Turn off color as we pass data through
Arc::make_mut(&mut engine_state.config).use_ansi_coloring = false;
@ -367,7 +374,7 @@ pub fn command_not_found(
) -> ShellError {
// Run the `command_not_found` hook if there is one.
if let Some(hook) = &stack.get_config(engine_state).hooks.command_not_found {
let mut stack = stack.start_capture();
let mut stack = stack.start_collect_value();
// Set a special environment variable to avoid infinite loops when the
// `command_not_found` hook triggers itself.
let canary = "ENTERED_COMMAND_NOT_FOUND";
@ -623,8 +630,16 @@ mod test {
#[test]
fn test_write_pipeline_data() {
let engine_state = EngineState::new();
let mut engine_state = EngineState::new();
let stack = Stack::new();
let cwd = std::env::current_dir()
.unwrap()
.into_os_string()
.into_string()
.unwrap();
// set the PWD environment variable as it's required now
engine_state.add_env_var("PWD".into(), Value::string(cwd, Span::test_data()));
let mut buf = vec![];
let input = PipelineData::Empty;

View File

@ -69,7 +69,7 @@ prints out the list properly."#
let icons_param: bool = call.has_flag(engine_state, stack, "icons")?;
let config = &stack.get_config(engine_state);
let env_str = match stack.get_env_var(engine_state, "LS_COLORS") {
Some(v) => Some(env_to_string("LS_COLORS", &v, engine_state, stack)?),
Some(v) => Some(env_to_string("LS_COLORS", v, engine_state, stack)?),
None => None,
};
@ -237,7 +237,9 @@ fn create_grid_output(
cell.alignment = Alignment::Left;
grid.add(cell);
} else {
let style = ls_colors.style_for_path(value.clone());
let no_ansi = nu_utils::strip_ansi_unlikely(&value);
let path = cwd.join(no_ansi.as_ref());
let style = ls_colors.style_for_path(path.clone());
let ansi_style = style.map(Style::to_nu_ansi_term_style).unwrap_or_default();
let mut cell = Cell::from(ansi_style.paint(value).to_string());
cell.alignment = Alignment::Left;

View File

@ -201,6 +201,7 @@ pub fn icon_for_file(file_path: &Path, span: Span) -> Result<char, ShellError> {
"cc" => '\u{e61d}', // 
"cert" => '\u{eafa}', // 
"cfg" => '\u{e615}', // 
"cjs" => '\u{e74e}', // 
"class" => '\u{e256}', // 
"clj" => '\u{e768}', // 
"cljs" => '\u{e76a}', // 

View File

@ -5,6 +5,7 @@
use lscolors::{LsColors, Style};
use nu_color_config::{color_from_hex, StyleComputer, TextStyle};
use nu_engine::{command_prelude::*, env_to_string};
use nu_path::form::Absolute;
use nu_pretty_hex::HexConfig;
use nu_protocol::{
ByteStream, Config, DataSource, ListStream, PipelineMetadata, Signals, TableMode, ValueIterator,
@ -125,7 +126,7 @@ impl Command for Table {
let val = Value::list(supported_table_modes(), Span::test_data());
return Ok(val.into_pipeline_data());
}
let cwd = engine_state.cwd(Some(stack))?;
let cfg = parse_table_config(call, engine_state, stack)?;
let input = CmdInput::new(engine_state, stack, call, input);
@ -135,7 +136,7 @@ impl Command for Table {
let _ = nu_utils::enable_vt_processing();
}
handle_table_command(input, cfg)
handle_table_command(input, cfg, cwd)
}
fn examples(&self) -> Vec<Example> {
@ -367,6 +368,7 @@ impl<'a> CmdInput<'a> {
fn handle_table_command(
mut input: CmdInput<'_>,
cfg: TableConfig,
cwd: nu_path::PathBuf<Absolute>,
) -> Result<PipelineData, ShellError> {
let span = input.data.span().unwrap_or(input.call.head);
match input.data {
@ -389,11 +391,11 @@ fn handle_table_command(
let stream = ListStream::new(vals.into_iter(), span, signals);
input.data = PipelineData::Empty;
handle_row_stream(input, cfg, stream, metadata)
handle_row_stream(input, cfg, stream, metadata, cwd)
}
PipelineData::ListStream(stream, metadata) => {
input.data = PipelineData::Empty;
handle_row_stream(input, cfg, stream, metadata)
handle_row_stream(input, cfg, stream, metadata, cwd)
}
PipelineData::Value(Value::Record { val, .. }, ..) => {
input.data = PipelineData::Empty;
@ -413,7 +415,7 @@ fn handle_table_command(
let stream =
ListStream::new(val.into_range_iter(span, Signals::empty()), span, signals);
input.data = PipelineData::Empty;
handle_row_stream(input, cfg, stream, metadata)
handle_row_stream(input, cfg, stream, metadata, cwd)
}
x => Ok(x),
}
@ -605,6 +607,7 @@ fn handle_row_stream(
cfg: TableConfig,
stream: ListStream,
metadata: Option<PipelineMetadata>,
cwd: nu_path::PathBuf<Absolute>,
) -> Result<PipelineData, ShellError> {
let stream = match metadata.as_ref() {
// First, `ls` sources:
@ -620,7 +623,7 @@ fn handle_row_stream(
let ls_colors_env_str = match input.stack.get_env_var(input.engine_state, "LS_COLORS") {
Some(v) => Some(env_to_string(
"LS_COLORS",
&v,
v,
input.engine_state,
input.stack,
)?),
@ -634,7 +637,9 @@ fn handle_row_stream(
if let Some(value) = record.to_mut().get_mut("name") {
let span = value.span();
if let Value::String { val, .. } = value {
if let Some(val) = render_path_name(val, &config, &ls_colors, span) {
if let Some(val) =
render_path_name(val, &config, &ls_colors, cwd.clone(), span)
{
*value = val;
}
}
@ -1008,15 +1013,16 @@ fn render_path_name(
path: &str,
config: &Config,
ls_colors: &LsColors,
cwd: nu_path::PathBuf<Absolute>,
span: Span,
) -> Option<Value> {
if !config.ls.use_ls_colors {
return None;
}
let fullpath = cwd.join(path);
let stripped_path = nu_utils::strip_ansi_unlikely(path);
let metadata = std::fs::symlink_metadata(stripped_path.as_ref());
let metadata = std::fs::symlink_metadata(fullpath);
let has_metadata = metadata.is_ok();
let style =
ls_colors.style_for_path_with_metadata(stripped_path.as_ref(), metadata.ok().as_ref());

View File

@ -2,18 +2,18 @@ use nu_test_support::nu;
#[test]
fn canonical() {
super::test_canonical("new-base64");
super::test_canonical("new-base64 --url");
super::test_canonical("new-base64 --nopad");
super::test_canonical("new-base64 --url --nopad");
super::test_canonical("base64");
super::test_canonical("base64 --url");
super::test_canonical("base64 --nopad");
super::test_canonical("base64 --url --nopad");
}
#[test]
fn const_() {
super::test_const("new-base64");
super::test_const("new-base64 --url");
super::test_const("new-base64 --nopad");
super::test_const("new-base64 --url --nopad");
super::test_const("base64");
super::test_const("base64 --url");
super::test_const("base64 --nopad");
super::test_const("base64 --url --nopad");
}
#[test]
@ -21,7 +21,7 @@ fn encode() {
let text = "Ș̗͙̂̏o̲̲̗͗̌͊m̝̊̓́͂ë̡̦̞̤́̌̈́̀ ̥̝̪̎̿ͅf̧̪̻͉͗̈́̍̆u̮̝͌̈́ͅn̹̞̈́̊k̮͇̟͎̂͘y̧̲̠̾̆̕ͅ ̙͖̭͔̂̐t̞́́͘e̢̨͕̽x̥͋t͍̑̔͝";
let encoded = "U8yCzI/MpsyXzZlvzZfMjM2KzLLMssyXbcyKzJPMgc2CzJ1lzYTMjM2EzIDMpsyhzJ7MpCDMjsy/zYXMpcydzKpmzZfNhMyNzIbMqsy7zKfNiXXNjM2EzK7Mnc2Fbs2EzIrMucyea82YzILMrs2HzJ/NjnnMvsyVzIbNhcyyzKfMoCDMgsyQzJnNlsytzZR0zIHNmMyBzJ5lzL3Mos2VzKh4zYvMpXTMkcyUzZ3NjQ==";
let outcome = nu!("'{}' | encode new-base64", text);
let outcome = nu!("'{}' | encode base64", text);
assert_eq!(outcome.out, encoded);
}
@ -30,7 +30,7 @@ fn decode_string() {
let text = "Very important data";
let encoded = "VmVyeSBpbXBvcnRhbnQgZGF0YQ==";
let outcome = nu!("'{}' | decode new-base64 | decode", encoded);
let outcome = nu!("'{}' | decode base64 | decode", encoded);
assert_eq!(outcome.out, text);
}
@ -40,10 +40,10 @@ fn decode_pad_nopad() {
let encoded_pad = "4oCdwqUuw6RAwrBiWsO2wqI=";
let encoded_nopad = "4oCdwqUuw6RAwrBiWsO2wqI";
let outcome = nu!("'{}' | decode new-base64 | decode", encoded_pad);
let outcome = nu!("'{}' | decode base64 | decode", encoded_pad);
assert_eq!(outcome.out, text);
let outcome = nu!("'{}' | decode new-base64 --nopad | decode", encoded_nopad);
let outcome = nu!("'{}' | decode base64 --nopad | decode", encoded_nopad);
assert_eq!(outcome.out, text);
}
@ -53,10 +53,10 @@ fn decode_url() {
let encoded = "cDpn15jdvt+rdCs/";
let encoded_url = "cDpn15jdvt-rdCs_";
let outcome = nu!("'{}' | decode new-base64 | decode", encoded);
let outcome = nu!("'{}' | decode base64 | decode", encoded);
assert_eq!(outcome.out, text);
let outcome = nu!("'{}' | decode new-base64 --url | decode", encoded_url);
let outcome = nu!("'{}' | decode base64 --url | decode", encoded_url);
assert_eq!(outcome.out, text);
}
@ -65,9 +65,9 @@ fn reject_pad_nopad() {
let encoded_nopad = "YQ";
let encoded_pad = "YQ==";
let outcome = nu!("'{}' | decode new-base64", encoded_nopad);
let outcome = nu!("'{}' | decode base64", encoded_nopad);
assert!(!outcome.err.is_empty());
let outcome = nu!("'{}' | decode new-base64 --nopad", encoded_pad);
let outcome = nu!("'{}' | decode base64 --nopad", encoded_pad);
assert!(!outcome.err.is_empty())
}

View File

@ -9,25 +9,28 @@ fn capture_errors_works() {
assert!(actual.err.contains("column_not_found"));
}
// TODO: need to add tests under display_error.exit_code = true
#[test]
fn capture_errors_works_for_external() {
let actual = nu!("do -c {nu --testbin fail}");
assert!(actual.err.contains("exited with code"));
assert_eq!(actual.out, "");
assert!(!actual.status.success());
assert!(!actual.err.contains("exited with code"));
}
// TODO: need to add tests under display_error.exit_code = true
#[test]
fn capture_errors_works_for_external_with_pipeline() {
let actual = nu!("do -c {nu --testbin fail} | echo `text`");
assert!(actual.err.contains("exited with code"));
assert_eq!(actual.out, "");
assert!(!actual.status.success());
assert!(!actual.err.contains("exited with code"));
}
// TODO: need to add tests under display_error.exit_code = true
#[test]
fn capture_errors_works_for_external_with_semicolon() {
let actual = nu!(r#"do -c {nu --testbin fail}; echo `text`"#);
assert!(actual.err.contains("exited with code"));
assert_eq!(actual.out, "");
assert!(!actual.status.success());
assert!(!actual.err.contains("exited with code"));
}
#[test]
@ -73,3 +76,10 @@ fn run_closure_with_it_using() {
assert!(actual.err.is_empty());
assert_eq!(actual.out, "3");
}
#[test]
fn waits_for_external() {
let actual = nu!(r#"do -p { nu -c 'sleep 1sec; print before; exit 1'}; print after"#);
assert!(actual.err.is_empty());
assert_eq!(actual.out, "beforeafter");
}

View File

@ -9,7 +9,7 @@ fn each_works_separately() {
#[test]
fn each_group_works() {
let actual = nu!("echo [1 2 3 4 5 6] | group 3 | to json --raw");
let actual = nu!("echo [1 2 3 4 5 6] | chunks 3 | to json --raw");
assert_eq!(actual.out, "[[1,2,3],[4,5,6]]");
}

View File

@ -10,43 +10,48 @@ fn base64_defaults_to_encoding_with_standard_character_type() {
}
#[test]
fn base64_encode_characterset_binhex() {
fn base64_defaults_to_encoding_with_nopad() {
let actual = nu!(r#"
echo 'username:password' | encode base64 --character-set binhex
echo 'username:password' | encode base64 --nopad
"#);
assert_eq!(actual.out, "GA0PFQjKE@8kF'&cFhG[FQ3");
assert_eq!(actual.out, "dXNlcm5hbWU6cGFzc3dvcmQ");
}
#[test]
fn error_when_invalid_character_set_given() {
fn base64_decode_value() {
let actual = nu!(r#"
echo 'username:password' | encode base64 --character-set 'this is invalid'
echo 'YWJjeHl6' | decode base64 | decode
"#);
assert!(actual
.err
.contains("this is invalid is not a valid character-set"));
assert_eq!(actual.out, "abcxyz");
}
#[test]
fn base64_decode_characterset_binhex() {
let actual = nu!(
r#""GA0PFQjKE@8kF'&cFhG[FQ3" | decode base64 --character-set binhex --binary | decode utf-8"#
);
fn base64_decode_with_nopad() {
let actual = nu!(r#"
echo 'R29vZCBsdWNrIHRvIHlvdQ' | decode base64 --nopad | decode
"#);
assert_eq!(actual.out, "username:password");
assert_eq!(actual.out, "Good luck to you");
}
#[test]
fn base64_decode_with_url() {
let actual = nu!(r#"
echo 'vu7_' | decode base64 --url | decode
"#);
assert_eq!(actual.out, "¾îÿ");
}
#[test]
fn error_invalid_decode_value() {
let actual = nu!(r#"
echo "this should not be a valid encoded value" | decode base64 --character-set url-safe
echo "this should not be a valid encoded value" | decode base64
"#);
assert!(actual
.err
.contains("invalid base64 input for character set url-safe"));
assert!(actual.err.contains("nu::shell::incorrect_value"));
}
#[test]

Some files were not shown because too many files have changed in this diff Show More