Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions tests/test_cli_cd.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,29 @@ 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


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
3 changes: 2 additions & 1 deletion trushell/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand All @@ -283,7 +284,7 @@ def _handle_cd_command(raw_command: str) -> bool:
typer.secho("Syntax: cd <directory_path>", fg=typer.colors.YELLOW)
return True

target = os.path.expanduser(argument)
target = os.path.expandvars(os.path.expanduser(argument.strip()))

try:
os.chdir(target)
Expand Down
Loading