Skip to content

Commit 1c44612

Browse files
committed
Fix auto-venv compatibility with nushell 0.108
- default-hooks: don't wrap existing hooks list in another list; this produced an invalid nested type that broke hook evaluation and downstream tab completion - on_enter: remove transient cd operations that triggered spurious hook evaluations; overlay use now resolves via NU_LIB_DIRS instead of runtime PWD (which nushell 0.108 no longer supports for dynamically evaluated code) - on_enter: guard against missing trigger file - on_exit: guard overlay hide against inactive overlay - venv_helpers: filter overlay list to active overlays only (overlay list now includes inactive entries in 0.108) - path_extensions: return null instead of [] on no match to prevent type errors in downstream path join calls; return deepest ancestor match rather than shallowest
1 parent 32cd1d5 commit 1c44612

3 files changed

Lines changed: 8 additions & 10 deletions

File tree

modules/virtual_environments/auto-venv/auto-venv.nu

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export-env {
2020

2121
def default-hooks [] {
2222
(if ($env.config.hooks.env_change.PWD != null) {
23-
[$env.config.hooks.env_change.PWD]
23+
$env.config.hooks.env_change.PWD
2424
}
2525
else {
2626
[]
@@ -33,24 +33,22 @@ def build-hooks [] {
3333

3434
let on_enter = '
3535
let _env = $env
36-
let pwd = $_env.PWD
3736
3837
let trigger = (path_extensions path find-sub . __trigger__ --type ["symlink", "file"])
38+
if ($trigger | is-empty) { return }
3939
40-
cd ($trigger | path dirname)
4140
overlay use __trigger__ as __auto_venv
4241
43-
cd ($pwd)
44-
4542
auto-venv-on-enter $_env
4643
4744
hide _env
48-
hide pwd
4945
hide trigger
5046
'
5147

5248
let on_exit = '
53-
overlay hide __auto_venv --keep-env [PWD]
49+
if (venv_helpers venv-is-active) {
50+
overlay hide __auto_venv --keep-env [PWD]
51+
}
5452
'
5553

5654
let on_enter = ($on_enter | str replace -a '__trigger__' $trigger)

modules/virtual_environments/auto-venv/path_extensions.nu

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,6 @@ export def "path find-sub" [
5454
);
5555

5656
if ($paths != null) and ($paths | length) > 0 {
57-
[ ($paths | first), $subfolder ] | path join
58-
} else {[]}
57+
[ ($paths | last), $subfolder ] | path join
58+
} else { null }
5959
}

modules/virtual_environments/auto-venv/venv_helpers.nu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get-env [
2020
}
2121

2222
export def venv-is-active [] {
23-
'__auto_venv' in (overlay list)
23+
'__auto_venv' in (overlay list | where active | get name)
2424
}
2525

2626
# Creates a virtual environment under the current directory

0 commit comments

Comments
 (0)