From 66d133952d8a9351ed59839209d3344f9bae3f7c Mon Sep 17 00:00:00 2001 From: Jamie Bliss Date: Mon, 3 Feb 2020 13:25:06 -0500 Subject: [PATCH] autovox: Fix algorithm to cd correctly --- xontrib/autovox.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/xontrib/autovox.py b/xontrib/autovox.py index 2e7621765..b3e99ab5f 100644 --- a/xontrib/autovox.py +++ b/xontrib/autovox.py @@ -59,12 +59,15 @@ def get_venv(vox, dirpath): return venvs[0] -def check_for_new_venv(curdir): +def check_for_new_venv(curdir, olddir): vox = voxapi.Vox() - try: - oldve = vox[...] - except KeyError: - oldve = None + if olddir is ... or olddir is None: + try: + oldve = vox[...] + except KeyError: + oldve = None + else: + oldve = get_venv(vox, olddir) newve = get_venv(vox, curdir) if oldve != newve: @@ -76,8 +79,8 @@ def check_for_new_venv(curdir): # Core mechanism: Check for venv when the current directory changes @events.on_chdir -def cd_handler(newdir, **_): - check_for_new_venv(Path(newdir)) +def cd_handler(newdir, olddir, **_): + check_for_new_venv(Path(newdir), Path(olddir)) # Recalculate when venvs are created or destroyed @@ -85,12 +88,12 @@ def cd_handler(newdir, **_): @events.vox_on_create def create_handler(**_): - check_for_new_venv(Path.cwd()) + check_for_new_venv(Path.cwd(), ...) @events.vox_on_destroy def destroy_handler(**_): - check_for_new_venv(Path.cwd()) + check_for_new_venv(Path.cwd(), ...) # Initial activation before first prompt @@ -98,4 +101,4 @@ def destroy_handler(**_): @events.on_post_init def load_handler(**_): - check_for_new_venv(Path.cwd()) + check_for_new_venv(Path.cwd(), None)