2022-03-17 23:35:50 +01:00
|
|
|
mod alias;
|
2021-04-03 20:40:54 +02:00
|
|
|
mod all;
|
|
|
|
mod any;
|
2019-12-15 17:15:06 +01:00
|
|
|
mod append;
|
2022-12-09 17:20:58 +01:00
|
|
|
mod assignment;
|
New commands: `break`, `continue`, `return`, and `loop` (#7230)
# Description
This adds `break`, `continue`, `return`, and `loop`.
* `break` - breaks out a loop
* `continue` - continues a loop at the next iteration
* `return` - early return from a function call
* `loop` - loop forever (until the loop hits a break)
Examples:
```
for i in 1..10 {
if $i == 5 {
continue
}
print $i
}
```
```
for i in 1..10 {
if $i == 5 {
break
}
print $i
}
```
```
def foo [x] {
if true {
return 2
}
$x
}
foo 100
```
```
loop { print "hello, forever" }
```
```
[1, 2, 3, 4, 5] | each {|x|
if $x > 3 { break }
$x
}
```
# User-Facing Changes
Adds the above commands.
# 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.
2022-11-24 21:39:16 +01:00
|
|
|
mod break_;
|
2020-05-10 01:05:48 +02:00
|
|
|
mod cal;
|
2019-12-15 17:15:06 +01:00
|
|
|
mod cd;
|
|
|
|
mod compact;
|
2023-12-16 16:07:08 +01:00
|
|
|
mod complete;
|
2023-09-25 15:00:59 +02:00
|
|
|
mod config_env_default;
|
|
|
|
mod config_nu_default;
|
New commands: `break`, `continue`, `return`, and `loop` (#7230)
# Description
This adds `break`, `continue`, `return`, and `loop`.
* `break` - breaks out a loop
* `continue` - continues a loop at the next iteration
* `return` - early return from a function call
* `loop` - loop forever (until the loop hits a break)
Examples:
```
for i in 1..10 {
if $i == 5 {
continue
}
print $i
}
```
```
for i in 1..10 {
if $i == 5 {
break
}
print $i
}
```
```
def foo [x] {
if true {
return 2
}
$x
}
foo 100
```
```
loop { print "hello, forever" }
```
```
[1, 2, 3, 4, 5] | each {|x|
if $x > 3 { break }
$x
}
```
# User-Facing Changes
Adds the above commands.
# 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.
2022-11-24 21:39:16 +01:00
|
|
|
mod continue_;
|
2023-08-24 14:08:58 +02:00
|
|
|
mod conversions;
|
2024-02-25 00:01:29 +01:00
|
|
|
#[cfg(feature = "sqlite")]
|
Fix memory consumption of into sqlite (#10232)
# Description
Currently, the `into sqlite` command collects the entire input stream
into a single Value, which soaks up the entire input into memory, before
it ever tries to write anything to the DB. This is very problematic for
large inputs; for example, I tried transforming a multi-gigabyte CSV
file into SQLite, and before I knew what was happening, my system's
memory was completely exhausted, and I had to hard reboot to recover.
This PR fixes this problem by working directly with the pipeline stream,
inserting into the DB as values are read from the stream.
In order to facilitate working with the stream directly, I introduced a
new `Table` struct to store the connection and a few configuration
parameters, as well as to make it easier to lazily create the table on
the first read value.
In addition to the purely functional fixes, a few other changes were
made to the serialization and user facing behavior.
### Serialization
Much of the preexisting code was focused on generating the exact text
needed for a SQL statement. This is unneeded and less safe than using
the `rusqlite` crate's serialization for native Rust types along with
prepared statements.
### User-Facing Changes
Currently, the command is very liberal in the input types it accepts.
The strategy is basically if it is a record, try to follow its structure
and make an analogous SQL row, which is pretty reasonable. However, when
it's not a record, it basically tries to guess what the user wanted and
just makes a single column table and serializes the value into that one
column, whatever type it may be.
This has been changed so that it only accepts records as input. If the
user wants to serialize non-record types into SQL, then they must
explicitly opt into doing this by constructing a record or table with it
first. For a utility for inserting data into SQL, I think it makes more
sense to let the user choose how to convert their data, rather than make
a choice for them that may surprise them.
However, I understand this may be a controversial change. If the
maintainers don't agree, I can change this back.
#### Long switch names
The `file_name` and `table_name` long form switches are currently
snake_case and expect to be as such at the command line. These have been
changed to kebab-case to be more conventional.
# Tests + Formatting
To test the memory consumption, I used [this publicly available index of
all Wikipedia articles](https://dumps.wikimedia.org/enwiki/20230820/),
using the first 10,000, 100,000, and 1,000,000 entries, in that order. I
ran the following script to benchmark the changes against the current
stable release:
```nu
#!/usr/bin/nu
# let shellbin = $"($env.HOME)/src/nushell/target/aarch64-linux-android/release/nu"
let shellbin = "nu"
const dbpath = 'enwiki-index.db'
[10000, 100000, 1000000]
| each {|rows|
rm -f $dbpath;
do { time -f '%M %e %U %S' $shellbin -c (
$"bzip2 -cdk ~/enwiki-20230820-pages-articles-multistream-index.txt.bz2
| head -n ($rows)
| lines
| parse '{offset}:{id}:{title}'
| update cells -c [offset, id] { into int }
| into sqlite ($dbpath)"
)
}
| complete
| get stderr
| str trim
| parse '{rss_max} {real} {user} {kernel}'
| update cells -c [rss_max] { $"($in)kb" | into filesize }
| update cells -c [real, user, kernel] { $"($in)sec" | into duration }
| insert rows $rows
| roll right
}
| flatten
| to nuon
```
This yields the following results
Current stable release:
|rows|rss_max|real|user|kernel|
|-|-|-|-|-|
|10000|53.6 MiB|770ms|460ms|420ms|
|100000|209.6 MiB|6sec 940ms|3sec 740ms|4sec 380ms|
|1000000|1.7 GiB|1min 8sec 810ms|38sec 690ms|42sec 550ms|
This PR:
|rows|rss_max|real|user|kernel|
|-|-|-|-|-|
|10000|38.2 MiB|780ms|440ms|410ms|
|100000|39.8 MiB|6sec 450ms|3sec 530ms|4sec 160ms|
|1000000|39.8 MiB|1min 3sec 230ms|37sec 440ms|40sec 180ms|
# Note
I started this branch kind of at the same time as my others, but I
understand the feedback that smaller PRs are preferred. Let me know if
it would be better to split this up.
I do think the scope of the changes are on the bigger side even without
the behavior changes I mentioned, so I'm not sure if that will help this
particular PR very much, but I'm happy to oblige on request.
2024-01-16 04:41:25 +01:00
|
|
|
mod database;
|
2022-05-23 18:59:34 +02:00
|
|
|
mod date;
|
2023-10-24 19:48:05 +02:00
|
|
|
mod debug_info;
|
2021-01-07 18:14:51 +01:00
|
|
|
mod def;
|
2019-12-15 17:15:06 +01:00
|
|
|
mod default;
|
2023-07-21 15:25:06 +02:00
|
|
|
mod detect_columns;
|
2022-06-30 03:01:34 +02:00
|
|
|
mod do_;
|
2020-04-26 08:34:45 +02:00
|
|
|
mod drop;
|
2024-02-14 23:55:21 +01:00
|
|
|
mod du;
|
2020-04-13 09:59:57 +02:00
|
|
|
mod each;
|
2020-07-06 10:23:27 +02:00
|
|
|
mod echo;
|
2020-10-06 12:21:20 +02:00
|
|
|
mod empty;
|
2022-07-12 13:03:50 +02:00
|
|
|
mod error_make;
|
2020-06-16 21:58:41 +02:00
|
|
|
mod every;
|
2022-12-21 23:33:26 +01:00
|
|
|
mod exec;
|
2022-08-02 17:26:16 +02:00
|
|
|
mod export_def;
|
`string | fill` counts clusters, not graphemes; and doesn't count ANSI escape codes (#8134)
Enhancement of new `fill` command (#7846) to handle content including
ANSI escape codes for formatting or multi-code-point Unicode grapheme
clusters.
In both of these cases, the content is (many) bytes longer than its
visible length, and `fill` was counting the extra bytes so not adding
enough fill characters.
# Description
This script:
```rust
# the teacher emoji `\u{1F9D1}\u{200D}\u{1F3EB}` is 3 code points, but only 1 print position wide.
echo "This output should be 3 print positions wide, with leading and trailing `+`"
$"\u{1F9D1}\u{200D}\u{1F3EB}" | fill -c "+" -w 3 -a "c"
echo "This output should be 3 print positions wide, with leading and trailing `+`"
$"(ansi green)a(ansi reset)" | fill -c "+" -w 3 -a c
echo ""
```
Was producing this output:
```rust
This output should be 3 print positions wide, with leading and trailing `+`
🧑🏫
This output should be 3 print positions wide, with leading and trailing `+`
a
```
After this PR, it produces this output:
```rust
This output should be 3 print positions wide, with leading and trailing `+`
+🧑🏫+
This output should be 3 print positions wide, with leading and trailing `+`
+a+
```
# User-Facing Changes
Users may have to undo fixes they may have introduced to work around the
former behavior. I have one such in my prompt string that I can now
revert.
# Tests + Formatting
Don't forget to add tests that cover your changes.
-- Done
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` to check that you're using the standard code
style
- [x] `cargo test --workspace` to check that all tests pass
# After Submitting
`fill` command not documented in the book, and it still talks about `str
lpad/rpad`. I'll fix.
Note added dependency on a new library `print-positions`, which is an
iterator that yields a complete print position (cluster + Ansi sequence)
per call. Should this be vendored?
2023-02-20 13:32:20 +01:00
|
|
|
mod fill;
|
2024-03-26 17:50:36 +01:00
|
|
|
mod filter;
|
2021-08-27 10:48:41 +02:00
|
|
|
mod find;
|
2019-12-15 17:15:06 +01:00
|
|
|
mod first;
|
2020-10-14 11:36:11 +02:00
|
|
|
mod flatten;
|
2022-12-11 17:46:03 +01:00
|
|
|
mod for_;
|
2019-12-15 17:15:06 +01:00
|
|
|
mod format;
|
2023-10-19 16:30:34 +02:00
|
|
|
mod generate;
|
2019-12-15 17:15:06 +01:00
|
|
|
mod get;
|
2022-10-15 18:00:38 +02:00
|
|
|
mod glob;
|
2019-12-15 17:15:06 +01:00
|
|
|
mod group_by;
|
2020-11-30 18:47:35 +01:00
|
|
|
mod hash_;
|
2020-03-29 04:05:57 +02:00
|
|
|
mod headers;
|
2021-02-26 21:05:22 +01:00
|
|
|
mod help;
|
2019-12-15 17:15:06 +01:00
|
|
|
mod histogram;
|
2024-03-08 08:18:26 +01:00
|
|
|
mod ignore;
|
2022-03-17 18:55:02 +01:00
|
|
|
mod insert;
|
2023-05-22 20:54:04 +02:00
|
|
|
mod inspect;
|
Add interleave command for reading multiple streams in parallel (#11955)
<!--
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 command mixes input from multiple sources and sends items to the
final stream as soon as they're available. It can be called as part of a
pipeline with input, or it can take multiple closures and mix them that
way.
See `crates/nu-command/tests/commands/interleave.rs` for a practical
example. I imagine this will be most often used to run multiple commands
in parallel and print their outputs line-by-line. A stdlib command could
potentially use `interleave` to make this particular use case easier.
It's quite common to wish that nushell had a command for running things
in the background, and instead of providing job control, this provides
an alternative to some use cases for that by just allowing multiple
commands to run simultaneously and direct their output to the same
place.
This enables certain things that are not possible with `par-each` - for
example, you may wish to run `make` across several projects in parallel:
```nushell
(ls projects).name | par-each { |project| cd $project; make }
```
This works well enough, but the output will only be available after each
`make` command finishes. `interleave` allows you to get each line:
```nushell
interleave ...(
(ls projects).name | each { |project|
{
cd $project
make | lines | each { |line| {project: $project, out: $line} }
}
}
)
```
The result of this is a stream that you could process further - for
example, by saving to a text file.
Note that the closures themselves are not run in parallel. The initial
execution happens serially, and then the streams are consumed in
parallel.
# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->
Adds a new command.
# Tests + Formatting
<!--
Don't forget to add tests that cover your changes.
Make sure you've run and fixed any issues with these commands:
- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to
check that you're using the standard code style
- `cargo test --workspace` to check that all tests pass (on Windows make
sure to [enable developer
mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging))
- `cargo run -- -c "use std testing; testing run-tests --path
crates/nu-std"` 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
> ```
-->
- :green_circle: `toolkit fmt`
- :green_circle: `toolkit clippy`
- :green_circle: `toolkit test`
- :green_circle: `toolkit test stdlib`
# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2024-03-01 23:56:37 +01:00
|
|
|
mod interleave;
|
2023-07-23 20:14:51 +02:00
|
|
|
mod into_datetime;
|
2021-09-03 01:19:54 +02:00
|
|
|
mod into_filesize;
|
2020-08-27 07:44:18 +02:00
|
|
|
mod into_int;
|
2023-03-17 00:57:20 +01:00
|
|
|
mod join;
|
2019-12-15 17:15:06 +01:00
|
|
|
mod last;
|
2021-03-13 22:46:40 +01:00
|
|
|
mod length;
|
2022-06-24 23:55:25 +02:00
|
|
|
mod let_;
|
2019-12-15 17:15:06 +01:00
|
|
|
mod lines;
|
2022-12-11 17:46:03 +01:00
|
|
|
mod loop_;
|
2019-12-15 17:15:06 +01:00
|
|
|
mod ls;
|
2023-03-27 00:31:57 +02:00
|
|
|
mod match_;
|
2020-04-18 03:50:58 +02:00
|
|
|
mod math;
|
2020-04-30 06:18:24 +02:00
|
|
|
mod merge;
|
Add `mktemp` command (#11005)
closes #10845
I've opened this a little prematurely to get some questions answered
before I cleanup the code.
As I started trying to better understand GNUs `mktemp` I've realized its
kind of peculiar and we might want to change its behavior to introduce
it to nushell.
#### quiet and dry run
Does it make sense to keep the `quiet` and `dry_run` flags? I don't
think so. The GNU documentation says this about the dry run flag "Using
the output of this command to create a new file is inherently unsafe, as
there is a window of time between generating the name and using it where
another process can create an object by the same name." So yeah why keep
it? As far as quiet goes, does it make sense to silence the errors in
nushell?
#### other confusing flags
According to the [gnu
docs](https://www.gnu.org/software/coreutils/manual/html_node/mktemp-invocation.html),
the `-t` flag is deprecated and the `-p`/ `--tempdir` are the same flag
with the only difference being `--tempdir` takes an optional path, Given
that, I've broken the `-p` away from `--tempdir`. Now there is one
switch `--tmpdir`/`-t` and one named param `--tmpdir-path`/`-p`.
GNU mktemp
```
-p DIR, --tmpdir[=DIR] interpret TEMPLATE relative to DIR; if DIR is not
specified, use $TMPDIR if set, else /tmp. With
this option, TEMPLATE must not be an absolute name;
unlike with -t, TEMPLATE may contain slashes, but
mktemp creates only the final component
-t interpret TEMPLATE as a single file name component,
relative to a directory: $TMPDIR, if set; else the
directory specified via -p; else /tmp [deprecated]
```
to
nushell mktemp
```
-p, --tmpdir-path <Filepath> # named param, must provide a path
-t, --tmpdir # a switch
```
Is this a terrible idea?
What should I do?
---------
Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
2023-11-18 02:30:53 +01:00
|
|
|
mod mktemp;
|
2020-07-06 17:27:01 +02:00
|
|
|
mod move_;
|
2022-11-11 07:51:08 +01:00
|
|
|
mod mut_;
|
2022-06-22 05:27:58 +02:00
|
|
|
mod network;
|
2022-06-26 13:53:06 +02:00
|
|
|
mod nu_check;
|
2022-02-04 03:01:45 +01:00
|
|
|
mod open;
|
Fix unexpected flattening of data by par-each (Issue #8497) (#9007)
# Description
Previously, `par-each` acted like a `flatmap`: first mapping the data,
then applying a `flatten`. This is unlike `each`, which just maps the
data. Now `par-each` works like `each` in this regard, leaving nested
data unflattened.
Fixes #8497
# User-Facing Changes
Previously:
`[1 2 3] | par-each {|e| [$e, $e] }` --> `[1,1,2,2,3,3]`
Now:
`[1 2 3] | par-each {|e| [$e, $e] }` --> `[[1,1],[2,2],[3,3]]`
# Tests
This adds one test that verifies the lack of flattening for `par-each`.
2023-04-26 23:27:27 +02:00
|
|
|
mod par_each;
|
2022-02-04 03:01:45 +01:00
|
|
|
mod parse;
|
|
|
|
mod path;
|
2022-08-18 18:58:51 +02:00
|
|
|
mod platform;
|
2019-12-15 17:15:06 +01:00
|
|
|
mod prepend;
|
2022-07-02 16:54:49 +02:00
|
|
|
mod print;
|
2022-11-23 01:58:11 +01:00
|
|
|
#[cfg(feature = "sqlite")]
|
2022-04-20 06:58:21 +02:00
|
|
|
mod query;
|
2020-06-25 07:51:09 +02:00
|
|
|
mod random;
|
2019-12-15 17:15:06 +01:00
|
|
|
mod range;
|
2022-11-22 19:26:13 +01:00
|
|
|
mod redirection;
|
2020-08-04 19:16:19 +02:00
|
|
|
mod reduce;
|
2022-02-08 21:57:46 +01:00
|
|
|
mod reject;
|
2020-03-03 22:01:24 +01:00
|
|
|
mod rename;
|
New commands: `break`, `continue`, `return`, and `loop` (#7230)
# Description
This adds `break`, `continue`, `return`, and `loop`.
* `break` - breaks out a loop
* `continue` - continues a loop at the next iteration
* `return` - early return from a function call
* `loop` - loop forever (until the loop hits a break)
Examples:
```
for i in 1..10 {
if $i == 5 {
continue
}
print $i
}
```
```
for i in 1..10 {
if $i == 5 {
break
}
print $i
}
```
```
def foo [x] {
if true {
return 2
}
$x
}
foo 100
```
```
loop { print "hello, forever" }
```
```
[1, 2, 3, 4, 5] | each {|x|
if $x > 3 { break }
$x
}
```
# User-Facing Changes
Adds the above commands.
# 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.
2022-11-24 21:39:16 +01:00
|
|
|
mod return_;
|
2019-12-15 17:15:06 +01:00
|
|
|
mod reverse;
|
|
|
|
mod rm;
|
2021-02-23 19:29:07 +01:00
|
|
|
mod roll;
|
90 degree table rotations (clockwise and counter-clockwise) (#3086)
Also for 180 degree is expected. Rotation is not exactly like pivoting (transposing)
for instance, given the following table:
```
> echo [[col1, col2, col3]; [cell1, cell2, cell3] [cell4, cell5, cell6]]
───┬───────┬───────┬───────
# │ col1 │ col2 │ col3
───┼───────┼───────┼───────
0 │ cell1 │ cell2 │ cell3
1 │ cell4 │ cell5 │ cell6
───┴───────┴───────┴───────
```
To rotate it counter clockwise by 90 degrees, we can resort to first transposing (`pivot`)
them adding a new column (preferably integers), sort by that column from highest to lowest,
then remove the column and we have a counter clockwise rotation.
```
> echo [[col1, col2, col3]; [cell1, cell2, cell3] [cell4, cell5, cell6]] | pivot | each --numbered { = $it.item | insert idx $it.index } | sort-by idx | reverse | reject idx
───┬─────────┬─────────┬─────────
# │ Column0 │ Column1 │ Column2
───┼─────────┼─────────┼─────────
0 │ col3 │ cell3 │ cell6
1 │ col2 │ cell2 │ cell5
2 │ col1 │ cell1 │ cell4
───┴─────────┴─────────┴─────────
```
Which we can get easily, in this case, by doing:
```
> echo [[col1, col2, cel3]; [cell1, cell2, cell3] [cell4, cell5, cell6]] | rotate counter-clockwise
───┬─────────┬─────────┬─────────
# │ Column0 │ Column1 │ Column2
───┼─────────┼─────────┼─────────
0 │ col3 │ cell3 │ cell6
1 │ col2 │ cell2 │ cell5
2 │ col1 │ cell1 │ cell4
───┴─────────┴─────────┴─────────
```
There are also many powerful use cases with rotation, it makes a breeze creating tables with many columns, say:
```
echo 0..12 | rotate counter-clockwise | reject Column0
───┬─────────┬─────────┬─────────┬─────────┬─────────┬─────────┬─────────┬─────────┬─────────┬──────────┬──────────┬──────────┬──────────
# │ Column1 │ Column2 │ Column3 │ Column4 │ Column5 │ Column6 │ Column7 │ Column8 │ Column9 │ Column10 │ Column11 │ Column12 │ Column13
───┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼──────────┼──────────┼──────────┼──────────
0 │ 0 │ 1 │ 2 │ 3 │ 4 │ 5 │ 6 │ 7 │ 8 │ 9 │ 10 │ 11 │ 12
───┴─────────┴─────────┴─────────┴─────────┴─────────┴─────────┴─────────┴─────────┴─────────┴──────────┴──────────┴──────────┴──────────
```
2021-02-22 12:56:34 +01:00
|
|
|
mod rotate;
|
2022-03-08 02:17:33 +01:00
|
|
|
mod run_external;
|
2019-12-15 17:15:06 +01:00
|
|
|
mod save;
|
2020-05-07 13:03:43 +02:00
|
|
|
mod select;
|
2020-04-20 08:41:51 +02:00
|
|
|
mod semicolon;
|
2022-12-07 03:48:03 +01:00
|
|
|
mod seq;
|
2022-11-10 02:06:47 +01:00
|
|
|
mod seq_char;
|
2024-02-17 09:51:20 +01:00
|
|
|
mod seq_date;
|
2020-07-15 03:44:49 +02:00
|
|
|
mod skip;
|
2022-12-01 14:11:30 +01:00
|
|
|
mod sort;
|
2019-12-15 17:15:06 +01:00
|
|
|
mod sort_by;
|
2022-08-31 22:32:56 +02:00
|
|
|
mod source_env;
|
2019-12-15 17:15:06 +01:00
|
|
|
mod split_by;
|
|
|
|
mod split_column;
|
2020-05-24 08:41:30 +02:00
|
|
|
mod split_row;
|
2020-05-27 00:19:18 +02:00
|
|
|
mod str_;
|
2022-10-03 18:40:16 +02:00
|
|
|
mod table;
|
2022-04-07 22:49:28 +02:00
|
|
|
mod take;
|
Add `tee` command for operating on copies of streams (#11928)
<!--
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!
-->
[Related conversation on
Discord](https://discord.com/channels/601130461678272522/615329862395101194/1209951539901366292)
# 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 is inspired by the Unix tee command, but significantly more
powerful. Rather than just writing to a file, you can do any kind of
stream operation that Nushell supports within the closure.
The equivalent of Unix `tee -a file.txt` would be, for example, `command
| tee { save -a file.txt }` - but of course this is Nushell, and you can
do the same with structured data to JSON objects, or even just run any
other command on the system with it.
A `--stderr` flag is provided for operating on the stderr stream from
external programs. This may produce unexpected results if the stderr
stream is not then also printed by something else - nushell currently
doesn't. See #11929 for the fix for that.
# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->
If someone was using the system `tee` command, they might be surprised
to find that it's different.
# Tests + Formatting
<!--
Don't forget to add tests that cover your changes.
Make sure you've run and fixed any issues with these commands:
- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to
check that you're using the standard code style
- `cargo test --workspace` to check that all tests pass (on Windows make
sure to [enable developer
mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging))
- `cargo run -- -c "use std testing; testing run-tests --path
crates/nu-std"` 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
> ```
-->
- :green_circle: `toolkit fmt`
- :green_circle: `toolkit clippy`
- :green_circle: `toolkit test`
- :green_circle: `toolkit test stdlib`
# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2024-02-29 00:08:31 +01:00
|
|
|
mod tee;
|
2023-11-22 03:48:39 +01:00
|
|
|
mod terminal;
|
2022-12-23 01:38:07 +01:00
|
|
|
mod to_text;
|
2020-02-18 21:54:32 +01:00
|
|
|
mod touch;
|
2022-06-23 02:19:06 +02:00
|
|
|
mod transpose;
|
2022-11-24 05:52:11 +01:00
|
|
|
mod try_;
|
use uutils/coreutils cp command in place of nushell's cp command (#10097)
<!--
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
Hi. Basically, this is a continuation of the work that @fdncred started.
Given some nice discussions on #9463 , and [merged uutils
PR](https://github.com/uutils/coreutils/pull/5152) from @tertsdiepraam
we have decided to give the `cp` command the `crawl` stage as it was
named.
> [!NOTE]
Given that the `uutils` crate has not made the release for the merged
PR, just make sure you checkout latest and put it in the required place
to make this PR work.
The aim of this PR is for is to see how to move forward using `uutils`
crate. In order to getting this started, I have made the current
`nushell cp tests` pass along with some extra ones I copied over from
the `uutils` repo.
With all of that being said, things that would be nice to decide, and
keep working on:
Crawl:
- Handling of certain `named` flags, with their long and short
forms(e.g. --update, --reflink, --preserve, etc), and using default
values. Maybe `-u` can already have a `default_missing_value`.
- Should we maybe just support one single option `switch` flags (see
`--backup` in code) as a contrast to the other named args.
- Complete test coverage from `uutils`. They had > 100 tests, and I
could only port like 12 as they are a bit time consuming given they
cannot be straight up copy pasted. Maybe we do not need all >100, but
maybe the more relevant to what we want.
- Refactor this code
Walk:
- Non fatal errors on `copy` from `utils`. Currently it just sends it to
stdout but errors have no span
- Better integration
An added possibility is the addition of `SyntaxShape::OneOf()` for
`Named` arguments which was briefly mentioned in the discord server, but
that is still to be decided. This could greatly improve some of the
integration. This would enable something like `cp --preserve [all
timestamp]` or `cp --preserve all` to both work.
I did not want to keep holding on this, and wait till I was happy with
the code because I think its nice if everyone can start up and suggest
refactors, but the main important part now was getting it out the door,
as if I take my sweet time this will take way longer :stuck_out_tongue:
<!--
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
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` to
check that you're using the standard code style
- [X] cargo test --workspace` to check that all tests pass
- [X] cargo run -- -c "use std testing; testing run-tests --path
crates/nu-std"` 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-09-08 20:57:38 +02:00
|
|
|
mod ucp;
|
Add ulimit command (#11324)
# Description
Add `ulimit` command to Nushell.
Closes #9563
Closes #3976
Related pr #11246
Reference:
https://github.com/fish-shell/fish-shell/blob/master/fish-rust/src/builtins/ulimit.rs
https://github.com/mirror/busybox/blob/master/shell/shell_common.c#L529
# User-Facing Changes
```
nushell on ulimit is 📦 v0.88.2 via 🦀 v1.72.1 [3/246]
❯ ulimit -a
╭────┬──────────────────────────────────────────────────────────────────────────┬───────────┬───────────╮
│ # │ description │ soft │ hard │
├────┼──────────────────────────────────────────────────────────────────────────┼───────────┼───────────┤
│ 0 │ Maximum size of core files created (kB, -c) │ unlimited │ unlimited │
│ 1 │ Maximum size of a process's data segment (kB, -d) │ unlimited │ unlimited │
│ 2 │ Controls of maximum nice priority (-e) │ 0 │ 0 │
│ 3 │ Maximum size of files created by the shell (kB, -f) │ unlimited │ unlimited │
│ 4 │ Maximum number of pending signals (-i) │ 55273 │ 55273 │
│ 5 │ Maximum size that may be locked into memory (kB, -l) │ 8192 │ 8192 │
│ 6 │ Maximum resident set size (kB, -m) │ unlimited │ unlimited │
│ 7 │ Maximum number of open file descriptors (-n) │ 1024 │ 524288 │
│ 8 │ Maximum bytes in POSIX message queues (kB, -q) │ 800 │ 800 │
│ 9 │ Maximum realtime scheduling priority (-r) │ 0 │ 0 │
│ 10 │ Maximum stack size (kB, -s) │ 8192 │ unlimited │
│ 11 │ Maximum amount of CPU time in seconds (seconds, -t) │ unlimited │ unlimited │
│ 12 │ Maximum number of processes available to the current user (-u) │ 55273 │ 55273 │
│ 13 │ Maximum amount of virtual memory available to each process (kB, -v) │ unlimited │ unlimited │
│ 14 │ Maximum number of file locks (-x) │ unlimited │ unlimited │
│ 15 │ Maximum contiguous realtime CPU time (-y) │ unlimited │ unlimited │
╰────┴──────────────────────────────────────────────────────────────────────────┴───────────┴───────────╯
nushell on ulimit is 📦 v0.88.2 via 🦀 v1.72.1
❯ ulimit -s
╭───┬─────────────────────────────┬──────┬───────────╮
│ # │ description │ soft │ hard │
├───┼─────────────────────────────┼──────┼───────────┤
│ 0 │ Maximum stack size (kB, -s) │ 8192 │ unlimited │
╰───┴─────────────────────────────┴──────┴───────────╯
nushell on ulimit is 📦 v0.88.2 via 🦀 v1.72.1
❯ ulimit -s 100
nushell on ulimit is 📦 v0.88.2 via 🦀 v1.72.1
❯ ulimit -s
╭───┬─────────────────────────────┬──────┬──────╮
│ # │ description │ soft │ hard │
├───┼─────────────────────────────┼──────┼──────┤
│ 0 │ Maximum stack size (kB, -s) │ 100 │ 100 │
╰───┴─────────────────────────────┴──────┴──────╯
nushell on ulimit is 📦 v0.88.2 via 🦀 v1.72.1
```
# Tests + Formatting
- [x] add commands::ulimit::limit_set_soft1
- [x] add commands::ulimit::limit_set_soft2
- [x] add commands::ulimit::limit_set_hard1
- [x] add commands::ulimit::limit_set_hard2
- [x] add commands::ulimit::limit_set_invalid1
- [x] add commands::ulimit::limit_set_invalid2
- [x] `cargo fmt --all -- --check` to check standard code formatting
(`cargo fmt --all` applies these changes)
- [x] `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used`
to check that you're using the standard code style
- [x] `cargo test --workspace` to check that all tests pass (on Windows
make sure to [enable developer
mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging))
- [x] `cargo run -- -c "use std testing; testing run-tests --path
crates/nu-std"` to run the tests for the standard library
2023-12-15 14:11:17 +01:00
|
|
|
#[cfg(unix)]
|
|
|
|
mod ulimit;
|
2024-03-25 22:51:50 +01:00
|
|
|
|
2023-10-30 13:59:48 +01:00
|
|
|
mod umkdir;
|
2024-03-25 22:51:50 +01:00
|
|
|
mod uname;
|
2019-12-31 05:05:02 +01:00
|
|
|
mod uniq;
|
2022-12-02 11:36:01 +01:00
|
|
|
mod uniq_by;
|
2020-05-07 07:33:30 +02:00
|
|
|
mod update;
|
2022-03-17 18:55:02 +01:00
|
|
|
mod upsert;
|
2022-11-19 19:14:29 +01:00
|
|
|
mod url;
|
2022-02-18 02:58:24 +01:00
|
|
|
mod use_;
|
2019-12-15 17:15:06 +01:00
|
|
|
mod where_;
|
2022-03-29 13:10:43 +02:00
|
|
|
#[cfg(feature = "which-support")]
|
2021-01-08 18:44:31 +01:00
|
|
|
mod which;
|
2022-11-11 19:21:45 +01:00
|
|
|
mod while_;
|
2020-05-06 05:56:31 +02:00
|
|
|
mod with_env;
|
2019-12-15 17:15:06 +01:00
|
|
|
mod wrap;
|
2021-08-15 06:36:08 +02:00
|
|
|
mod zip;
|