xonsh icon indicating copy to clipboard operation
xonsh copied to clipboard

feat: load `rc` files in non-interactive mode if `--rc` is passed

Open kpblackatverisk opened this issue 2 years ago • 3 comments

Executing a single command via xonsh -c does not load the xonsh config files.

xonfig

$ xonsh -c "xonfig"
+------------------+----------------------+
| xonsh            | 0.12.2               |
| Git SHA          | e0a0394b             |
| Commit Date      | Apr 25 10:52:15 2022 |
| Python           | 3.7.13               |
| PLY              | 3.11                 |
| have readline    | False                |
| prompt toolkit   | 3.0.29               |
| shell type       | none                 |
| history backend  | json                 |
| pygments         | 2.12.0               |
| on posix         | False                |
| on linux         | False                |
| on darwin        | False                |
| on windows       | True                 |
| on cygwin        | False                |
| on msys2         | False                |
| is superuser     | False                |
| default encoding | utf-8                |
| xonsh encoding   | utf-8                |
| encoding errors  | surrogateescape      |
| xontrib          | []                   |
| RC file          | []                   |
+------------------+----------------------+

And even when the rc file is explicitly given

$ xonsh --rc C:\Users\username\.xonshrc -c "xonfig"
+------------------+----------------------+
| xonsh            | 0.12.2               |
| Git SHA          | e0a0394b             |
| Commit Date      | Apr 25 10:52:15 2022 |
| Python           | 3.7.13               |
| PLY              | 3.11                 |
| have readline    | False                |
| prompt toolkit   | 3.0.29               |
| shell type       | none                 |
| history backend  | json                 |
| pygments         | 2.12.0               |
| on posix         | False                |
| on linux         | False                |
| on darwin        | False                |
| on windows       | True                 |
| on cygwin        | False                |
| on msys2         | False                |
| is superuser     | False                |
| default encoding | utf-8                |
| xonsh encoding   | utf-8                |
| encoding errors  | surrogateescape      |
| xontrib          | []                   |
| RC file          | []                   |
+------------------+----------------------+

Expected Behavior

The xonsh config files ought to be loaded when executing a single command via xonsh -c instead of only be loaded for interactive mode.

Current Behavior

No xonsh config files are loaded when running xonsh -c by default nor when explicitly given the path to the config file.

Traceback (if applicable)

traceback

Steps to Reproduce

Create an alias in the ~/.xonshrc file:

aliases['hw'] = 'echo "Hello, World"'

Try executing xonsh -c "hw" and note the alias is not found.

Now run xonsh -c "xonfig" and note that no config files are loaded.

Then try xonsh --rc ~/.xonshrc -c "xonfig" and note that no config files are loaded.

For community

⬇️ Please click the 👍 reaction instead of leaving a +1 or 👍 comment

kpblackatverisk avatar Jun 27 '22 19:06 kpblackatverisk

Thanks for raising this @kpblackatverisk -- I think that we're doing the correct thing here -- generally rc files don't get loaded in a non-interactive command.
That said, we should load them if --rc is passed in. You can also force interactive mode by passing -i

gforsyth avatar Jun 27 '22 21:06 gforsyth

Okay, then this issue can be scoped to just the lack of loading the specified rc file.

kpblackatverisk avatar Jun 27 '22 21:06 kpblackatverisk

fish and zsh all load some of their startup files when running non interactively. (fish loads all the files and has flags to determine what to run - zsh will always load ~/.zshenv and /etc/zshenv)

Bash has a way to do this using BASH_ENV which I suppose is equivalent to passing in a file name with --rc , if that worked.

See #4096

bestlem avatar Jun 28 '22 09:06 bestlem