Skip to content

enable cd to work with directory abbreviations#5452

Merged
fdncred merged 4 commits intonushell:mainfrom
fdncred:cd_with_abbreviations
May 6, 2022
Merged

enable cd to work with directory abbreviations#5452
fdncred merged 4 commits intonushell:mainfrom
fdncred:cd_with_abbreviations

Conversation

@fdncred
Copy link
Copy Markdown
Contributor

@fdncred fdncred commented May 5, 2022

Description

This PR allows the cd command to work with abbreviations if you have the configuration point cd_with_abbreviations set to true in your config.nu file.

Example:

> $env.PWD
~/some/path
> cd d/s/9
> $env.PWD
~/some/path/deep/space/9

To be clear, this is not for completions so cd t/n/g<tab> will not work with this PR.

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

@sholderbach
Copy link
Copy Markdown
Member

I love that general functionality coming from zsh! Great work on the implementation @fdncred !

But I think this has big surprise factor and I would prefer that behind a config option and would personally use it only in a completion/autocorrect way and would prefer my history to contain the actual file/folder names.

I assume that should be cd d/s/9 for correct semantics?

> $env.PWD
~/some/path
> cd /d/s/9
> $env.PWD
~/some/path/deep/space/9

@fdncred
Copy link
Copy Markdown
Contributor Author

fdncred commented May 5, 2022

I haven't looked at the history. I'm also not exactly sure how to put this behind a feature since it's so tightly integrated.

We don't have to land this. No harm done. I was just having some fun.

@fdncred
Copy link
Copy Markdown
Contributor Author

fdncred commented May 6, 2022

I took your advice @sholderbach and made it configurable. I also checked my history and this is what it stores.
image

I don't think there's a way for me to control what gets stored in the history. If you know of a way, let me know. I'm not sure how this functionality would work with autocomplete because it's not instantaneously fast since it has to traverse the directory tree to figure out what t/n/g means and if it's valid. But the code could be reused if someone wants to take a stab at it.

@fdncred fdncred merged commit 768ff47 into nushell:main May 6, 2022
@fdncred fdncred deleted the cd_with_abbreviations branch May 6, 2022 12:58
@sholderbach
Copy link
Copy Markdown
Member

Awesome!

kubouch pushed a commit to kubouch/nushell that referenced this pull request May 6, 2022
* enable cd to work with abbreviations

* add abbreviation example

* fix tests

* make it configurable
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
* enable cd to work with abbreviations

* add abbreviation example

* fix tests

* make it configurable
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>
drbrain added a commit to drbrain/nushell that referenced this pull request Dec 9, 2023
This error was introduced in nushell#5452 and was removed in nushell#10588
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.

2 participants