From 1c446126d323216601ac1b47eba6fdfd7a9faf83 Mon Sep 17 00:00:00 2001 From: hyiltiz Date: Fri, 8 May 2026 14:28:31 -0500 Subject: [PATCH] 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 --- modules/virtual_environments/auto-venv/auto-venv.nu | 12 +++++------- .../auto-venv/path_extensions.nu | 4 ++-- .../virtual_environments/auto-venv/venv_helpers.nu | 2 +- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/modules/virtual_environments/auto-venv/auto-venv.nu b/modules/virtual_environments/auto-venv/auto-venv.nu index 025067813..0761b369d 100644 --- a/modules/virtual_environments/auto-venv/auto-venv.nu +++ b/modules/virtual_environments/auto-venv/auto-venv.nu @@ -20,7 +20,7 @@ export-env { def default-hooks [] { (if ($env.config.hooks.env_change.PWD != null) { - [$env.config.hooks.env_change.PWD] + $env.config.hooks.env_change.PWD } else { [] @@ -33,24 +33,22 @@ def build-hooks [] { let on_enter = ' let _env = $env - let pwd = $_env.PWD let trigger = (path_extensions path find-sub . __trigger__ --type ["symlink", "file"]) + if ($trigger | is-empty) { return } - cd ($trigger | path dirname) overlay use __trigger__ as __auto_venv - cd ($pwd) - auto-venv-on-enter $_env hide _env - hide pwd hide trigger ' let on_exit = ' - overlay hide __auto_venv --keep-env [PWD] + if (venv_helpers venv-is-active) { + overlay hide __auto_venv --keep-env [PWD] + } ' let on_enter = ($on_enter | str replace -a '__trigger__' $trigger) diff --git a/modules/virtual_environments/auto-venv/path_extensions.nu b/modules/virtual_environments/auto-venv/path_extensions.nu index 1bf393718..d8afe2eef 100644 --- a/modules/virtual_environments/auto-venv/path_extensions.nu +++ b/modules/virtual_environments/auto-venv/path_extensions.nu @@ -54,6 +54,6 @@ export def "path find-sub" [ ); if ($paths != null) and ($paths | length) > 0 { - [ ($paths | first), $subfolder ] | path join - } else {[]} + [ ($paths | last), $subfolder ] | path join + } else { null } } diff --git a/modules/virtual_environments/auto-venv/venv_helpers.nu b/modules/virtual_environments/auto-venv/venv_helpers.nu index 45bacc1d3..b7d375198 100644 --- a/modules/virtual_environments/auto-venv/venv_helpers.nu +++ b/modules/virtual_environments/auto-venv/venv_helpers.nu @@ -20,7 +20,7 @@ def get-env [ } export def venv-is-active [] { - '__auto_venv' in (overlay list) + '__auto_venv' in (overlay list | where active | get name) } # Creates a virtual environment under the current directory