🐚 Python-powered shell. Full-featured and cross-platform.
Find a file
Andy Kipp f81d55d09b
Do not load ~/.xonshrc in not interactive mode (#5491)
### Motivation

In #5099 was introduced the logic where all RC files are loaded in
interactive and non-interactive modes. This logic is not working good
for home based `~/.xonshrc` file.

First of all `~/.xonshrc` is the buffer/accumulator of settings focused
on interactive mode. Most tools with integration with xonsh (e.g.
`conda`, `zoxide`, etc) offer to just do `echo "init_tool()" >>
~/.xonshrc` (`conda` has around 20 lines of init code) to start using
the tool and users are doing this without any doubts.

But because of after 5099 `~/.xonshrc` is executed in non-interactive
mode the adding code to it leads to unexpected and unintended side
effects:

* If you run a script with shebang (e.g. `#!/usr/bin/env xonsh` or
[xonsh-awesome-cli-app](https://github.com/anki-code/xonsh-awesome-cli-app))
or just from `xonsh script.xsh` the code will be unexpected and
unintended slower.

* If you're using xonsh-based tools (e.g. you install them using pip)
and run them in environment that has no packages that initiated in
`~/.xonshrc` you will see epic errors.

* Additional context: 
* Bash and Zsh do not load `~/.bashrc` and `~/.zshrc` in non-interactive
mode by the same reasons.
* We have welcome message `Create ~/.xonshrc file manually or use xonfig
to suppress the welcome message` and we don't want to make the process
of creating this file complex.

All of this leads to bad unexpected and unintended experience. This PR
is to fix this.

### Expectation

By doing this fix we assume that experienced user who wants to build
good repeatable run control files will use another ways to create config
files and this has [reflection in
docs](8860f2bd52/docs/xonshrc.rst).
In the nutshell if you want to create the RC files that affect every run
of code you should use one or many of these ways:

* Cross-desktop group (XDG) compliant `~/.config/xonsh/rc.xsh` control
file.
* The system-wide control file `/etc/xonsh/xonshrc` for Linux and OSX
and in `%ALLUSERSPROFILE%\xonsh\xonshrc` on Windows. It controls options
that are applied to all users of Xonsh on a given system.
* The home-based directory `~/.config/xonsh/rc.d/` and system
`/etc/xonsh/rc.d/` can contain .xsh files. They will be executed at
startup in order. This allows for drop-in configuration where your
configuration can be split across scripts and common and local
configurations more easily separated.

In your configs you need to check `$XONSH_INTERACTIVE` and
`$XONSH_LOGIN` explicitly.

### Before

`~/.xonshrc` is used in non-interactive mode.

```xsh
echo "echo RC" >> ~/.xonshrc
cd /tmp
echo "echo Script" > script.xsh
xonsh script.xsh
# RC
# Script
```
```xsh
cd /tmp
echo 'echo RC' >> ~/.xonshrc
echo '#!/usr/bin/env xonsh' > myscript
chmod +x myscript

./myscript
# RC
```

### After

`~/.xonshrc` is not used in non-interactive mode. Use `-i` if you need
it.

```xsh
echo "echo RC" >> ~/.xonshrc
cd /tmp
echo "echo Script" > script.xsh
xonsh script.xsh
# Script

xonsh -i script.xsh
# RC
# Script
```
```xsh
cd /tmp
echo 'echo RC' >> ~/.xonshrc
echo '#!/usr/bin/env xonsh' > myscript
chmod +x myscript

./myscript
```
Closes #5488 #4096 #5496

### Fun

I want to leave here some nice representation of how it works in
bash/sh/zsh from [twitter
post](https://twitter.com/paxx39/status/1742768007154479109):



![image](https://github.com/xonsh/xonsh/assets/1708680/cd7b3803-483f-4d5d-bf9d-baa61c794f68)


## For community
⬇️ **Please click the 👍 reaction instead of leaving a `+1` or 👍
comment**

---------

Co-authored-by: a <1@1.1>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-06-13 10:08:23 -04:00
.devcontainer Codespaces and devcontainer.json (#5158) 2023-06-21 22:23:46 +05:30
.github Micro update new-issue.md (#5490) 2024-06-11 17:25:10 +02:00
appimage Unpin prompt-toolkit version (#5438) 2024-05-23 14:08:54 -04:00
ci fix: xonfig web is not upto-date (#4606) 2022-01-18 11:11:16 -05:00
docs Do not load ~/.xonshrc in not interactive mode (#5491) 2024-06-13 10:08:23 -04:00
news Do not load ~/.xonshrc in not interactive mode (#5491) 2024-06-13 10:08:23 -04:00
scripts re-run CI tests 2020-08-08 14:02:44 -04:00
tests Do not load ~/.xonshrc in not interactive mode (#5491) 2024-06-13 10:08:23 -04:00
xompletions feat: add xontrib-django 2022-04-12 14:19:15 +05:30
xonsh Do not load ~/.xonshrc in not interactive mode (#5491) 2024-06-13 10:08:23 -04:00
xontrib [pre-commit.ci] pre-commit autoupdate (#5271) 2024-01-30 12:23:50 +01:00
.authors.yml Updated authorship for 0.16.0 2024-04-23 14:34:30 -04:00
.coveragerc refactor(amalgamate): remove amalgamation (#4858) 2022-07-04 10:40:16 +05:30
.gitattributes Remove syntax override for .xsh files (#4554) 2021-11-22 10:07:04 -05:00
.gitignore chore: use stable 3.12 for CI jobs (#5307) 2024-05-16 15:43:57 +05:30
.mailmap Updated authorship for 0.16.0 2024-04-23 14:34:30 -04:00
.pre-commit-config.yaml [pre-commit.ci] pre-commit autoupdate (#5486) 2024-06-10 21:33:37 +02:00
AUTHORS.rst Updated authorship for 0.16.0 2024-04-23 14:34:30 -04:00
CHANGELOG.rst Updated CHANGELOG for 0.16.0 2024-04-23 14:34:31 -04:00
conftest.py use recommended pytest entry point in docs and comments (#4671) 2022-02-19 01:45:45 +05:30
CONTRIBUTING.rst note that xonsh requires pip 24 for an editable install and development (#5460) 2024-05-30 16:03:55 +02:00
FUNDING.yml Become a sponsor to xonsh (#5167) 2023-07-01 13:15:06 +00:00
github_deploy_key.enc publish dev and latest release docs on xonsh-docs 2016-10-20 19:48:38 -04:00
license copyright update 2016-06-30 12:24:55 -04:00
logo.txt accomodate pip bug by making setup.py ascii 2015-11-16 15:12:02 -08:00
MANIFEST.in refactor(amalgamate): remove amalgamation (#4858) 2022-07-04 10:40:16 +05:30
pyproject.toml Perform proper case-insensitive matching in command_cache on Windows (#5477) 2024-06-10 12:29:13 -04:00
README.rst Add Starship to xonsh-compatible projects (#5484) 2024-06-10 18:25:31 +02:00
rever.xsh Downgrade AppImage to 3.11 (#5364) 2024-04-25 11:46:36 +02:00
run-tests.xsh refactor(amalgamate): remove amalgamation (#4858) 2022-07-04 10:40:16 +05:30
setup.cfg refactor: update line length to default setting 2024-04-16 11:23:35 -04:00
setup.py docs: Fix a few typos (#4889) 2022-07-23 04:42:46 +05:30
xonsh-in-docker.py Ruff linter (#5118) 2023-04-19 12:59:32 +00:00

xonsh
=====

.. class:: center

    **xonsh** is a Python-powered, cross-platform, Unix-gazing shell language and command prompt.

    The language is a superset of Python 3.6+ with additional shell primitives.
    xonsh (pronounced *conch*) is meant for the daily use of experts and novices alike.

    .. image:: https://raw.githubusercontent.com/xonsh/xonsh/main/docs/_static/what_is_xonsh.png
            :alt: What is xonsh?
            :align: center

.. class:: center

    If you like xonsh, :star: the repo, `write a tweet`_ and stay tuned by watching releases.

    .. image:: https://img.shields.io/badge/Zulip%20Community-xonsh-green
            :target: https://xonsh.zulipchat.com/join/hbvue5rimpdkwkdjuiqfs7tv/
            :alt: Join to xonsh.zulipchat.com

    .. image:: https://github.com/xonsh/xonsh/actions/workflows/test.yml/badge.svg
            :target: https://github.com/xonsh/xonsh/actions/workflows/test.yml
            :alt: GitHub Actions

    .. image:: https://codecov.io/gh/xonsh/xonsh/branch/master/graphs/badge.svg?branch=main
            :target: https://codecov.io/github/xonsh/xonsh?branch=main
            :alt: codecov.io

    .. image:: https://repology.org/badge/tiny-repos/xonsh.svg
            :target: https://repology.org/project/xonsh/versions
            :alt: repology.org

First steps
***********

Install xonsh from pip:

.. code-block:: xonshcon

    python -m pip install 'xonsh[full]'

And visit https://xon.sh for more information:

- `Installation <https://xon.sh/contents.html#installation>`_ - using packages, docker or AppImage.
- `Tutorial <https://xon.sh/tutorial.html>`_ - step by step introduction in xonsh.

Extensions
**********

Xonsh has an extension/plugin system.  We call these additions ``xontribs``.

- `Xontribs on Github <https://github.com/topics/xontrib>`_
- `Awesome xontribs <https://github.com/xonsh/awesome-xontribs>`_
- `Core xontribs <https://xon.sh/api/_autosummary/xontribs/xontrib.html>`_
- `Create a xontrib step by step from template <https://github.com/xonsh/xontrib-template>`_

Projects that use xonsh or compatible
*************************************

- `gitsome <https://github.com/donnemartin/gitsome>`_: Supercharged Git/shell autocompleter with GitHub integration.
- `xxh <https://github.com/xxh/xxh>`_: Using xonsh wherever you go through the SSH.
- `rever <https://regro.github.io/rever-docs/>`_: Cross-platform software release tool.
- `Regro autotick bot <https://github.com/regro/cf-scripts>`_: Regro Conda-Forge autoticker.
- `zoxide <https://github.com/ajeetdsouza/zoxide>`_: A smarter cd command.
- `any-nix-shell <https://github.com/haslersn/any-nix-shell>`_: xonsh support for the ``nix run`` and ``nix-shell`` environments of the Nix package manager.
- `Starship <https://starship.rs/>`_: Cross-shell prompt.

Jupyter-based interactive notebooks via `xontrib-jupyter <https://github.com/xonsh/xontrib-jupyter>`_:

- `Jupyter and JupyterLab <https://jupyter.org/>`_: Interactive notebook platform.
- `euporie <https://github.com/joouha/euporie>`_: Terminal based interactive computing environment.
- `Jupytext <https://jupytext.readthedocs.io/>`_: Clear and meaningful diffs when doing Jupyter notebooks version control.

The xonsh shell community
*************************

The xonsh shell is developed by a community of volunteers. There are a few ways to help out:

- Solve a `popular issue <https://github.com/xonsh/xonsh/issues?q=is%3Aissue+is%3Aopen+sort%3Areactions-%2B1-desc>`_. You can start with the `Developer guide <https://xon.sh/devguide.html>`_.
- Solve a `good first issue <https://github.com/xonsh/xonsh/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22+sort%3Areactions-%2B1-desc>`_.
- Take an `idea <https://github.com/xonsh/xontrib-template/issues?q=is%3Aopen+is%3Aissue+label%3Aidea+sort%3Areactions-%2B1-desc>`_ and `create a new xontrib <https://github.com/xonsh/xontrib-template#why-use-this-template>`_.
- Become xonsh core by deep diving into xonsh and improve the threading and subprocess logic.
- `Become a sponsor to xonsh <https://github.com/sponsors/xonsh>`_.
- `Write a tweet`_, post or an article to spread the good word about xonsh in the world.
- Give a star to xonsh repository and to `xontribs <https://github.com/topics/xontrib>`_ you like.

We welcome new contributors!

.. _write a tweet: https://twitter.com/intent/tweet?text=xonsh%20is%20a%20Python-powered,%20cross-platform,%20Unix-gazing%20shell%20language%20and%20command%20prompt.&url=https://github.com/xonsh/xonsh

Credits
*******

- Thanks to `Zulip <https://zulip.com/>`_ for supporting the xonsh community!