Skip to content

Add split number flag in split row#5434

Merged
fdncred merged 1 commit intonushell:mainfrom
gipsyh:splitn
May 6, 2022
Merged

Add split number flag in split row#5434
fdncred merged 1 commit intonushell:mainfrom
gipsyh:splitn

Conversation

@gipsyh
Copy link
Copy Markdown
Contributor

@gipsyh gipsyh commented May 4, 2022

Signed-off-by: Yuheng Su gipsyh.icu@gmail.com

Description

add split number flag in split row

Tests

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 --all --all-features -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect to check that you're using the standard code style
  • cargo build; cargo test --all --all-features to check that all the tests pass

Signed-off-by: Yuheng Su <gipsyh.icu@gmail.com>
@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented May 4, 2022

can you help me understand the point of this PR? what problem is it trying to solve? Also, I'm not sure it's working right because these return the same.

$env.PWD | split row / -n 1
╭──────────────────────────────────╮
│ /Users/fdncred/src/forks/nushell │
╰──────────────────────────────────╯
$env.PWD | split row / -n 2
╭──────────────────────────────────╮
│ /Users/fdncred/src/forks/nushell │
╰──────────────────────────────────╯

it's not until 3 that I get this

$env.PWD | split row / -n 3
╭───────────────────────────╮
│ Users                     │
│ fdncred/src/forks/nushell │
╰───────────────────────────╯

@gipsyh
Copy link
Copy Markdown
Contributor Author

gipsyh commented May 4, 2022

can you help me understand the point of this PR? what problem is it trying to solve? Also, I'm not sure it's working right because these return the same.

$env.PWD | split row / -n 1
╭──────────────────────────────────╮
│ /Users/fdncred/src/forks/nushell │
╰──────────────────────────────────╯
$env.PWD | split row / -n 2
╭──────────────────────────────────╮
│ /Users/fdncred/src/forks/nushell │
╰──────────────────────────────────╯

it's not until 3 that I get this

$env.PWD | split row / -n 3
╭───────────────────────────╮
│ Users                     │
│ fdncred/src/forks/nushell │
╰───────────────────────────╯

It's weird, the output of $env.PWD | split row / -n 2:
截屏2022-05-04 19 45 04
there is no / before Users, and the output is right. we want to split pwd into 2 part by /, but there is empty before the first /, so the number of parts of output is 1.

Substantially, it called the splitn function in rust std.

@gipsyh
Copy link
Copy Markdown
Contributor Author

gipsyh commented May 4, 2022

what problem is it trying to solve?

for example:
git help -a | lines | find -r '^ ', and I want to split into name and desctiption. and I wants to use split row ' ', but it will spilt the desctiption into single words, so I need to specify the maximum parts.

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented May 6, 2022

probably no harm in adding this.

@fdncred fdncred merged commit fbdb125 into nushell:main May 6, 2022
kubouch pushed a commit to kubouch/nushell that referenced this pull request May 6, 2022
Signed-off-by: Yuheng Su <gipsyh.icu@gmail.com>
@hustcer
Copy link
Copy Markdown
Contributor

hustcer commented May 7, 2022

Will count be better than number? I'm not quite sure, just what I thought

@gipsyh gipsyh deleted the splitn branch May 7, 2022 04:33
sophiajt added a commit that referenced this pull request May 7, 2022
* WIP: Start laying overlays

* Rename Overlay->Module; Start adding overlay

* Revamp adding overlay

* Add overlay add tests; Disable debug print

* Fix overlay add; Add overlay remove

* Add overlay remove tests

* Add missing overlay remove file

* Add overlay list command

* (WIP?) Enable overlays for env vars

* Move OverlayFrames to ScopeFrames

* (WIP) Move everything to overlays only

ScopeFrame contains nothing but overlays now

* Fix predecls

* Fix wrong overlay id translation and aliases

* Fix broken env lookup logic

* Remove TODOs

* Add overlay add + remove for environment

* Add a few overlay tests; Fix overlay add name

* Some cleanup; Fix overlay add/remove names

* Clippy

* Fmt

* Remove walls of comments

* List overlays from stack; Add debugging flag

Currently, the engine state ordering is somehow broken.

* Fix (?) overlay list test

* Fix tests on Windows

* Fix activated overlay ordering

* Check for active overlays equality in overlay list

This removes the -p flag: Either both parser and engine will have the
same overlays, or the command will fail.

* Add merging on overlay remove

* Change help message and comment

* Add some remove-merge/discard tests

* (WIP) Track removed overlays properly

* Clippy; Fmt

* Fix getting last overlay; Fix predecls in overlays

* Remove merging; Fix re-add overwriting stuff

Also some error message tweaks.

* Fix overlay error in the engine

* Update variable_completions.rs

* Adds flags and optional arguments to view-source (#5446)

* added flags and optional arguments to view-source

* removed redundant code

* removed redundant code

* fmt

* fix bug in shell_integration (#5450)

* fix bug in shell_integration

* add some comments

* enable cd to work with directory abbreviations (#5452)

* enable cd to work with abbreviations

* add abbreviation example

* fix tests

* make it configurable

* make cd recornize symblic link (#5454)

* implement seq char command to generate single character sequence (#5453)

* add tmp code

* add seq char command

* Add split number flag in `split row` (#5434)

Signed-off-by: Yuheng Su <gipsyh.icu@gmail.com>

* Add two more overlay tests

* Add ModuleId to OverlayFrame

* Fix env conversion accidentally activating overlay

It activated overlay from permanent state prematurely which would
cause `overlay add` to misbehave.

* Remove unused parameter; Add overlay list test

* Remove added traces

* Add overlay commands examples

* Modify TODO

* Fix $nu.scope iteration

* Disallow removing default overlay

* Refactor some parser errors

* Remove last overlay if no argument

* Diversify overlay examples

* Make it possible to update overlay's module

In case the origin module updates, the overlay add loads the new module,
makes it overlay's origin and applies the changes. Before, it was
impossible to update the overlay if the module changed.

Co-authored-by: JT <547158+jntrnr@users.noreply.github.com>
Co-authored-by: pwygab <88221256+merelymyself@users.noreply.github.com>
Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
Co-authored-by: WindSoilder <WindSoilder@outlook.com>
Co-authored-by: Yuheng Su <gipsyh.icu@gmail.com>
fennewald pushed a commit to fennewald/nushell that referenced this pull request Jun 27, 2022
Signed-off-by: Yuheng Su <gipsyh.icu@gmail.com>
fennewald pushed a commit to fennewald/nushell that referenced this pull request Jun 27, 2022
* WIP: Start laying overlays

* Rename Overlay->Module; Start adding overlay

* Revamp adding overlay

* Add overlay add tests; Disable debug print

* Fix overlay add; Add overlay remove

* Add overlay remove tests

* Add missing overlay remove file

* Add overlay list command

* (WIP?) Enable overlays for env vars

* Move OverlayFrames to ScopeFrames

* (WIP) Move everything to overlays only

ScopeFrame contains nothing but overlays now

* Fix predecls

* Fix wrong overlay id translation and aliases

* Fix broken env lookup logic

* Remove TODOs

* Add overlay add + remove for environment

* Add a few overlay tests; Fix overlay add name

* Some cleanup; Fix overlay add/remove names

* Clippy

* Fmt

* Remove walls of comments

* List overlays from stack; Add debugging flag

Currently, the engine state ordering is somehow broken.

* Fix (?) overlay list test

* Fix tests on Windows

* Fix activated overlay ordering

* Check for active overlays equality in overlay list

This removes the -p flag: Either both parser and engine will have the
same overlays, or the command will fail.

* Add merging on overlay remove

* Change help message and comment

* Add some remove-merge/discard tests

* (WIP) Track removed overlays properly

* Clippy; Fmt

* Fix getting last overlay; Fix predecls in overlays

* Remove merging; Fix re-add overwriting stuff

Also some error message tweaks.

* Fix overlay error in the engine

* Update variable_completions.rs

* Adds flags and optional arguments to view-source (nushell#5446)

* added flags and optional arguments to view-source

* removed redundant code

* removed redundant code

* fmt

* fix bug in shell_integration (nushell#5450)

* fix bug in shell_integration

* add some comments

* enable cd to work with directory abbreviations (nushell#5452)

* enable cd to work with abbreviations

* add abbreviation example

* fix tests

* make it configurable

* make cd recornize symblic link (nushell#5454)

* implement seq char command to generate single character sequence (nushell#5453)

* add tmp code

* add seq char command

* Add split number flag in `split row` (nushell#5434)

Signed-off-by: Yuheng Su <gipsyh.icu@gmail.com>

* Add two more overlay tests

* Add ModuleId to OverlayFrame

* Fix env conversion accidentally activating overlay

It activated overlay from permanent state prematurely which would
cause `overlay add` to misbehave.

* Remove unused parameter; Add overlay list test

* Remove added traces

* Add overlay commands examples

* Modify TODO

* Fix $nu.scope iteration

* Disallow removing default overlay

* Refactor some parser errors

* Remove last overlay if no argument

* Diversify overlay examples

* Make it possible to update overlay's module

In case the origin module updates, the overlay add loads the new module,
makes it overlay's origin and applies the changes. Before, it was
impossible to update the overlay if the module changed.

Co-authored-by: JT <547158+jntrnr@users.noreply.github.com>
Co-authored-by: pwygab <88221256+merelymyself@users.noreply.github.com>
Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
Co-authored-by: WindSoilder <WindSoilder@outlook.com>
Co-authored-by: Yuheng Su <gipsyh.icu@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants