Hello! xonsh is super cool every time I try to do something new! Thank you!
print(__xonsh__.env.get('SHELL_TYPE'))
# or __xonsh__.shell.shell_type
And add the xontrib load ... to ~/.xonshrc.
bash$ xonsh --shell-type readline
You will get best in the output instead of readline.
After this run in xonsh:
$ print(__xonsh__.env.get('SHELL_TYPE'))
readline
You've got the right shell type.
What is the best way to get shell type in xontrib?
Thanks!
Hi @anki-code, the question is not how to get the shell type in xontrib, but rather how to load a xontrib that needs to know the shell type :wink:
Since the shell type is decided after your RC files are processed according to the final $SHELL_TYPE value (that's by design), you can't really determine the shell type from the RC files themselves. You can, however, install an on_post_init handler and load your xontrib from there.
.xonshrc:
...
echo pre: $SHELL_TYPE
@events.on_post_init
def _rc_post_init():
echo post: $SHELL_TYPE
#xontrib load ...
It works great! Thanks for explanation!
Most helpful comment
Hi @anki-code, the question is not how to get the shell type in xontrib, but rather how to load a xontrib that needs to know the shell type :wink:
Since the shell type is decided after your RC files are processed according to the final
$SHELL_TYPEvalue (that's by design), you can't really determine the shell type from the RC files themselves. You can, however, install anon_post_inithandler and load your xontrib from there..xonshrc: