Commit Graph

4538 Commits

Author SHA1 Message Date
Darren Schroeder
341fa7b196
add kind and state to other key presses (#9669)
# Description

This PR adds `kind` and `state` to other `keybindings listen` presses
like `home` and `end` keys. Before they didn't exist.

```
❯ keybindings listen
Type any key combination to see key details. Press ESC to abort.
code: Enter, modifier: NONE, flags: 0b000000, kind: Release, state: NONE
code: Home, modifier: NONE, flags: 0b000000, kind: Press, state: NONE
code: Home, modifier: NONE, flags: 0b000000, kind: Release, state: NONE
code: End, modifier: NONE, flags: 0b000000, kind: Press, state: NONE
code: End, modifier: NONE, flags: 0b000000, kind: Release, state: NONE
code: End, modifier: CONTROL, flags: 0b000010, kind: Press, state: NONE
code: End, modifier: CONTROL, flags: 0b000010, kind: Release, state: NO
```

# 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 -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` 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.
-->
2023-07-12 10:42:19 -05:00
Stefan Holderbach
bd0032898f
Apply nightly clippy lints (#9654)
# Description
- A new one is the removal of unnecessary `#` in raw strings without `"`
inside.
-
https://rust-lang.github.io/rust-clippy/master/index.html#/needless_raw_string_hashes
- The automatically applied removal of `.into_iter()` touched several
places where #9648 will change to the use of the record API. If
necessary I can remove them @IanManske to avoid churn with this PR.
- Manually applied `.try_fold` in two places
- Removed a dead `if`
- Manual: Combat rightward-drift with early return
2023-07-12 00:00:31 +02:00
JT
ad11e25fc5
allow mut to take pipelines (#9658)
# Description

This extends the syntax fix for `let` (#9589) to `mut` as well.

Example: `mut x = "hello world" | str length; print $x`

closes #9634

# User-Facing Changes

`mut` now joins `let` in being able to be assigned from a pipeline

# 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 -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` 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.
-->
2023-07-12 06:36:34 +12:00
Michael Angerman
942c66a9f3
cratification: part II of the math commands to nu-cmd-extra (#9657)
The following math commands are being moved to nu-cmd-extra

* cos
* cosh
* egamma
* phi
* pi
* sin
* sinh
* tan
* tanh
* tau

For now I think we have most of the obvious commands moved over based on

@sholderbach this should cover moving the "high school" commands..

>>Yeah I think this rough separation into "high school" math in extra
and "middle school"/"programmer" math in the core makes a ton of sense.

And to reference the @fdncred list from
https://github.com/nushell/nushell/pull/9647#issuecomment-1629498812
2023-07-11 11:23:39 -07:00
Michael Angerman
e10d84b72f
cratification: start moving over the math commands to nu-cmd-extra (#9647)
* arccos
* arccosh
* arcsin
* arcsinh
* arctan
* arctanh

The above commands are being ported over to nu-cmd-extra

I initially moved all of the math commands over but there are some
issues with the tests...

So we will move them over slowly --- and actually I kind of like this
idea better...

Because some of the math commands we might want to leave in the core
nushell...

Stay tuned...

For more details 👍 
Read this document:

https://github.com/stormasm/nutmp/blob/main/commands/math.md
2023-07-10 12:08:45 -07:00
dependabot[bot]
cf36f052c4
Bump strum from 0.24.1 to 0.25.0 (#9639) 2023-07-10 11:35:23 +00:00
Stefan Holderbach
a3702e1eb7
Bump indexmap to 2.0 (#9643)
# Description
Apart from `polars` (only used with `--features dataframe`) and the
dev-dependencies our deps use `indexmap 2.0`.
Thus the default or `extra` `cargo build` will reduce deps.
This also will help deduplicating `hashbrown` and `ahash`.

For #8060

- Bump `indexmap` to 2.0
- Remove unneeded `serde` feature from `indexmap`

# User-Facing Changes
None
2023-07-10 10:30:01 +02:00
Stefan Holderbach
92354a817c
Remove duplicated dependency on ansi-str 0.7 (#9641)
# Description
`tabled`/`papergrid` already use `ansi-str 0.8` while `nu-explore`
itself was still depending on `0.7`. Single fix necessary to adapt to
the new API.

cc @zhiburt

# User-Facing Changes
None
2023-07-10 09:24:08 +02:00
dependabot[bot]
79a9751a58
Bump scraper from 0.16.0 to 0.17.1 (#9638) 2023-07-10 05:28:36 +00:00
dependabot[bot]
47979651f3
Bump libproc from 0.13.0 to 0.14.0 (#9640) 2023-07-10 05:10:36 +00:00
Yethal
fabc0a3f45
test-runner: add configurable threading (#9628)
<!--
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.
-->
Max amount of threads used by the test runner can now be configured via
the `--threads` flag

# 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 -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` 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.
-->
2023-07-08 11:27:56 +02:00
Ayush Singh
ad125abf6a
fixes which showing aliases as built-in nushell commands (#9580)
fixes #8577 

# Description
Currently, using `which` on an alias describes it as a nushell built-in
command:
```bash
> alias foo = print "foo!"                                                                                                                                                                                   > which ls foo --all                                                                                                                                                                                        
╭───┬─────┬──────────────────────────┬──────────╮
│ # │ arg │           path           │ built-in │
├───┼─────┼──────────────────────────┼──────────┤
│ 0 │ ls  │ Nushell built-in command │ true     │
│ 1 │ ls  │ /bin/ls                  │ false    │
│ 2 │ foo │ Nushell built-in command │ true     │
╰───┴─────┴──────────────────────────┴──────────╯
```

This PR fixes the behaviour above to the following:
```bash
> alias foo = print "foo!"
> which ls foo --all
╭───┬─────┬──────────────────────────┬──────────╮
│ # │ arg │           path           │ built-in │
├───┼─────┼──────────────────────────┼──────────┤
│ 0 │ ls  │ Nushell built-in command │ true     │
│ 1 │ ls  │ /bin/ls                  │ false    │
│ 2 │ foo │ Nushell alias            │ false    │
╰───┴─────┴──────────────────────────┴──────────╯
```

# User-Facing Changes
Passing in an alias to `which` will no longer return `Nushell built-in
command`, `true` for `path` and `built-in` respectively.

# Tests + Formatting

# After Submitting
2023-07-08 10:48:42 +02:00
mike
8e38596bc9
allow tables to have annotations (#9613)
# Description

follow up to #8529 and #8914

this works very similarly to record annotations, only difference being
that

```sh
table<name: string>
      ^^^^  ^^^^^^
      |     | 
      |     represents the type of the items in that column
      |
      represents the column name
```
more info on the syntax can be found
[here](https://github.com/nushell/nushell/pull/8914#issue-1672113520)

# User-Facing Changes

**[BREAKING CHANGE]**
this change adds a field to `SyntaxShape::Table` so any plugins that
used it will have to update and include the field. though if you are
unsure of the type the table expects, `SyntaxShape::Table(vec![])` will
suffice
2023-07-07 11:06:09 +02:00
Yethal
440a0e960a
test-runner: Performance improvements + regex match for test include/exclude (#9622)
<!--
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.
-->
Test-runner performance improved by:
* Not loading user config or stdlib during ide parsing
* Not loading user config during test execution
* Running tests in parallel instead of serially
On my machine `toolkit test stdlib` execution time went from 38s to 15s
(with all code precompiled)

Use regex match for test include/exclude and module exclude to allow for
multiple tests/modules to be excluded.
# 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 -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` 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.
-->
2023-07-07 09:20:36 +02:00
Han Junghyuk
85d47c299e
Fix explore crashes on {} (#9623)
<!--
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: #8479 

Co-authored-by: Jan9103 <55753387+Jan9103@users.noreply.github.com>

# 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 -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

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

---------

Co-authored-by: Jan9103 <55753387+Jan9103@users.noreply.github.com>
2023-07-06 20:17:55 -05:00
Yassine Haouzane
628a47e6dc
Fix: update engine_state when history.isolation is true (#9268) (#9616)
<!--
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
Fixes #9268, the issue was due to the fact that when `history_isolation`
was set to true the engine_state's `session_id` wasn't updated.

This PR mainly refactors the code that updates the line_editor's history
information into one function `update_line_editor_history` and also
updates the engine_state's `session_id` when `history_isolation` is set
to `true` by calling the function `store_history_id_in_engine`.
<!--
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. -->
None since it's a bug fix.

# 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 -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` 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
> ```
-->

I tried to extract the block that was updating the line_editor's
`session_id` to make it easier to add a test.
The test checks that after a call to the function
`update_line_editor_history`, the `engine_state` and the returned
`line_editor` do have the same `session_id`.
2023-07-06 20:16:17 -05:00
Ian Manske
f38657e6f3
Fix headers command handling of missing values (#9603)
# Description
This fixes the `headers` command handling of missing values (issue
#9602). Previously, each row in the table would have its columns set to
be exactly equal to the first row even if it had less columns than the
first row. This would cause to values magically change their column or
cause panics in other commands if rows ended up having more columns than
values.

# Tests
Added a missing values  test for the `headers` command
2023-07-06 19:54:59 +02:00
Antoine Stevan
504eff73f0
REFACTOR: move the 0% commands to nu-cmd-extra (#9404)
requires
- https://github.com/nushell/nushell/pull/9455

# ⚙️ Description
in this PR i move the commands we've all agreed, in the core team, to
move out of the core Nushell to the `extra` feature.

> **Warning**
> in the first commits here, i've
> - moved the implementations to `nu-cmd-extra`
> - removed the declaration of all the commands below from `nu-command`
> - made sure the commands were not available anymore with `cargo run --
-n`

## the list of commands to move
with the current command table downloaded as `commands.csv`, i've run
```bash
let commands = (
    open commands.csv
    | where is_plugin == "FALSE" and category != "deprecated"
    | select name category "approv. %"
    | rename name category approval
    | insert treated {|it| (
        ($it.approval == 100) or                # all the core team agreed on them
        ($it.name | str starts-with "bits") or  # see https://github.com/nushell/nushell/pull/9241
        ($it.name | str starts-with "dfr")      # see https://github.com/nushell/nushell/pull/9327
    )}
)
```
to preprocess them and then
```bash
$commands | where {|it| (not $it.treated) and ($it.approval == 0)}
```
to get all untreated commands with no approval, which gives
```
╭────┬───────────────┬─────────┬─────────────┬──────────╮
│  # │     name      │ treated │  category   │ approval │
├────┼───────────────┼─────────┼─────────────┼──────────┤
│  0 │ fmt           │ false   │ conversions │        0 │
│  1 │ each while    │ false   │ filters     │        0 │
│  2 │ roll          │ false   │ filters     │        0 │
│  3 │ roll down     │ false   │ filters     │        0 │
│  4 │ roll left     │ false   │ filters     │        0 │
│  5 │ roll right    │ false   │ filters     │        0 │
│  6 │ roll up       │ false   │ filters     │        0 │
│  7 │ rotate        │ false   │ filters     │        0 │
│  8 │ update cells  │ false   │ filters     │        0 │
│  9 │ decode hex    │ false   │ formats     │        0 │
│ 10 │ encode hex    │ false   │ formats     │        0 │
│ 11 │ from url      │ false   │ formats     │        0 │
│ 12 │ to html       │ false   │ formats     │        0 │
│ 13 │ ansi gradient │ false   │ platform    │        0 │
│ 14 │ ansi link     │ false   │ platform    │        0 │
│ 15 │ format        │ false   │ strings     │        0 │
╰────┴───────────────┴─────────┴─────────────┴──────────╯
```
# 🖌️ User-Facing Changes
```
$nothing
```

# 🧪 Tests + Formatting
-  `toolkit fmt`
-  `toolkit clippy`
-  `toolkit test`
-  `toolkit test stdlib`

# 📖 After Submitting
```
$nothing
```

# 🔍 For reviewers
```bash
$commands | where {|it| (not $it.treated) and ($it.approval == 0)} | each {|command|
    try {
        help $command.name | ignore
    } catch {|e|
        $"($command.name): ($e.msg)"
    }
}
```
should give no output in `cargo run --features extra -- -n` and a table
with 16 lines in `cargo run -- -n`
2023-07-06 08:31:31 -07:00
Yethal
fbc1408913
test-runner: Add option to exclude single test and module (#9611)
# Description
This PR adds two additional flags to the test runner `--exclude` and
`--exclude-module` which as the name suggests allow to exclude tests
from a run
The now options only support a single test / module to exclude.

# User-Facing Changes

# Tests + Formatting

# After Submitting
2023-07-06 11:21:37 +02:00
mike
544c46e0e4
improve subtyping (#9614)
# Description

the current subtyping rule needs you to define the record entries in the
same order as declared in the annotation. this pr improves that

now
```nushell
{ name: 'Him', age: 12 } 

# ,

{ age: 100, name: 'It' }

# and

{ name: 'Red', age: 69, height: "5-8" }

# will all match

record<name: string, age: int>

# previously only the first one would match
```

however, something like

```nushell
{ name: 'Her' } # will not


# and

{ name: 'Car', wheels: 5 }
```

EDIT: applied JT's suggestion
2023-07-06 10:25:39 +02:00
nibon7
687b0e16f7
Replace users with nix crate (#9610)
# Description
The `users` crate hasn't been updated for a long time, this PR tries to
replace `users` with `nix`.
See [advisory
page](https://rustsec.org/advisories/RUSTSEC-2023-0040.html) for
additional details.
2023-07-06 00:07:07 +02:00
Stefan Holderbach
881c3495c1
Exclude deprecated commands from completions (#9612)
# Description
We previously simply searched all commands in the working set. As our
deprecated/removed subcommands are documented by stub commands that
don't do anything apart from providing a message, they were still
included.
With this change we check the `Signature.category` to not be
`Category::Deprecated`.

## Note on performance
Making this change will exercise `Command.signature()` more
frequently! As the rust-implemented commands include their builders here
this probably will cause a number of extra allocations. There is
actually no valid reason why the commands should construct a new
`Signature` for each call to `Command.signature()`.
This will introduce some overhead to generate the completions for
commands.
# User-Facing Changes
Example: `str <TAB>`


![grafik](https://github.com/nushell/nushell/assets/15833959/4d5ec5fe-aa93-45af-aa60-3854a20fcb04)
2023-07-05 23:13:16 +02:00
WindSoilder
406b606398
dependency: use notify-debouncer-full(based on notify v6) instead of notify v4 (#9606)
# Description

Closes: #9324

I have done some manually test locally on MacOS, and it seems fine for
me.

cc: @rgwood
2023-07-05 14:14:55 +02:00
Stefan Holderbach
168e7f7b16
Document fn pipeline() used with nu! tests (#9609)
# Description
Its purpose and its limitation around statements are not too obvious but
ubiquituous in our `nu!` tests. Document its behavior as we remove it in
many places for #8670


# User-Facing Changes
None
2023-07-05 13:19:54 +02:00
Antoine Stevan
53cd4df806
simplify the nu! tests for last and first commands (#9608)
# Description
in most of the tests for `last` and `first`, we do not need to
- give `cwd` to `nu!`
- use pipeline as the tests are all short pipes
- use `r#" ... "#` as the pipes never contain quotes

this PR removes all these points from the tests for the `last` and
`first` commands.
2023-07-05 12:30:53 +02:00
Hofer-Julian
65a163357d
Add pwd command to stdlib (#9607)
Closes #9601
2023-07-04 19:25:01 +02:00
Stefan Holderbach
1bdec1cbb6
Remove unnecessary parentheses (#9605)
# Description
As seen on nightly
2023-07-04 11:12:46 +02:00
JT
7e39179b7f
Move to using a safer shell integration default setting (#9600)
# Description

We're seeing some issues in a few terminals with the shell integration
support. Moving shell_integration to off by default to help with the
default user experience, but it will remain easy to re-enable for folks
who want to have the integration experience and a terminal that supports
it well.

# User-Facing Changes

This turns off shell integration by default, requiring the user to edit
the config and re-enable it.

# 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 -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` 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.
-->
2023-07-04 06:26:49 +12:00
Artemiy
2bb0c1c618
Command to get individual keys (#9453)
# Description
Add a `keybindings get` command to listen and get individual "keyboard"
events. This includes different keyboard keys (see example of use) on
seemingly all terminals and mouse, resize, focus and paste events on
some special once. The record returned by this command is similar to
crossterm event structure and is documented in help message. For ease of
use, option `--types` can get a list of event types to filter only
desired events automatically. Additionally `--raw` options displays raw
code of char keys and numeric format of modifier flags.

Example of use, moving a character around a grid with arrow keys:
```nu
def test [] {
  mut x = 0
  mut y = 0
  loop {
    clear
    $x = ([([$x 4] | math min) 0] | math max)
    $y = ([([$y 4] | math min) 0] | math max)

    for i in 0..4 {
      for j in 0..4 {
        if $j == $x and $i == $y {
          print -n "*"
        } else {
          print -n "."
        }
      }
      print ""
    }
    
    let inp = (input listen-t [ key ])
    match $inp.key {
      {type: other key: enter} => (break)
      {type: other key: up} => ($y = $y - 1)
      {type: other key: down} => ($y = $y + 1)
      {type: other key: left} => ($x = $x - 1)
      {type: other key: right} => ($x = $x + 1)
      _ => ()
    }
  }
}

```

# User-Facing Changes
- New `keybindngs get` command
- `keybindings listen` is left as is
- New `input display` command in std, mirroring functionality of
`keybindings listen`

# 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 -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` 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.
-->
2023-07-03 10:23:44 -05:00
Julian Aichholz
9c7e37f728
Fix: return all headers with the same name from http <method> (#9594)
# Description

Hi nushell!

Thanks so much for [adding http headers][headers]! I've been waiting for
this feature for a long time and it's great. However, I found that
`Record` as a return type and using `ureq`'s `response.header` api
results in missing header values when there are multiple with the same
name, as can occur with `set-cookie` and others.

This issue with http has been discussed at length [on
stackoverflow][stackoverflow] and in [`ureq` itself][ureq]. It seems
like concatenating header values with `,` is a common solution, but
tricky especially with `set-cookie` which may contain `,` in the
`Expires` field, as discussed in the former post.

I propose changing the return type to a `List` of `Record` so we can get
all of the header values without relying on ad-hoc mutation. This
solution does not return the headers in the same order as they appear in
the `Response` due to `ureq`'s `Response.all` API, but it's better than
dropping values imo.

This is a **breaking change**. I'm sure `ureq`'s
[`CookieStore`][cookiestore] is a better long-term solution for
returning cookies as a separate record on `http <method>`, but other
headers can be set multiple times as well.

# User-Facing Changes
- Changes the return type of an `http <method>` `header` field from
`Record` to `List` (Table with columns `name` and `value`)
- Returns all values of a header set multiple times instead of just the
first one duplicated

# Implementation

Quick note that running `header_names.dedup()` does not resolve the
necessity to iterate through the previously parsed headers since `dedup`
only removes identical values when they are next to each other in the
`Vec`. You could do a `sort` first, but header ordering can be important
in some cases, so I tried to avoid messing with that more than is
already the case with `Response.all`. Would love to see a better way of
doing this though!

# Tests + Formatting
No tests broke implementing this change. Not sure what endpoint to hit
or mock server to use to verify this in tests. I have some screenshots
to illustrate what I'm talking about.

Before:
![Screenshot 2023-07-03 at 12 50 17
AM](https://github.com/nushell/nushell/assets/39018167/41604bef-54c6-424b-91b2-6b89a020e4ff)

> `set-cookie` has the same value for every record field.
> Even if it did not I'm not sure how you would access the different
values since they all have the same key.

After:
![Screenshot 2023-07-03 at 12 49 45
AM](https://github.com/nushell/nushell/assets/39018167/4ee45e6e-3785-471f-aee7-5af185cd06c2)

> Actual values from the response returned for the same name

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

- [x] `cargo fmt --all -- --check` to check standard code formatting
(`cargo fmt --all` applies these changes)
- [x] `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- [x] `cargo test --workspace` to check that all tests pass
- [x] `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library <-- Note: I did not see a `crates/nu-std/test/run.nu`
file so I ran the snippet below which returned without error
```nushell
for $i in (ls crates/nu-std/tests/*.nu) {
   cargo run -- $i.name
}
```

# Code of Conduct

Apologies for not opening an issue first. Just did this fix for myself
because it seemed simple enough before deciding to open this 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.
-->
- [ ] update docs

[stackoverflow]:
https://stackoverflow.com/questions/3241326/set-more-than-one-http-header-with-the-same-name
[headers]: https://github.com/nushell/nushell/pull/8571
[ureq]: https://github.com/algesten/ureq/issues/95
[cookiestore]:
https://docs.rs/cookie_store/latest/cookie_store/struct.CookieStore.html
2023-07-03 10:20:39 -05:00
baehyunsol
227d1d9508
make the behaviours of last and first more consistent (#9582)
<!--
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

- fixes #9567 

I have fixed everything mentioned in the issue, and made their help
messages more similar.

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

- Previously, `last` on binary data returned an integer. Now it returns
a binary
- Now, `[] | last` and `[] | first` are both errors.
- Now, `ls | table | first` and `ls | table | last` are both errors.
2023-07-03 10:19:50 -05:00
dependabot[bot]
9d76bf97a3
Bump calamine from 0.19.1 to 0.21.2 (#9592) 2023-07-03 09:46:32 +00:00
dependabot[bot]
9cd494cdfa
Bump ureq from 2.6.2 to 2.7.1 (#9590) 2023-07-03 09:45:18 +00:00
JT
5d9e2455f7
Let with pipeline (#9589)
# Description

This changes the default behaviour of `let` to be able to take a
pipeline as its initial value.

For example:

```
> let x = "hello world" | str length
```

This is a change from the existing behaviour, where the right hand side
is assumed to be an expression. Pipelines are more general, and can be
more powerful.

My google foo is failing me, but this also fixes this issue:

```
let x = foo
```

Currently, this reads `foo` as a bareword that gets converted to a
string rather than running the `foo` command. In practice, this is
really annoying and is a really hard to spot bug in a script.

# User-Facing Changes

BREAKING CHANGE BREAKING CHANGE

`let` gains the power to be assigned via a pipeline. However, this
changes the behaviour of `let x = foo` from assigning the string "foo"
to `$x` to being "run the command `foo` and give the result to `$x`"

# 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 -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` 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.
-->
2023-07-03 17:45:10 +12:00
JT
b70cce47e2
disallow blocks as first-class values (#9587)
# Description

This PR disallows blocks as first-class values by removing the ability
to create them using the `block` syntax shape or type. Now, the parser
will only ever be able to create closures as first-class values.

This means that `{ 3 }` will always be treated as a closure, unless used
in the specifically supported use case of the literal being given as an
arg to `for`, `if` and other built-in block users.

Note: first-class value here means "value that can be passed into
commands and held in variables"

# User-Facing Changes

This may break some user scripts as `: block` is no longer allows as a
type annotation. Note: these cases were not actually supported before,
as, for example, passing a block that accessed a variable would have
errored when the block was later evaluated.

Closures do not have the restriction mentioned above and are the much
safer value to pass as first-class, so now they are the only block-like
value to be allowed to be passed.

# 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 -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` 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.
-->
2023-07-03 07:40:56 +12:00
WindSoilder
4acf21cdcf
Bracketed paste refactor (#9547)
<!--
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
This pr is a completion of https://github.com/nushell/reedline/pull/598

After that pr is merged, we no longer need to disable bracketed mode in
nushell

# 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 -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` 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.
-->
2023-07-02 14:11:12 -05:00
Yethal
9ef1203ef9
Implement annotations support in test runner (#9406)
<!--
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
Test runner now uses annotations instead of magic function names to pick
up code to run. Additionally skipping tests is now done on annotation
level so skipping and unskipping a test no longer requires changes to
the test code

In order for a function to be picked up by the test runner it needs to
meet following criteria:
* Needs to be private (all exported functions are ignored)
* Needs to contain one of valid annotations (and only the annotation)
directly above the definition, all other comments are ignored

Following are considered valid annotations:
* \# test
* \# test-skip
* \# before-all
* \# before-each
* \# after-each
* \# after-all

# 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 -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` 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.
-->
2023-07-02 10:41:33 +02:00
JT
7c80067900
use an easier-to-read date format in prompt (#9585)
# Description

Switches the right prompt to use an easier-to-read date format
(YYYY-MM-DD)

It's currently using (MM-DD-YYYY) which is only used in a few countries
but it is unfortunately ambiguous with countries that use (DD-MM-YYYY)
format (most countries). While YYYY-MM-DD is used in fewer countries
than DD-MM-YYYY it's at least unambiguous to MM-DD-YYYY countries.

More info: https://en.wikipedia.org/wiki/Date_format_by_country

Alternatively, we could spell out the month name (even abbreviated) to
make it clear as well.

# User-Facing Changes

Just changes the date in the default right prompt

# 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 -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` 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.
-->
2023-07-02 20:25:22 +12:00
Darren Schroeder
49a1e22ba3
fix right prompt in the default_env.nu (#9581)
# Description

## Before

![image](https://github.com/nushell/nushell/assets/343840/4618c7b9-693c-4658-80e7-991464b8032f)

## After

![image](https://github.com/nushell/nushell/assets/343840/81305e69-fe47-46d9-b573-d9d1992f5088)


# 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 -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` 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.
-->
2023-07-02 12:47:26 +12:00
Darren Schroeder
ebd89d8b21
fix typo in deprecated message: $nu should be $env (#9579)
# Description

This PR fixes a small typeo where it has `$nu` and it should be `$env`.
2023-07-01 17:55:25 +02:00
Brian Mortenson
9547c106d3
Add useful example to http options documentation (#9576)
This PR adds a more real-world example of how the new http options is
used, as well as some additional information in the description.
2023-07-01 10:04:30 +02:00
JT
88b22a9248
fix a few clippy issues (#9578)
# Description

A couple clippy fixes

# 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 -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` 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.
-->
2023-07-01 19:52:04 +12:00
JT
4af24363c2
remove let-env, focus on mutating $env (#9574)
# Description

For years, Nushell has used `let-env` to set a single environment
variable. As our work on scoping continued, we refined what it meant for
a variable to be in scope using `let` but never updated how `let-env`
would work. Instead, `let-env` confusingly created mutations to the
command's copy of `$env`.

So, to help fix the mental model and point people to the right way of
thinking about what changing the environment means, this PR removes
`let-env` to encourage people to think of it as updating the command's
environment variable via mutation.

Before:

```
let-env FOO = "BAR"
```

Now:

```
$env.FOO = "BAR"
```

It's also a good reminder that the environment owned by the command is
in the `$env` variable rather than global like it is in other shells.

# User-Facing Changes

BREAKING CHANGE BREAKING CHANGE

This completely removes `let-env FOO = "BAR"` so that we can focus on
`$env.FOO = "BAR"`.

# 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 -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` 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 / Before Submitting
integration scripts to update:
- ✔️
[starship](https://github.com/starship/starship/blob/master/src/init/starship.nu)
- ✔️
[virtualenv](https://github.com/pypa/virtualenv/blob/main/src/virtualenv/activation/nushell/activate.nu)
- ✔️
[atuin](https://github.com/ellie/atuin/blob/main/atuin/src/shell/atuin.nu)
(PR: https://github.com/ellie/atuin/pull/1080)
- 
[zoxide](https://github.com/ajeetdsouza/zoxide/blob/main/templates/nushell.txt)
(PR: https://github.com/ajeetdsouza/zoxide/pull/587)
- ✔️
[oh-my-posh](https://github.com/JanDeDobbeleer/oh-my-posh/blob/main/src/shell/scripts/omp.nu)
(pr: https://github.com/JanDeDobbeleer/oh-my-posh/pull/4011)
2023-07-01 07:57:51 +12:00
WindSoilder
cd56b97587
fix cd permissions when user belongs to folder group (#9531)
# Description

Fixes: #9498

Actually we don't need this pr if the upstream pr is merged:
https://github.com/ogham/rust-users/pull/45

But it doesn't have any commit since 2021, and the author seems not
active on github now, I think we have to copy the function into nushell
to get relative issue fixed...
2023-06-30 11:03:26 +02:00
WindSoilder
18fdc5a229
rename: add -b flag to support closure input (#8948)
# Description
Closes: #8108 

Adding a new `-b` flag to `rename` command. I have thought about making
it as a positional argument, but I don't think it's ok because we alredy
have `...rest` parameters

Here are how they works:
```
#  Rename fields based on a given closure
> {a: 1, b: 2} | rename -b {str upcase}
  ╭───┬───╮
  │ A │ 1 │
  │ B │ 2 │
  ╰───┴───╯

#  Rename fields based on fields' value
> {a: abc, b: def} | rename -b {|it| $it.value | str upcase}
  ╭─────┬─────╮
  │ ABC │ abc │
  │ DEF │ def │
  ╰─────┴─────╯
```
# User-Facing 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 -A
clippy::needless_collect` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` 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.
-->
2023-06-29 10:24:34 -05:00
dependabot[bot]
3699188586
Bump open from 4.1.0 to 5.0.0 (#9526) 2023-06-29 13:30:07 +00:00
Darren Schroeder
88acc11501
add input_output type to input list to return string (#9557)
# Description

This PR fixes a bug that @amtoine found. It adds an input_output type so
that `input list`'s signature supports `string` as an output.

## Before

![image](https://github.com/nushell/nushell/assets/343840/7ee2b672-9976-4c69-a9a2-686ddbd3a60d)
```
Signatures:
  list<any> | input list <string?> -> list<any>
```

## After

![image](https://github.com/nushell/nushell/assets/343840/f86747cf-a134-4bb0-b89c-2e28f590f3c3)
```
Signatures:
  list<any> | input list <string?> -> list<any>
  list<string> | input list <string?> -> <string>
```

# 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 -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` 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.
-->
2023-06-29 08:27:25 -05:00
Maxim Zhiburt
b52e31fac2
Fix #9548 (#9552)
close #9548

Could you verify @fdncred the fix?

PS: Maybe a test shall be created (to test proper colors)?

Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
2023-06-28 17:52:04 -05:00
Darren Schroeder
3fd92b6437
convert a string to a raw binary string of 0s and 1s (#9534)
# Description

This PR converts a string into a raw binary represented by a string of
0s and 1s padded to 8 digits with zeros.

This is useful for encoding data.

![image](https://github.com/nushell/nushell/assets/343840/66864c79-3da1-4007-a62b-306ed85f4df4)

# 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 -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` 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.
-->
2023-06-28 13:04:07 -05:00
A. Taha Baki
d80abb20a4
A new subcommand to str, str-expand. (#9290)
# 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.
-->

Description can be found [here:
https://github.com/nushell/nushell/discussions/9277#discussioncomment-5997793](https://github.com/nushell/nushell/discussions/9277#discussioncomment-5997793)

# User-Facing Changes

Again, examples can be found in the discussion #9277

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

# Tests + Formatting

I've written tests that cover the changes I've made.

<!--
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 -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

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

---------

Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
2023-06-28 12:57:44 -05:00
JT
9068093081
Improve type hovers (#9515)
# Description

This PR does a few things to help improve type hovers and, in the
process, fixes a few outstanding issues in the type system. Here's a
list of the changes:

* `for` now will try to infer the type of the iteration variable based
on the expression it's given. This fixes things like `for x in [1, 2, 3]
{ }` where `x` now properly gets the int type.
* Removed old input/output type fields from the signature, focuses on
the vec of signatures. Updated a bunch of dataframe commands that hadn't
moved over. This helps tie things together a bit better
* Fixed inference of types from subexpressions to use the last
expression in the block
* Fixed handling of explicit types in `let` and `mut` calls, so we now
respect that as the authoritative type

I also tried to add `def` input/output type inference, but unfortunately
we only know the predecl types universally, which means we won't have
enough information to properly know what the types of the custom
commands are.

# User-Facing Changes

Script typechecking will get tighter in some cases
Hovers should be more accurate in some cases that previously resorted to
any.

# 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 -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

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

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

---------

Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
2023-06-29 05:19:48 +12:00
Darren Schroeder
9d247387ea
update sqlparser dep to 0.34 (#9549)
# Description

This PR updates the sqlparser dep to 0.34.0.

closes #9525

# 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 -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` 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.
-->
2023-06-28 09:54:08 -05:00
dependabot[bot]
283589dc2f
Bump rust-embed from 6.6.1 to 6.7.0 (#9528) 2023-06-27 21:09:04 +00:00
Stefan Holderbach
088e6dffbe
Bump to 0.82.1 dev version (#9543)
# Description
Marks development or hotfix
2023-06-27 21:33:53 +02:00
Stefan Holderbach
ecdb023e2f
Bump version for 0.82.0 release (#9530)
# Checklist

- `nu-ansi-term` remains the same
- [x] `reedline` is released and updated
- [x] release scripts are updated for `nu-cmd-base`
- [x] info blog post is online
- [ ] release notes are ready
2023-06-27 19:11:46 +02:00
Stefan Holderbach
63aba5feb7
Pin reedline to 0.21 for release (#9532)
# Description
See changelog:
https://github.com/nushell/reedline/releases/tag/v0.21.0
2023-06-26 12:47:59 +02:00
Taylor C. Richberger
08449e174c
Format negative datetimes with rfc3339 (#9501) (#9502)
- fixes #9501 

# Description

`chrono::Datetime::to_rfc2822()` panics when it would format a negative
year. 3339 does not. This makes negative-year datetimes inconsistent
compared to positive ones, but it's better than a panic.
2023-06-25 13:53:17 -05:00
Stefan Holderbach
971f9ae0f0
Skip strum in regular nu-protocol build (#9445)
# Description
`derive(EnumIter)` is only required to run completeness tests.
Thus make the derive conditional on test and move `strum` and
`strum_macros` to the dev dependencies.

## Is it worth it?

Removing this derive does not change the binary size (checked via `cargo
bloat --crates` from `cargo-bloat`).
Compile time change is below a second so hard to judge based on a single
run of `cargo clean --profile dev; cargo build --timings`
Unsure if this negatively impacts how incremental compilation can
recompile when you switch between `cargo build`/`run` and `cargo test`
in your local workflow.

To get rid of `strum`/`strum_macros` as a proc macro crate we would need
to also remove it from `reedline`.
Further more a crate in the `polars` dependency tree uses `strum`
(curently not as relevant for the 1.0 build).
2023-06-25 20:28:37 +02:00
JT
33535c514e
Better error message if env var is used as var (#9522)
# Description

This PR improves the error message if an environment variable (that's
visible before the parser begins) is used in the form of `$PATH` instead
of `$env.PATH`.

Before:

```
Error: nu::parser::variable_not_found

  × Variable not found.
   ╭─[entry #31:1:1]
 1 │ echo $PATH
   ·      ──┬──
   ·        ╰── variable not found.
   ╰────
```

After:

```
Error: nu::parser::env_var_not_var

  × Use $env.PATH instead of $PATH.
   ╭─[entry #1:1:1]
 1 │ echo $PATH
   ·      ──┬──
   ·        ╰── use $env.PATH instead of $PATH
   ╰────
```

# User-Facing Changes

Just the improvement to the error message

# 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 -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` 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.
-->
2023-06-26 05:59:56 +12:00
TrMen
b74d508c0b
Test examples of use (#9032)
# Description
Add `test_examples()` to `use` that verifies its examples. For that, add
the necessary definitions and the `PWD` to the `nu-cmd-lang` test
support.

Note: `let-env` is a `nu-command` and thus not accessible from the
`nu-cmd-lang` tests. So replace `let-env` with `$env.<var> =`. This
should be fine, since `let-env` is supposed to be removed before 1.0
anyway.


# User-Facing Changes
Nothing

# Question for reviewer
Is there any particular reason why so many core commands (parser
keywords) don't verify their examples with tests? E.g. `break`, `hide`,
`overlay use`, etc. (I think most of them?). If there is no particular
reason, I'd make a follow up PR to enable tests for as many of them as
possible.
2023-06-25 07:43:48 -05:00
Michael Angerman
14daa93a19
Modify the bits command in nu-cmd-extra to improve visibility (#9516)
In the spirit of #9509 we are changing the visibility of the bits
commands
to align with the way they are correctly done in the bytes commands...

Thanks to @sholderbach for pointing out this nice improvement
to me in my PR earlier in the day...

```rust
mod and;
mod bits_;
mod not;
mod or;
mod rotate_left;
mod rotate_right;
mod shift_left;
mod shift_right;
mod xor;
```
2023-06-23 21:41:14 -07:00
Darren Schroeder
761946c522
add the ability to combine columns with detect columns (#9511)
# Description

This PR adds the ability to manually combine columns in the `detect
columns` command. This is useful when items are close together but want
them to be in one column.

For example, if you want to parse the output of bash's `ls` command, the
output passed into `detect columns` would look similar to this.
```
❯ ^ls -lh
total 242K
-rw-r--r-- 1 dschroeder 197121 3.5K Mar 30 10:10 CODE_OF_CONDUCT.md
-rw-r--r-- 1 dschroeder 197121  11K Jun 21 14:16 CONTRIBUTING.md
-rw-r--r-- 1 dschroeder 197121 153K Jun 21 14:16 Cargo.lock
-rw-r--r-- 1 dschroeder 197121 5.7K Jun 21 08:47 Cargo.toml
-rw-r--r-- 1 dschroeder 197121  371 Mar 30 10:10 Cross.toml
-rw-r--r-- 1 dschroeder 197121 1.1K Apr  3 08:37 LICENSE
-rw-r--r-- 1 dschroeder 197121  13K Jun 21 14:16 README.md
drwxr-xr-x 1 dschroeder 197121    0 May 24 08:06 assets
drwxr-xr-x 1 dschroeder 197121    0 Jun 21 14:16 benches
-rw-r--r-- 1 dschroeder 197121  310 Mar 30 10:10 codecov.yml
drwxr-xr-x 1 dschroeder 197121    0 Jun  1 15:30 crates
drwxr-xr-x 1 dschroeder 197121    0 May  4 07:55 dict
drwxr-xr-x 1 dschroeder 197121    0 Mar 30 10:10 docker
-rw-r--r-- 1 dschroeder 197121 1.1K Jun 12 07:03 rust-toolchain.toml
drwxr-xr-x 1 dschroeder 197121    0 May 26 07:11 scripts
drwxr-xr-x 1 dschroeder 197121    0 Jun 15 07:14 src
drwxr-xr-x 1 dschroeder 197121    0 Jun 21 09:48 target
drwxr-xr-x 1 dschroeder 197121    0 Jun 21 12:30 tests
-rw-r--r-- 1 dschroeder 197121  16K Jun 21 14:16 toolkit.nu
drwxr-xr-x 1 dschroeder 197121    0 Jun  1 15:30 wix
```
Running it through `detect columns` is helpful but notice how the Month,
Day, and Time are in their own columns.
```
❯ ^ls -lh | detect columns --no-headers --skip 1
╭────┬────────────┬─────────┬────────────┬─────────┬─────────┬─────────┬─────────┬─────────┬─────────────────────╮
│  # │  column0   │ column1 │  column2   │ column3 │ column4 │ column5 │ column6 │ column7 │       column8       │
├────┼────────────┼─────────┼────────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────────────────┤
│  0 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 3.5K    │ Mar     │ 30      │ 10:10   │ CODE_OF_CONDUCT.md  │
│  1 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 11K     │ Jun     │ 21      │ 14:16   │ CONTRIBUTING.md     │
│  2 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 153K    │ Jun     │ 21      │ 14:16   │ Cargo.lock          │
│  3 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 5.7K    │ Jun     │ 21      │ 08:47   │ Cargo.toml          │
│  4 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 371     │ Mar     │ 30      │ 10:10   │ Cross.toml          │
│  5 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 1.1K    │ Apr     │ 3       │ 08:37   │ LICENSE             │
│  6 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 13K     │ Jun     │ 21      │ 14:16   │ README.md           │
│  7 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ May     │ 24      │ 08:06   │ assets              │
│  8 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ Jun     │ 21      │ 14:16   │ benches             │
│  9 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 310     │ Mar     │ 30      │ 10:10   │ codecov.yml         │
│ 10 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ Jun     │ 1       │ 15:30   │ crates              │
│ 11 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ May     │ 4       │ 07:55   │ dict                │
│ 12 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ Mar     │ 30      │ 10:10   │ docker              │
│ 13 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 1.1K    │ Jun     │ 12      │ 07:03   │ rust-toolchain.toml │
│ 14 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ May     │ 26      │ 07:11   │ scripts             │
│ 15 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ Jun     │ 15      │ 07:14   │ src                 │
│ 16 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ Jun     │ 21      │ 09:48   │ target              │
│ 17 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ Jun     │ 21      │ 12:30   │ tests               │
│ 18 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 16K     │ Jun     │ 21      │ 14:16   │ toolkit.nu          │
│ 19 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ Jun     │ 1       │ 15:30   │ wix                 │
├────┼────────────┼─────────┼────────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────────────────┤
│  # │  column0   │ column1 │  column2   │ column3 │ column4 │ column5 │ column6 │ column7 │       column8       │
╰────┴────────────┴─────────┴────────────┴─────────┴─────────┴─────────┴─────────┴─────────┴─────────────────────╯
```
Now you can add `--combine-columns <range>` and get something like this.
```
❯ ^ls -lh | detect columns --no-headers --skip 1 --combine-columns 5..7
╭────┬────────────┬─────────┬────────────┬─────────┬─────────┬──────────────┬─────────────────────╮
│  # │  column0   │ column1 │  column2   │ column3 │ column4 │   column5    │       column6       │
├────┼────────────┼─────────┼────────────┼─────────┼─────────┼──────────────┼─────────────────────┤
│  0 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 3.5K    │ Mar 30 10:10 │ CODE_OF_CONDUCT.md  │
│  1 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 11K     │ Jun 21 14:16 │ CONTRIBUTING.md     │
│  2 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 153K    │ Jun 21 14:16 │ Cargo.lock          │
│  3 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 5.7K    │ Jun 21 08:47 │ Cargo.toml          │
│  4 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 371     │ Mar 30 10:10 │ Cross.toml          │
│  5 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 1.1K    │ Apr 3 08:37  │ LICENSE             │
│  6 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 13K     │ Jun 21 14:16 │ README.md           │
│  7 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ May 24 08:06 │ assets              │
│  8 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ Jun 21 14:16 │ benches             │
│  9 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 310     │ Mar 30 10:10 │ codecov.yml         │
│ 10 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ Jun 1 15:30  │ crates              │
│ 11 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ May 4 07:55  │ dict                │
│ 12 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ Mar 30 10:10 │ docker              │
│ 13 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 1.1K    │ Jun 12 07:03 │ rust-toolchain.toml │
│ 14 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ May 26 07:11 │ scripts             │
│ 15 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ Jun 15 07:14 │ src                 │
│ 16 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ Jun 21 09:48 │ target              │
│ 17 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ Jun 21 12:30 │ tests               │
│ 18 │ -rw-r--r-- │ 1       │ dschroeder │ 197121  │ 16K     │ Jun 21 14:16 │ toolkit.nu          │
│ 19 │ drwxr-xr-x │ 1       │ dschroeder │ 197121  │ 0       │ Jun 1 15:30  │ wix                 │
├────┼────────────┼─────────┼────────────┼─────────┼─────────┼──────────────┼─────────────────────┤
│  # │  column0   │ column1 │  column2   │ column3 │ column4 │   column5    │       column6       │
╰────┴────────────┴─────────┴────────────┴─────────┴─────────┴──────────────┴─────────────────────╯
```
Then you can fancy-it-up by tweaking the other columns and renaming
columns.
```
❯ ^ls -lh | detect columns --no-headers --skip 1 --combine-columns 5..7 | update column5 {|r| $r.column5 | into datetime} | into int column1 column3 | into filesize column4 | rename perms links user inode filesize datetime name
╭────┬────────────┬───────┬────────────┬────────┬──────────┬──────────────┬─────────────────────╮
│  # │   perms    │ links │    user    │ inode  │ filesize │   datetime   │        name         │
├────┼────────────┼───────┼────────────┼────────┼──────────┼──────────────┼─────────────────────┤
│  0 │ -rw-r--r-- │     1 │ dschroeder │ 197121 │   3.5 KB │ 2 months ago │ CODE_OF_CONDUCT.md  │
│  1 │ -rw-r--r-- │     1 │ dschroeder │ 197121 │  11.0 KB │ 2 days ago   │ CONTRIBUTING.md     │
│  2 │ -rw-r--r-- │     1 │ dschroeder │ 197121 │ 153.0 KB │ 2 days ago   │ Cargo.lock          │
│  3 │ -rw-r--r-- │     1 │ dschroeder │ 197121 │   5.7 KB │ 2 days ago   │ Cargo.toml          │
│  4 │ -rw-r--r-- │     1 │ dschroeder │ 197121 │    371 B │ 2 months ago │ Cross.toml          │
│  5 │ -rw-r--r-- │     1 │ dschroeder │ 197121 │   1.1 KB │ 2 months ago │ LICENSE             │
│  6 │ -rw-r--r-- │     1 │ dschroeder │ 197121 │  13.0 KB │ 2 days ago   │ README.md           │
│  7 │ drwxr-xr-x │     1 │ dschroeder │ 197121 │      0 B │ a month ago  │ assets              │
│  8 │ drwxr-xr-x │     1 │ dschroeder │ 197121 │      0 B │ 2 days ago   │ benches             │
│  9 │ -rw-r--r-- │     1 │ dschroeder │ 197121 │    310 B │ 2 months ago │ codecov.yml         │
│ 10 │ drwxr-xr-x │     1 │ dschroeder │ 197121 │      0 B │ 3 weeks ago  │ crates              │
│ 11 │ drwxr-xr-x │     1 │ dschroeder │ 197121 │      0 B │ 2 months ago │ dict                │
│ 12 │ drwxr-xr-x │     1 │ dschroeder │ 197121 │      0 B │ 2 months ago │ docker              │
│ 13 │ -rw-r--r-- │     1 │ dschroeder │ 197121 │   1.1 KB │ 2 weeks ago  │ rust-toolchain.toml │
│ 14 │ drwxr-xr-x │     1 │ dschroeder │ 197121 │      0 B │ 4 weeks ago  │ scripts             │
│ 15 │ drwxr-xr-x │     1 │ dschroeder │ 197121 │      0 B │ a week ago   │ src                 │
│ 16 │ drwxr-xr-x │     1 │ dschroeder │ 197121 │      0 B │ 2 days ago   │ target              │
│ 17 │ drwxr-xr-x │     1 │ dschroeder │ 197121 │      0 B │ 2 days ago   │ tests               │
│ 18 │ -rw-r--r-- │     1 │ dschroeder │ 197121 │  16.0 KB │ 2 days ago   │ toolkit.nu          │
│ 19 │ drwxr-xr-x │     1 │ dschroeder │ 197121 │      0 B │ 3 weeks ago  │ wix                 │
├────┼────────────┼───────┼────────────┼────────┼──────────┼──────────────┼─────────────────────┤
│  # │   perms    │ links │    user    │ inode  │ filesize │   datetime   │        name         │
╰────┴────────────┴───────┴────────────┴────────┴──────────┴──────────────┴─────────────────────╯
```
# 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 -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` 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.
-->
2023-06-23 16:19:08 -05:00
WMR
0c888486c9
Add custom datetime format through strftime strings (#9500)
- improves usability of datetime's in displayed text
- 
# Description
Creates a config point for specifying long / short date time formats.
Defaults to humanized as we have today.

Provides for adding strftime formats into config.nu such as:
```nu
  datetime_format: {
    normal: "%Y-%m-%d %H:%M:%S"
    table: "%Y-%m-%d"
  }
```

Example:
```bash
> $env.config.datetime_format                                                                                                                         
┏━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ normal ┃ %a, %d %b %Y %H:%M:%S %z ┃
┃ table  ┃ %m/%d/%y %I:%M:%S%p      ┃
┗━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━━━┛
> let a = (date now)                                                                                                                                  
> echo $a                                                                                                                                             
Thu, 22 Jun 2023 10:21:23 -0700
> echo [$a]                                                                                                                                           
┏━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃ 0 ┃ 06/22/23 10:21:23AM ┃
┗━━━┻━━━━━━━━━━━━━━━━━━━━━┛
```

# User-Facing Changes
Any place converting a datetime to a user displayed value should be
impacted.

# Tests + Formatting

- `cargo fmt --all -- --check` Done
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` Done
- `cargo test --workspace` Done 
- `cargo run -- crates/nu-std/tests/run.nu` Not done - doesn't seem to
work

```bash
> use toolkit.nu  # or use an `env_change` hook to activate it automatically
> toolkit check pr
``` - Done

---------

Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
Co-authored-by: Antoine Stevan <44101798+amtoine@users.noreply.github.com>
2023-06-23 15:05:04 -05:00
Michael Angerman
d1449c4ee7
cratification: move the bytes command to nu-cmd-extra (#9509)
now that #9455 has landed we can move the bytes command to nu-cmd-extra

in concert with

moving nu_command::util to nu-cmd-base
2023-06-23 12:23:08 -07:00
David Scholberg
81abb17b38
Add multiline regex flag to str replace (#9508)
# Description

This change adds a new flag to the `str replace` command: `--multiline`,
`-m`. This flag will automatically add the multiline regex flag `(?m)`
to the beginning of the supplied regex, allowing for the `^` and `$`
regex characters to match the beginnings and ends of lines,
respectively.

The main advantage of this addition is to make `str replace` more
closely match sed's default behavior of performing matches per-line with
a simple cli flag as opposed to forcing the user to add the {somewhat
clunky) regex flag themselves. This could be an especially valuable
addition since [`str replace` is listed as an alternative to sed in the
official
documentation](https://www.nushell.sh/book/coming_from_bash.html).

With this change, the following two commands would be functionally
equivalent:

```bash
# bash
printf "non-matching line\n123. one line\n124. another line\n" | sed -r 's/^[0-9]+\. //'
```

```bash
# nu
"non-matching line\n123. one line\n124. another line\n" | str replace -am '^[0-9]+\. ' ''
```

both producing the following output:

```
non-matching line
one line
another line
```

# User-Facing Changes

1. Adds a new flag to the `str replace` command: `--multiline`, `-m`.

# Tests + Formatting

I have update the unit tests to test this flag.
<!--
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 -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` 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.
-->
I will submit a PR for all relevant documentation changes as soon as
this PR is approved.
2023-06-23 20:08:02 +02:00
Darren Schroeder
cbb9f8efe4
clean up config by removing legacy options (#9496)
# Description

This PR cleans up the deprecated legacy config options that were
deprecated in nushell version 0.72.0. These are the config points that
were in the root of the config but also duplicated in the nested
structures. For instance `use_ls_colors` was in the root of the config
and also in the `ls.use_ls_colors` nested structure. This was originally
done to preserve backwards compatibility when nested structures were
introduced in the config file.

Here's a list of the legacy config points that were removed.

- `use_ls_colors` - previously replaced with `ls.use_ls_colors`
- `rm_always_trash` - previously replaced with `rm.always_trash`
- `history_file_format` - previously replaced with `history.file_format`
- `sync_history_on_enter` - previously replaced with
`history.sync_on_enter`
- `max_history_size` - previously replaced with `history.max_size`
- `quick_completions` - previously replaced with `completions.quick`
- `partial_completions` - previously replaced with `completions.partial`
- `max_external_completion_results` - previously replaced with
`completions.external.max_results`
- `completion_algorithm` - previously replaced with
`completions.algorithm`
- `case_sensitive_completions` - previously replaced with
`completions.case_sensitive`
- `enable_external_completion` - previously replaced with
`completions.external.enable`
- `external_completer` - previously replaced with
`completions.external.completer`
- `table_mode` - previously replaced with `table.mode`
- `table_index_mode` - previously replaced with `table.index_mode`
- `table_trim` - previously replaced with `table.trim`
- `show_clickable_links_in_ls` - previously replaced with
`ls.clickable_links`
- `cd_with_abbreviations` - previously replaced with `cd.abbreviations`
- `filesize_metric` - previously replaced with `filesize.metric`
- `filesize_format` - previously replaced with `filesize.format`
- `cursor_shape_vi_insert` - previously replaced with
`cursor_shape.vi_insert`
- `cursor_shape_vi_normal` - previously replaced with
`cursor_shape.vi_normal`
- `cursor_shape_emacs` - previously replaced with `cursor_shape.emacs`

Removes log_level from the config since it doesn't do anything any
longer. We moved log-level to a nushell parameter some time ago.

Renames history_isolation to isolation in the config.nu for consistency.

Fixes a couple bugs where values weren't being set in the "//
Reconstruct" sections (history_isolation, table_show_empty).

Reorganized/Moved things around a tiny bit and added a few comments.

# User-Facing Changes

history.histor_isolation is now history.isolation.
If anyone is still using the legacy config points, deprecated since
0.72.0 2022-11-29, their config will break.

# 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 -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` 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.
-->
2023-06-23 06:17:10 -05:00
Darren Schroeder
a0dafcb0f8
make history.max_size bigger (#9494)
# Description

make history.max_size bigger so it doesn't eat history

closes #9493

# 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 -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` 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.
-->
2023-06-22 19:42:55 -05:00
Antoine Stevan
78697bb8cf
move common tools from nu-command to nu-cmd-base (#9455)
related to 
- https://github.com/nushell/nushell/pull/9404

# Description
to support our cratification effort and moving non-1.0 commands outside
of the main focus, this PR
- creates a new `nu-cmd-base` crate to hold the common structs, traits
and functions used by all command-related crates
- to start the transition, moves the `input_handler` module from
`nu-command` to `nu-cmd-base`

# User-Facing Changes
```
$nothing
```

# Tests + Formatting
- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
-  `toolkit test`
-  `toolkit test stdlib`

# After Submitting
```
$nothing
```
2023-06-22 14:45:54 -07:00
JT
fbf3f7cf1c
split $nu variable into scope commands and simpler $nu (#9487)
# Description

This splits off `scope` from `$nu`, creating a set of `scope` commands
for the various types of scope you might be interested in.

This also simplifies the `$nu` variable a bit.

# User-Facing Changes

This changes `$nu` to be a bit simpler and introduces a set of `scope`
subcommands.

# 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 -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` 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.
-->
2023-06-21 09:33:01 +12:00
Antoine Stevan
aaa21c1619
make *dots* tests easier to read (#9467)
related to
- https://github.com/nushell/nushell/pull/8544

cc/ @jntrnr @ahkrr 

# Description
some of the tests in the `dots.rs` file are a bit hard to read because
some of the paths look like command calls 🤔

in an attempt to making them easier to read, in the tests of `dots.rs`,
this PR
- replaces `file .../` with `not_a_cmd.../` because it's not a call to
the `file` command
- removes the space in `not_a_cmd .../` to see it's not a command call
- adds a bit more `not a cmd` to the last tests, to be consistent with
the other tests

# User-Facing Changes
```
$nothing
```

# Tests + Formatting
- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
-  `toolkit test`
-  `toolkit test stdlib`
2023-06-20 20:28:10 +12:00
Stefan Holderbach
1be4eaeae3
Revert #8395 "Treat empty pipelines as pass-through" (#9472)
In my view we should revert nushell/nushell#8395 for now

## Potentially inconsistent application of semantic change
#8395 (1d5e7b441b) was loosening the type
coercion rules significantly, to let missing data / void returns that
were either expressed by `PipelineData::Empty` or the `Value::nothing`
be accept by specifically those commands/operations that made use of
`PipelineData::into_iter_strict()`. This could apply the new rules
inconsistently.

## Turning explicit failures into silent continuations
Furthermore the effect of this breaking change to the missing data
semantics could make previous errors into silent failures.
This could either just reduce the effectiveness of teaching error
messages in interactive use:

### Contrived example before
```bash
> cd . | where blah
Error: nu:🐚:only_supports_this_input_type

  × Input type not supported.
   ╭─[entry #13:1:1]
 1 │ cd . | where blah
   ·        ──┬──┬
   ·          │  ╰── input type: null
   ·          ╰── only list, binary, raw data or range input data is supported
   ╰────
```
### ...after, with #8395
```bash
> cd . | where blah
╭────────────╮
│ empty list │
╰────────────╯
```

In rare cases people could already try to rely on catching an error of a
downstream command to actually deal with the missing data, so it would
be a breaking change for their existing code.

## Problem with `PipelineData::into_iter_strict()`

Maybe this makes `_strict` a bit of a misnomer for this particular
iterator construction.
Further we did not actively test the `PipelineData::empty` branch before

![grafik](https://github.com/nushell/nushell/assets/15833959/c377bf1d-d47c-4c25-a342-9a348539f242)

## Parsimonious solution exists

For the motivating issue https://github.com/nushell/nushell/issues/8393
there already exists a fix that makes `ls` more consistent with the type
system by returning an empty `Value::List`
https://github.com/nushell/nushell/pull/8439
2023-06-20 20:27:18 +12:00
Maxim Zhiburt
2ec1364925
nu-table/ Fix indexing issue for table --expand (#9484)
close #9481

---------

Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
2023-06-20 20:27:00 +12:00
nibon7
69bf43ef56
Apply nightly clippy fixes (#9482)
<!--
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
This PR fixes the following nightly clippy warnings.

```
warning: you should consider adding a `Default` implementation for `HjsonFormatter<'a>`
   --> crates/nu-json/src/ser.rs:700:5
    |
700 | /     pub fn new() -> Self {
701 | |         HjsonFormatter::with_indent(b"  ")
702 | |     }
    | |_____^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#new_without_default
    = note: `#[warn(clippy::new_without_default)]` on by default
help: try adding this
    |
698 + impl<'a> Default for HjsonFormatter<'a> {
699 +     fn default() -> Self {
700 +         Self::new()
701 +     }
702 + }
    |

warning: `nu-json` (lib) generated 1 warning
warning: private item shadows public glob re-export
  --> crates/nu-command/src/strings/mod.rs:8:1
   |
8  | mod str_;
   | ^^^^^^^^^
   |
note: the name `str_` in the type namespace is supposed to be publicly re-exported here
  --> crates/nu-command/src/strings/mod.rs:17:9
   |
17 | pub use str_::*;
   |         ^^^^^^^
note: but the private item here shadows it
  --> crates/nu-command/src/strings/mod.rs:8:1
   |
8  | mod str_;
   | ^^^^^^^^^
   = note: `#[warn(hidden_glob_reexports)]` on by default

warning: incorrect NaN comparison, NaN cannot be directly compared to itself
   --> crates/nu-command/src/formats/to/nuon.rs:186:20
    |
186 |                 && val != &f64::NAN
    |                    ^^^^^^^^^^^^^^^^
    |
    = note: `#[warn(invalid_nan_comparisons)]` on by default
help: use `f32::is_nan()` or `f64::is_nan()` instead
    |
186 -                 && val != &f64::NAN
186 +                 && !val.is_nan()
    |

warning: `nu-command` (lib) generated 2 warnings (run `cargo clippy --fix --lib -p nu-command` to apply 1 suggestion)
   Compiling nu v0.81.1 (/data/source/nushell)
warning: this expression creates a reference which is immediately dereferenced by the compiler
   --> crates/nu-command/tests/commands/rm.rs:392:27
    |
392 |             dir_to_clean: &test_dir,
    |                           ^^^^^^^^^ help: change this to: `test_dir`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
    = note: `#[warn(clippy::needless_borrow)]` on by default

warning: `nu-command` (test "main") generated 1 warning (run `cargo clippy --fix --test "main"` to apply 1 suggestion)
warning: `nu-command` (lib test) generated 2 warnings (2 duplicates)
warning: `nu-json` (lib test) generated 1 warning (1 duplicate)
    Finished dev [unoptimized + debuginfo] target(s) in 3.89s

```

# User-Facing Changes
N/A

# 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 -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` 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.
-->
2023-06-20 10:17:33 +02:00
Sygmei
d25fb3ad56
Fix/input suppress output on windows (#9459)
this PR should close #9018

# Description
This PR aims to fix the `input` command with `--suppress-output` on
Windows
This fixes two separates issues : 
- Keypresses being duplicated in output due to "Release" event not being
ignored
- "Return" event from entering the `input -s "blah :"` still being in
the event buffer (need to be cleared before reading keypresses)

# Tests + Formatting

- `cargo fmt --all -- --check` ✔️ 
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` ✔️
- `cargo test --workspace` ✔️
- `cargo run -- crates/nu-std/tests/run.nu` ✔️
2023-06-19 19:04:37 +02:00
dependabot[bot]
d78e3c3b0d
Bump shadow-rs from 0.22.0 to 0.23.0 (#9473) 2023-06-19 12:40:17 +00:00
dependabot[bot]
de41c9eaf7
Bump percent-encoding from 2.2.0 to 2.3.0 (#9475) 2023-06-19 07:00:12 +00:00
dependabot[bot]
63e30899f7
Bump quick-xml from 0.28.2 to 0.29.0 (#9477) 2023-06-19 06:17:37 +00:00
dependabot[bot]
379260b110
Bump mockito from 1.0.2 to 1.1.0 (#9476) 2023-06-19 06:16:55 +00:00
dependabot[bot]
d2629293e8
Bump once_cell from 1.17.1 to 1.18.0 (#9474) 2023-06-19 06:16:00 +00:00
ahkrr
fa957a1a07
fix: 3 or more dots in file paths (#8544)
# Description
In cases that a path contained 3 or more `.` in succession followed by a
path-separator, the dots would be expanded.
This logic didn't take into account the cases where characters other
than a separator could appear before the `...`, which would lead to
`...` in filenames being expanded.
This PR changes the behavior so that path-segments consisting of 3 or
more dots only will be expanded.
This PR fixes issue #8386


# User-Facing Changes
Paths with filenames like `.../folder.../file.txt` will be correctly
expanded.

# Tests + Formatting

I added tests that cover a number of cases.
2023-06-18 15:21:57 +02:00
JT
1d5e7b441b
Treat empty pipelines as pass-through (#8395)
# Description

This allows empty pipelines to pass their emptiness through a filter.
This helps fix issues like trying to run a filter on an `ls` in an empty
directory. It also feels a bit more reasonable that a filter filters
what is *there* but doesn't require something to be there.

fixes #8393

# User-Facing Changes

No breaking changes (that I know of). Should allow filtering to be a
little less surprising with emptiness.

# 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 -A
clippy::needless_collect` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass

# After Submitting

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

---------

Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-18 11:40:18 +02:00
Michael Albers
c12b211075
Fix missing file names from rm errors (#9120)
# Description
Fixes a small bug with `rm` where names of files which couldn't be
deleted due to error were not printed.

Fixes https://github.com/nushell/nushell/issues/9004

# User-Facing Changes
Slightly different error message than previously. Nothing significant,
though.

The new error message looks like this
```
~/Projects/rust/nushell> rm /proc/1/mem                                                                                                                                                            05/06/2023 01:13:23 PM
Error: nu:🐚:remove_not_possible

  × Remove not possible
   ╭─[entry #3:1:1]
 1 │ rm /proc/1/mem
   ·    ─────┬─────
   ·         ╰── Could not delete /proc/1/mem: Operation not permitted (os error 1)
   ╰────

```

or when using a glob (only showing a single entry for brevity)

```
Error: nu:🐚:remove_not_possible

  × Remove not possible
   ╭─[entry #2:1:1]
 1 │ rm --recursive --force --verbose /proc/1/*
   ·                                  ────┬────
   ·                                      ╰── Could not delete /proc/1/comm: Operation not permitted (os error 1)
   ╰────
```

# Tests + Formatting
No new unit tests were added for this change as it is pretty difficult
to test this particular case. However, manual testing was run with the
following commands

```
rm /proc/1/mem
rm --recursive --force --verbose /proc/1/*
```

# After Submitting
N/A
2023-06-18 10:00:12 +02:00
JT
6c730def4b
revert: move to ahash (#9464)
This PR reverts https://github.com/nushell/nushell/pull/9391

We try not to revert PRs like this, though after discussion with the
Nushell team, we decided to revert this one.

The main reason is that Nushell, as a codebase, isn't ready for these
kinds of optimisations. It's in the part of the development cycle where
our main focus should be on improving the algorithms inside of Nushell
itself. Once we have matured our algorithms, then we can look for
opportunities to switch out technologies we're using for alternate
forms.

Much of Nushell still has lots of opportunities for tuning the codebase,
paying down technical debt, and making the codebase generally cleaner
and more robust. This should be the focus. Performance improvements
should flow out of that work.

Said another, optimisation that isn't part of tuning the codebase is
premature at this stage. We need to focus on doing the hard work of
making the engine, parser, etc better.

# User-Facing Changes

Reverts the HashMap -> ahash change.

cc @FilipAndersson245
2023-06-18 15:27:57 +12:00
Stefan Holderbach
f032e28657
Remove duplicated feature in nu-cmd-dataframe dep (#9461)
Minor fixup
2023-06-17 12:55:29 +02:00
Antoine Stevan
bb30051006
add a "capture" example to str replace, before the fancy ones (#9447)
closes https://github.com/nushell/nushell/issues/9437
cc/ @Sygmei 😉 

# Description
the syntax of *captures* used in `str replace` can be confusing for
people not used to the `regex` syntax.
there is already a capture example in `help str replace`
```bash
  Find and replace with fancy-regex
  > 'a successful b' | str replace '\b([sS])uc(?:cs|s?)e(ed(?:ed|ing|s?)|ss(?:es|ful(?:ly)?|i(?:ons?|ve(?:ly)?)|ors?)?)\b' '${1}ucce$2'
  a successful b
```
but it's really not trivial to understand the *capture* syntax...

this PR adds a simpler example only focused on *captures*
🥳
```bash
  Use captures to manipulate the input text
  > "abc-def" | str replace "(.+)-(.+)" "${2}_${1}"
  def_abc
```

# User-Facing Changes
an example in `help str replace` to understand the syntax of *captures*.

# Tests + Formatting
- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
-  `toolkit test`
-  `toolkit test stdlib`

# After Submitting
```
$nothing
```
2023-06-16 13:23:44 -05:00
Stefan Kupresak
67b1dcae44
Fix a panic bug in platform ansi logic (Closes #9448) (#9458)
Fixes #9448 

# Description
Attempts to fix a bug from the linked issue.

# User-Facing Changes
 - The editor doesn't crash on wrong commands
# Tests + Formatting

Tests cover my 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 -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library
2023-06-16 11:40:03 -05:00
Brian London
d00a040da9
Plugin api docs (#9452)
<!--
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.
-->

Added comments to support API docs for the `nu-plugin` crate. Removed a
few items that I'd expect should only be used internally to Nushell from
the documentation and reduced the visibility of some items that did not
need to be public.

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

# 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 -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` 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
> ```
-->

Standard tests run. Additionally numerous doctests were added to the
`nu-plugin` crate.

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

No changes to the website necessary.
2023-06-16 16:25:40 +02:00
Bram Geron
86f12ffe61
Fix bug in std dirs drop; improve documentation (#9449)
# Description

When the directory stack contains only two directories, then std dirs
drop
used to misbehave and (essentially) drop the other directory, instead of
dropping the current directory.

This is fixed by always cd'ing for std dirs drop.

Before:

    /tmp〉enter ..
    /〉dexit
    /〉

After:

    /tmp〉enter ..
    /〉dexit
    /tmp〉


Additionally, I propose to explain the relevant environment variables a
bit
more thoroughly.


# User-Facing Changes

- Fix bug in dexit (std dirs drop) when two directories are remaining

# Tests + Formatting

Added a regression test. Made the existing test easier to understand.
2023-06-16 10:42:50 +02:00
Bram Geron
df5dcdab64
Fix usage for the exit command. (#9450)
Since #8415 the `exit` command no longer manipulates shells.
2023-06-16 10:09:02 +02:00
Michael Angerman
e09d482fb7
nu-cmd-lang readme (#9446)
Add a Readme file to the crate nu-cmd-lang to better explain what this
crate is about.
2023-06-15 08:45:23 -07:00
Anas Alkhatib
b072d75300
http post --content-type should set Content-Type header (#9431)
Parse the data from string to json if the `--content-type
"application/json"` flag is used for the request.

Fixes: https://github.com/nushell/nushell/issues/9408

In the issue, the actual data is a string `'{ "query": "{ greeting }"
}'` representing json, and it would match the case `Value::String { val,
.. }`


-------------------------

The example in the issue does set the `content-type` to
`application/json` but sends the body as a string note the `'`.

```
(
::: http post
:::   -fer
:::   # -H [ "Content-Type" "application/json" ]
:::   --content-type "application/json"
:::   'http://127.0.0.1:3000/greetings/hello'
:::   '{ "query": "{ greeting }" }'
::: )
```

```
╭─────────┬───────────────────────╮
│ headers │ {record 14 fields}    │
│ body    │ {"content_type":null} │
│ status  │ 200                   │
╰─────────┴───────────────────────╯
```

If we send the same request but using actual json as the body, the
Header is set correctly.

```
(        
::: http post
:::   -fer
:::   # -H [ "Content-Type" "application/json" ]
:::   --content-type "application/json"
:::   'http://127.0.0.1:3000/greetings/hello'
:::   { "query": "{ greeting }" }
::: )
```
```

╭─────────┬─────────────────────────────────────╮
│ headers │ {record 14 fields}                  │
│ body    │ {"content_type":"application/json"} │
│ status  │ 200                                 │
╰─────────┴─────────────────────────────────────╯
```
2023-06-15 06:51:35 -05:00
Stefan Holderbach
d371a78a0b
Drop unused nu-color-config in nu-cmd-lang (#9444)
# Description
Unneeded dependency as `help` moved back to `nu-command`.
Currently probably won't provide a compile time benefit.
2023-06-15 13:12:01 +02:00
WindSoilder
90863439d1
allow comment in multiple line pipeline (#9436)
<!--
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
- fixes: #5517
- fixes: #9250

For the following commands:
```
ls
# | le
| length
```

I found that it generates a bad lite parsing result:
```
LiteBlock { 
    block: [
        LitePipeline { 
            commands: [
                Command(None, LiteCommand { comments: [], parts: [Span { start: 138600, end: 138602 }] })
            ]
        },
        LitePipeline { 
            commands: [
                Command(Some(Span { start: 138610, end: 138611 }),
                LiteCommand { comments: [Span { start: 138603, end: 138609 }], parts: [Span { start: 138612, end: 138618 }] })
            ]
        }
    ]
}
```

Which should contains only one `LitePipeline`, and the second
`LitePipeline` is generated because of `Eol` lex token:
```
[
    Token { contents: Item, span: Span { start: 138600, end: 138602 } },
    Token { contents: Eol, span: Span { start: 138602, end: 138603 } },    // it generates the second LitePipeline
    Token { contents: Comment, span: Span { start: 138603, end: 138609 } },
    Token { contents: Pipe, span: Span { start: 138610, end: 138611 } },
    Token { contents: Item, span: Span { start: 138612, end: 138618 } }
]
```

To fix the issue, I remove the `Eol` token when we meet `Comment` right
after `Eol`, then it will generate a good LiteBlock, and everything will
work fine.

### After the fix:
Token:
```
[
  Token { contents: Item, span: Span { start: 138618, end: 138620 } },
  Token { contents: Comment, span: Span { start: 138622, end: 138628 } },
  Token { contents: Pipe, span: Span { start: 138629, end: 138630 } },
  Token { contents: Item, span: Span { start: 138631, end: 138637 } }
]
```

LiteBlock:
```
LiteBlock {
  block: [
    LitePipeline { 
      commands: [
        Command(
            None, 
            LiteCommand { 
                comments: [Span { start: 138622, end: 138628 }],
                parts: [Span { start: 138618, end: 138620 }] 
            }
        ),
        Command(
            Some(Span { start: 138629, end: 138630 }),
            LiteCommand { comments: [], parts: [Span { start: 138631, end: 138637 }] })] }] }
```
<!--
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 -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` 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.
-->
2023-06-15 13:11:42 +02:00
Anas Alkhatib
33ad2a36bd
Fix clippy errors (Mac) (#9440)
<!--
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

Was getting errors when running the clip checks on another PR.
Applied the suggested fixes.


<img width="1792" alt="image"
src="https://github.com/nushell/nushell/assets/432535/bec30bd9-307d-4877-9eb8-1f8f3ed3edd9">


<img width="1527" alt="image"
src="https://github.com/nushell/nushell/assets/432535/f540da61-aa81-4a9e-9948-46d8d45afecb">
2023-06-15 07:30:54 +02:00
Filip Andersson
2fd4a36c0d
Changes global allocator to mimalloc, improving performance. (#9415)
# 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.
-->

this PR makes nushell use mimalloc as the default allocator, this has
the benefit of reducing startup time on my machine. `17%` on linux and
`22%` on windows, when testing using hyperfine.
the overhead to compile seem to be quite small, aswell as the increase
of binary size quite small
on linux the binary went from `33.1mb` to `33.2mb`

linux

![image](https://github.com/nushell/nushell/assets/17986183/ba5379b4-2c08-483a-a9ff-a9d8524d2943)

windows 

![image](https://github.com/nushell/nushell/assets/17986183/fda5090f-96a9-48d1-ada4-617694b9d880)


# 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 -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` 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.
-->
2023-06-14 17:27:12 -05:00
Stefan Holderbach
46eebc644c
Break up interdependencies of command crates (#9429)
# Description
Make sure that our different crates that contain commands can be
compiled in parallel.
This can under certain circumstances accelerate the compilation with
sufficient multithreading available.

## Details
- Move `help` commands from `nu-cmd-lang` back to `nu-command`
- This also makes sense as the commands are implemented in an
ANSI-terminal specific way
- Make `nu-cmd-lang` only a dev dependency for `nu-command`
- Change context creation helpers for `nu-cmd-extra` and
`nu-cmd-dataframe` to have a consistent api used in
`src/main.rs`:`get_engine_state()`
- `nu-command` now indepedent from `nu-cmd-extra` and `nu-cmd-dataframe`
that are now dependencies of `nu` directly. (change to internal
features)
- Fix tests that previously used `nu-command::create_default_context()`
with replacement functions

## From scratch compilation times:

just debug (dev) build and default features
```
cargo clean --profile dev && cargo build --timings
```

### before

![grafik](https://github.com/nushell/nushell/assets/15833959/e49f1f42-2e53-4a6c-bc23-625b686af1bc)

### after

![grafik](https://github.com/nushell/nushell/assets/15833959/8dec4723-e625-4a86-b91e-e6e808f64726)

# User-Facing Changes
None direct, only change to compilation on multithreaded jobs expected.

# Tests + Formatting
Tests that previously chose to use `nu-command` for their scope will
still use `nu-cmd-lang` + `nu-command` (command list in the granularity
at the time)
2023-06-14 23:12:55 +02:00
Han Junghyuk
b14bdd865f
Remove ZB and ZiB from file size type (#9427)
<!--
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.
-->
This PR removes ZB and ZiB from file size type, as they 
were showing incorrect values due to an integer overflow.

Fixes: #9337
# 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 -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` 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.
-->
2023-06-14 10:53:32 -05:00
Stefan Holderbach
604aadc938
Move explore command out of nu-command deps (#9421)
# Description
For better parallel compilation, make sure that `nu-command` doesn't
depend on `nu-explore`.

Moves the `nu_protocol::Command` implementation into `nu-explore`. Adds
`nu_explore::add_explore_context()` which is used in `main.rs` to add
the `explore` command.

Minor improvement in compile time ~0.5 sec observed as `nu-command`
still blocks on `nu-cmd-lang` as well.

## `cargo build --timings` before


![grafik](https://github.com/nushell/nushell/assets/15833959/583aa56e-6a1e-47b9-ba00-6a86293a38db)

## `cargo build --timings` after


![grafik](https://github.com/nushell/nushell/assets/15833959/30687575-c1c8-4635-bcdd-7ce9488fcfff)


# User-Facing Changes
None
2023-06-14 01:18:36 +02:00
Darren Schroeder
2b181bf69c
update ini dependency (#9426)
# Description

This PR updates the ini dependency.

# 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 -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` 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.
-->
2023-06-13 13:33:00 -05:00
Darren Schroeder
cdb7b9d9b2
update dfr to polars 0.30.0 (#9424)
# Description

Update the polars dependency for dataframes to stay on-version.

# 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 -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` 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.
-->
2023-06-13 12:05:45 -05:00