From abe1c733bc654842a8887e75e232a45ae853cfde Mon Sep 17 00:00:00 2001 From: Christ Beaubrun Date: Sun, 7 Jun 2026 20:44:51 -0700 Subject: [PATCH 1/3] fix: expand environment variables in cd command --- tests/test_cli_cd.py | 13 +++++++++++++ trushell/cli.py | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/test_cli_cd.py b/tests/test_cli_cd.py index 4b39cab..88450a3 100644 --- a/tests/test_cli_cd.py +++ b/tests/test_cli_cd.py @@ -25,3 +25,16 @@ def fake_run_external_command(command: str, shell: bool = True, check: bool = Fa assert Path.cwd() == target assert not called assert str(target) in capsys.readouterr().out + + +def test_handle_cd_command_expands_environment_variables(tmp_path, monkeypatch, capsys): + monkeypatch.chdir(tmp_path) + target = tmp_path / "env-target" + target.mkdir() + monkeypatch.setenv("TRUSHELL_CD_TARGET", str(target)) + + result = cli._handle_cd_command("cd $TRUSHELL_CD_TARGET") + + assert result is True + assert Path.cwd() == target + assert str(target) in capsys.readouterr().out diff --git a/trushell/cli.py b/trushell/cli.py index ff10ff7..735c616 100644 --- a/trushell/cli.py +++ b/trushell/cli.py @@ -283,7 +283,7 @@ def _handle_cd_command(raw_command: str) -> bool: typer.secho("Syntax: cd ", fg=typer.colors.YELLOW) return True - target = os.path.expanduser(argument) + target = os.path.expandvars(os.path.expanduser(argument)) try: os.chdir(target) From 4e6c584d2c420cf14a725ca3bf4f2ca52c9e6dbe Mon Sep 17 00:00:00 2001 From: Christ Beaubrun Date: Mon, 8 Jun 2026 22:37:20 -0500 Subject: [PATCH 2/3] Add cd handler deprecation TODO --- trushell/cli.py | 1 + 1 file changed, 1 insertion(+) diff --git a/trushell/cli.py b/trushell/cli.py index 735c616..47d7267 100644 --- a/trushell/cli.py +++ b/trushell/cli.py @@ -274,6 +274,7 @@ def _handle_chronoterm_command(raw_command: str, normalized_command: str) -> boo return False +# TODO: Deprecate this CLI cd stub in favor of kernel dispatch to avoid duplicate path handling logic. def _handle_cd_command(raw_command: str) -> bool: command, argument = _split_command(raw_command) if command != "cd": From 52c3f95995bdba79749494031df6bf0fff449f9f Mon Sep 17 00:00:00 2001 From: Christ Beaubrun Date: Mon, 8 Jun 2026 21:52:38 -0700 Subject: [PATCH 3/3] Handle cd paths with trailing whitespace --- tests/test_cli_cd.py | 13 +++++++++++++ trushell/cli.py | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/test_cli_cd.py b/tests/test_cli_cd.py index 88450a3..edf6e39 100644 --- a/tests/test_cli_cd.py +++ b/tests/test_cli_cd.py @@ -38,3 +38,16 @@ def test_handle_cd_command_expands_environment_variables(tmp_path, monkeypatch, assert result is True assert Path.cwd() == target assert str(target) in capsys.readouterr().out + + +def test_handle_cd_command_strips_trailing_whitespace(tmp_path, monkeypatch, capsys): + monkeypatch.chdir(tmp_path) + target = tmp_path / "space-target" + target.mkdir() + monkeypatch.setenv("TRUSHELL_CD_TARGET", str(target)) + + result = cli._handle_cd_command("cd $TRUSHELL_CD_TARGET ") + + assert result is True + assert Path.cwd() == target + assert str(target) in capsys.readouterr().out diff --git a/trushell/cli.py b/trushell/cli.py index 47d7267..820aee7 100644 --- a/trushell/cli.py +++ b/trushell/cli.py @@ -284,7 +284,7 @@ def _handle_cd_command(raw_command: str) -> bool: typer.secho("Syntax: cd ", fg=typer.colors.YELLOW) return True - target = os.path.expandvars(os.path.expanduser(argument)) + target = os.path.expandvars(os.path.expanduser(argument.strip())) try: os.chdir(target)