Xonsh: What is the best way to get shell type in xontrib? Wrong SHELL_TYPE in xontrib.

Created on 21 May 2020  路  2Comments  路  Source: xonsh/xonsh

Hello! xonsh is super cool every time I try to do something new! Thank you!

  1. Create xontrib with:
print(__xonsh__.env.get('SHELL_TYPE'))
# or __xonsh__.shell.shell_type

And add the xontrib load ... to ~/.xonshrc.

  1. Run xonsh with setting readline shell:
bash$ xonsh --shell-type readline
  1. You will get best in the output instead of readline.

  2. 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!

question

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_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 ...

All 2 comments

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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

battaglia01 picture battaglia01  路  3Comments

74th picture 74th  路  4Comments

ahundt picture ahundt  路  6Comments

ywangd picture ywangd  路  6Comments

ahundt picture ahundt  路  4Comments