rtx shell does not appear to work when using xonsh
Describe the bug
When I try to use rtx shell [email protected] while running under xonsh, it appears that it is unable to set the Python version correctly (seems like it just doesn't work):
↓2 ~
❯ rtx shell [email protected]
export RTX_PYTHON_VERSION=3.10.10
↓2 ~
❯ rtx list
⏵ pdm 2.4.9 (set by ~/.tool-versions)
python 2.7.18
python 3.7.16
python 3.8.16
python 3.9.16
python 3.10.10
⏵ python 3.11.2 (set by ~/.tool-versions)
When I drop to a sub-shell using fish and try it again, it works just fine:
↓2 ~
❯ fish
Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fish
↓3 ~
❯ rtx list
⏵ pdm 2.4.9 (set by ~/.tool-versions)
python 2.7.18
python 3.7.16
python 3.8.16
python 3.9.16
python 3.10.10
⏵ python 3.11.2 (set by ~/.tool-versions)
↓3 ~
❯ rtx shell [email protected]
↓3 ~
❯ rtx current
python 3.10.10
pdm 2.4.9
To Reproduce
Try to use rtx shell while running under xonsh.
Expected behavior
Same behavior as when using other shells like fish.
rtx doctor output
↓2 ~
❯ rtx doctor
rtx version:
1.27.9 macos-arm64 (unknown 2023-03-27)
build:
Target: aarch64-apple-darwin
Features: BREW
Built: Mon, 27 Mar 2023 18:53:19 +0000
Rust Version: rustc 1.68.1 (8460ca823 2023-03-20) (built from a source tarball)
Profile: release
shell:
/bin/zsh
zsh 5.9 (x86_64-apple-darwin22.0)
rtx environment variables:
(none)
settings:
{"experimental": "false", "missing_runtime_behavior": "prompt", "always_keep_download": "false", "legacy_version_file": "true", "plugin_autoupdate_last_check_duration
": "10080", "trusted_config_paths": "[]", "verbose": "false", "asdf_compat": "false", "jobs": "4", "disable_default_shorthands": "false", "log_level": "INFO", "raw": "f
alse"}
config files:
/Users/taran/.tool-versions
plugins:
pdm https://github.com/1oglop1/asdf-pdm#451c30f
python https://github.com/jdxcode/rtx-python.git#e21a6da
toolset:
pdm@latest, python@latest
No problems found
Additional context
I am running xonsh in a zellij session.
just for transparency sake: I don't have the bandwidth to look into alternative shells (meaning: not bash, zsh, or fish). I'd happily accept a PR if someone can look into this or describe what needs to happen. It may be worth documenting this as these shells being "tier 2" or something.
In bash/zsh/fish the way this works is that rtx is created as a bash function. In the case of shell and deactivate, it eval's the result of rtx shell:
https://github.com/jdxcode/rtx/blob/d2d91e1c33484d919c43ac55c8631afa42d8f3f6/src/shell/bash.rs#L31-L34
That logic needs to be ported to xonsh—or something that functions similarly.
@jdxcode No worries! Thanks for the quick response. I also doubt that I will have time to look submit a PR, especially since the work-around is to just drop to a sub-shell. Perhaps a note could be added to the documentation noting that there is a limitation when using xonsh?
yeah I should clarify the support tier and document this
While I'm not a rust programmer, after combing through the code and experimenting a bit I found that most of what is needed to do this is indeed already present. Only the setting of the MISE_SOMETOOL_VERSION environment variables were missing.
Porting the shell function to xonsh seemed indeed the easiest way to accomplish that, PR is here: https://github.com/jdx/mise/pull/1801
I hope I did everything right, esp. regarding the insta snapshots.