Commit Graph

9550 Commits

Author SHA1 Message Date
Ian Manske
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
132ikl
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
Darren Schroeder
bdbcf82967
Revert "Add the history import command" (#14077) 2024-10-12 21:43:24 -05:00
Piotr Kufel
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
Solomon
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
Piotr Kufel
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
Ian Manske
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
Douglas
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
Darren Schroeder
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
Ian Manske
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
Douglas
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
Solomon
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
Piotr Kufel
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
Tristan P.
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
Ian Manske
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
Jack Wright
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
Wind
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
Justin Ma
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
Darren Schroeder
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
Douglas
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
Wind
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
Wind
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
Douglas
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
Darren Schroeder
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
132ikl
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
Tristan P.
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
Darren Schroeder
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
Douglas
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
dependabot[bot]
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
dependabot[bot]
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
1256-bits
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
JustForFun88
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
Justin Ma
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
Douglas
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
Darren Schroeder
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
Darren Schroeder
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
Kither
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
Sergio Morales
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
Douglas
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
Douglas
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
Douglas
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
Darren Schroeder
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
Douglas
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
Vivek Kethineni
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
Kither
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
Douglas
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
Akira Baruah
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
Maxim Zhiburt
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
LordLightSpeed
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
Darren Schroeder
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