mirror of
https://github.com/nushell/nushell.git
synced 2025-04-25 13:48:19 +02:00
feat(std/dirs): retain state in subshells or with exec-restarts (#15080)
Persist `std/dirs`'s state in subshells and also when restarting the shell with `exec $nu.current-exe`
This commit is contained in:
parent
f7d5162582
commit
d577074da9
crates/nu-std
@ -17,8 +17,16 @@
|
||||
# This situation could arise if we started with [/a, /b, /c], then
|
||||
# we changed directories from /b to /var/tmp.
|
||||
export-env {
|
||||
$env.DIRS_POSITION = 0
|
||||
$env.DIRS_LIST = [($env.PWD | path expand)]
|
||||
$env.ENV_CONVERSIONS.DIRS_LIST = {
|
||||
from_string: {|| split row (char esep)}
|
||||
to_string: {|| str join (char esep)}
|
||||
}
|
||||
$env.ENV_CONVERSIONS.DIRS_POSITION = {
|
||||
from_string: {|| into int}
|
||||
to_string: {|| into string}
|
||||
}
|
||||
$env.DIRS_POSITION = $env.DIRS_POSITION? | default (0)
|
||||
$env.DIRS_LIST = $env.DIRS_LIST? | default [($env.PWD | path expand)]
|
||||
}
|
||||
|
||||
# Add one or more directories to the list.
|
||||
@ -145,4 +153,4 @@ export module shells-aliases {
|
||||
export alias p = prev
|
||||
export alias n = next
|
||||
export alias g = goto
|
||||
}
|
||||
}
|
||||
|
@ -46,6 +46,8 @@ def dirs_command [] {
|
||||
# must set PWD *before* doing `use` that will run the def --env block in dirs module.
|
||||
cd $c.base_path
|
||||
|
||||
# hide existing variables to prevent the state from outside affecting the tests
|
||||
hide-env -i DIRS_LIST DIRS_POSITION
|
||||
# must execute these uses for the UOT commands *after* the test and *not* just put them at top of test module.
|
||||
# the def --env gets messed up
|
||||
use std/dirs
|
||||
@ -96,6 +98,7 @@ def dirs_next [] {
|
||||
cd $c.base_path
|
||||
assert equal $env.PWD $c.base_path "test setup"
|
||||
|
||||
hide-env -i DIRS_LIST DIRS_POSITION
|
||||
use std/dirs
|
||||
cur_dir_check $c.base_path "use module test setup"
|
||||
|
||||
@ -117,6 +120,7 @@ def dirs_cd [] {
|
||||
# must set PWD *before* doing `use` that will run the def --env block in dirs module.
|
||||
cd $c.base_path
|
||||
|
||||
hide-env -i DIRS_LIST DIRS_POSITION
|
||||
use std/dirs
|
||||
|
||||
cur_dir_check $c.base_path "use module test setup"
|
||||
@ -139,6 +143,8 @@ def dirs_cd [] {
|
||||
def dirs_goto_bug10696 [] {
|
||||
let $c = $in
|
||||
cd $c.base_path
|
||||
|
||||
hide-env -i DIRS_LIST DIRS_POSITION
|
||||
use std/dirs
|
||||
|
||||
dirs add $c.path_a
|
||||
@ -153,6 +159,8 @@ def dirs_goto_bug10696 [] {
|
||||
def dirs_goto [] {
|
||||
let $c = $in
|
||||
cd $c.base_path
|
||||
|
||||
hide-env -i DIRS_LIST DIRS_POSITION
|
||||
use std/dirs
|
||||
|
||||
# check that goto can move *from* any position in the ring *to* any other position (correctly)
|
||||
|
Loading…
Reference in New Issue
Block a user