├── .github └── FUNDING.yml ├── LICENSE ├── README.md └── mamba-install-xonsh.sh /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | 2 | # These are supported funding model platforms 3 | 4 | #github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 5 | #patreon: xonssh # Replace with a single Patreon username 6 | #open_collective: # Replace with a single Open Collective username 7 | #ko_fi: # Replace with a single Ko-fi username 8 | #tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 9 | #community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 10 | #liberapay: # Replace with a single Liberapay username 11 | #issuehunt: # Replace with a single IssueHunt username 12 | #otechie: # Replace with a single Otechie username 13 | custom: ['https://github.com/anki-code', 'https://www.buymeacoffee.com/xxh', 'https://github.com/xonsh/xonsh#the-xonsh-shell-community'] 14 | 15 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 2-Clause License 2 | 3 | Copyright (c) 2024, Andy Kipp 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | Best way to install xonsh on macOS or Linux and using it as core shell. 3 |

4 | 5 |

6 | If you like the idea click ⭐ on the repo and tweet. 7 |

8 | 9 | ## Motivation 10 | 11 | Xonsh is a Python-based shell, and to run xonsh you must have Python installed. The Python version and its packages can be installed and located anywhere and when you execute `import` or any other Python code during a xonsh session, it will be executed in the Python environment that was used to run the current instance of xonsh. You must have good knowledge of this process after reading [xonsh-cheatsheet](https://github.com/anki-code/xonsh-cheatsheet/). 12 | 13 | When xonsh becomes a core shell it's needed to keep python environment with xonsh stable, predictable and independent of any changes in the system. The lightweight environment managers like `venv`, `pipx` or `rye` will not help with this and it's needed to use package managers that have ability to install isolated python invironment as core feature e.g. `miniconda`, `micromamba`. 14 | 15 | ## mamba-install-xonsh 16 | 17 | The `mamba-install-xonsh.sh` script creates independent python environment for xonsh using [mamba](https://mamba.readthedocs.io/) in `$TARGET_DIR` without affect any other things on the system. It's isolated xonsh-specific environment that can't be affected by upgrading the system packages, python version and other experiments around environments. You can use `xpip` and `xmamba` to install packages into this environment intentionally. 18 | 19 | **Install stable**: the latest xonsh release with mostly tested python version: 20 | 21 | ```xsh 22 | TARGET_DIR=$HOME/.local/xonsh-env PYTHON_VER=3.11 XONSH_VER='xonsh[full]>=0.19.0' \ 23 | /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/anki-code/xonsh-install/main/mamba-install-xonsh.sh)" 24 | ``` 25 | 26 | **Install the front line**: xonsh from main git branch with stable python version (known issues: [#5166](https://github.com/xonsh/xonsh/issues/5166)): 27 | 28 | ```xsh 29 | TARGET_DIR=$HOME/.local/xonsh-env PYTHON_VER=3.12 XONSH_VER='git+https://github.com/xonsh/xonsh#egg=xonsh[full]' \ 30 | /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/anki-code/xonsh-install/main/mamba-install-xonsh.sh)" 31 | ``` 32 | 33 | **Install with stuff**: preinstall and preload [xontribs](https://github.com/topics/xontrib) (good for ssh and as manual alternative to [xxh](https://github.com/xxh/xxh)): 34 | 35 | ```xsh 36 | TARGET_DIR=$HOME/.local/xonsh-env PYTHON_VER=3.11 XONSH_VER='git+https://github.com/xonsh/xonsh#egg=xonsh[full]' \ 37 | PIP_INSTALL="uv xontrib-sh xontrib-jump-to-dir xontrib-dalias xontrib-pipeliner xontrib-whole-word-jumping" \ 38 | XONSHRC="\$XONSH_HISTORY_BACKEND = 'sqlite'; xontrib load -s sh jump_to_dir pipeliner whole_word_jumping dalias; \$PROMPT = \$PROMPT.replace('{prompt_end}', '\n{prompt_end}')" \ 39 | /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/anki-code/xonsh-install/main/mamba-install-xonsh.sh)" 40 | ``` 41 | 42 | ### Usage 43 | 44 | Now forget about the cases where manipulations around python and packages break the shell unintended. Use `pip`, `brew` and other package managers without corrupting xonsh-env. 45 | 46 | After installation: 47 | * `xonsh` refers to `~/.local/xonsh-env/xbin/xonsh`. 48 | * `xpip` refers to `~/.local/xonsh-env/bin/python -m pip`. 49 | * You can run `source xmamba` to activate mamba. See below. 50 | 51 | Additions: 52 | 53 | * `xbin-xonsh` is to run xonsh from xonsh-env if xonsh overwritten by `$PATH`. 54 | * `xbin-python` is to run python from xonsh-env. 55 | * Use executable script from xonsh-env: 56 | * `xbin-hidden` is to list xonsh-env internal hidden `bin` directory. E.g. `xpip install lolcat && xbin-hidden # lolcat`. 57 | * `xbin-add` is to add executer from hidden `bin` to visible `xbin`. E.g. `xbin-add lolcat`. 58 | * `xbin-list` is to list visible `xbin` directory. E.g. `xbin-list # lolcat`. 59 | * `xbin-del` is to delete executer from `xbin`. E.g. `xbin-del lolcat`. It will stay in `bin`. 60 | 61 | ### Tips and tricks 62 | 63 | #### Using mamba from xonsh-env 64 | 65 | To bind xonsh-env micromamba to `xmamba` alias run: 66 | ```xsh 67 | source xmamba 68 | ``` 69 | Now you can: 70 | ```xsh 71 | xmamba activate base # Env where xonsh was installed. 72 | pip install lolcat # Install `lolcat` into `base` env. 73 | xmamba deactivate 74 | 75 | xmamba create --name myenv python=3.12 76 | xmamba activate myenv 77 | pip install lolcat # Install `lolcat` into `myenv`. 78 | xmamba deactivate 79 | ``` 80 | 81 | #### Cleaning 82 | 83 | If you have no plans to use `xmamba` [clean](https://fig.io/manual/mamba/clean) the disk space: 84 | 85 | ```xsh 86 | source xmamba 87 | xmamba clean -a 88 | ``` 89 | 90 | ### Uninstall 91 | 92 | Just delete `$TARGET_DIR` e.g. `rm -rf ~/.local/xonsh-env/` by default. 93 | 94 | ### Known issues 95 | 96 | #### Do not blindly use as a login shell 97 | 98 | We do not recommend to use xonsh as a [login shell](https://linuxhandbook.com/login-shell/) if you are not feel you strong and experienced. Most tools are waiting that login shell is POSIX-compliant you can face with issues when some tool is trying to run POSIX-compatible commands in xonsh. 99 | 100 | #### `std::bad_alloc` 101 | 102 | If you see `terminate called after throwing an instance of 'std::bad_alloc'` just delete the target directory (e.g. `rm -rf ~/.local/xonsh-env/`) and try to install again. 103 | 104 | ## Another way to install xonsh 105 | 106 | If you know how to install xonsh using another package manager - PR is welcome! 107 | 108 | ## See also 109 | * [xonsh-cheatsheet](https://github.com/anki-code/xonsh-cheatsheet/tree/main) - Cheat sheet for xonsh shell with copy-pastable examples. The best doc for the new users. 110 | * [xonsh.AppImage](https://xon.sh/appimage.html) - one executable file which contains both xonsh and Python. AppImage allows xonsh to be run on any AppImage supported Linux distribution without installation or root access. 111 | -------------------------------------------------------------------------------- /mamba-install-xonsh.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -eu 4 | 5 | echo 6 | echo Start 7 | echo 8 | 9 | TARGET_DIR="${TARGET_DIR:-${HOME}/.local/xonsh-env}" 10 | PYTHON_VER="${PYTHON_VER:-3.12}" 11 | XONSH_VER="${XONSH_VER:-xonsh[full]}" 12 | PIP_INSTALL="${PIP_INSTALL:-}" 13 | XONSHRC="${XONSHRC:-}" 14 | 15 | 16 | MAMBA_BIN_DIR="${TARGET_DIR}/bin" 17 | MAMBA_USE_CONDA_FORGE="${MAMBA_USE_CONDA_FORGE:-yes}" 18 | 19 | echo 20 | echo Env 21 | echo 22 | echo TARGET_DIR=$TARGET_DIR 23 | echo PYTHON_VER=$PYTHON_VER 24 | echo MAMBA_USE_CONDA_FORGE=$MAMBA_USE_CONDA_FORGE 25 | 26 | echo 27 | echo Create directories 28 | echo 29 | 30 | mkdir -p $TARGET_DIR $MAMBA_BIN_DIR $TARGET_DIR/xbin 31 | cd $TARGET_DIR 32 | 33 | 34 | echo 35 | echo Install micromamba 36 | echo 37 | 38 | # START INSTALLING MAMBA -- Code from https://github.com/mamba-org/micromamba-releases/blob/main/install.sh 39 | 40 | # Computing artifact location 41 | case "$(uname)" in 42 | Linux) 43 | PLATFORM="linux" ;; 44 | Darwin) 45 | PLATFORM="osx" ;; 46 | *NT*) 47 | PLATFORM="win" ;; 48 | esac 49 | 50 | ARCH="$(uname -m)" 51 | case "$ARCH" in 52 | aarch64|ppc64le|arm64) 53 | ;; # pass 54 | *) 55 | ARCH="64" ;; 56 | esac 57 | 58 | case "$PLATFORM-$ARCH" in 59 | linux-aarch64|linux-ppc64le|linux-64|osx-arm64|osx-64|win-64) 60 | ;; # pass 61 | *) 62 | echo "Failed to detect your OS" >&2 63 | exit 1 64 | ;; 65 | esac 66 | 67 | if [ "${VERSION:-}" = "" ]; then 68 | RELEASE_URL="https://github.com/mamba-org/micromamba-releases/releases/latest/download/micromamba-${PLATFORM}-${ARCH}" 69 | else 70 | RELEASE_URL="https://github.com/mamba-org/micromamba-releases/releases/download/micromamba-${VERSION}/micromamba-${PLATFORM}-${ARCH}" 71 | fi 72 | 73 | 74 | # Downloading artifact 75 | mkdir -p "${MAMBA_BIN_DIR}" 76 | if hash curl >/dev/null 2>&1; then 77 | curl "${RELEASE_URL}" -o "${MAMBA_BIN_DIR}/micromamba" -fsSL --compressed ${CURL_OPTS:-} 78 | elif hash wget >/dev/null 2>&1; then 79 | wget ${WGET_OPTS:-} -qO "${MAMBA_BIN_DIR}/micromamba" "${RELEASE_URL}" 80 | else 81 | echo "Neither curl nor wget was found" >&2 82 | exit 1 83 | fi 84 | chmod +x "${MAMBA_BIN_DIR}/micromamba" 85 | 86 | 87 | # Initializing conda-forge 88 | case "$MAMBA_USE_CONDA_FORGE" in 89 | y|Y|yes) 90 | "${MAMBA_BIN_DIR}/micromamba" config append channels conda-forge 91 | "${MAMBA_BIN_DIR}/micromamba" config append channels nodefaults 92 | "${MAMBA_BIN_DIR}/micromamba" config set channel_priority strict 93 | ;; 94 | esac 95 | 96 | # STOP INSTALLING MAMBA 97 | 98 | echo 99 | echo Install xonsh 100 | echo 101 | 102 | cat > ./xbin/xmamba < ./xbin/xbin-add < ./xbin/xbin-del < ./xbin/xbin-list < ./xbin/xbin-hidden <> ~/.xonshrc 163 | fi 164 | 165 | # echo 166 | # echo Test and prewarm xonsh 167 | # echo 168 | # ${TARGET_DIR}/xbin/xonsh --no-rc --no-env -c "2+2" 169 | 170 | echo 171 | echo Result 172 | echo 173 | echo TARGET_DIR=$TARGET_DIR 174 | echo PYTHON_VER=$PYTHON_VER 175 | echo MAMBA_USE_CONDA_FORGE=$MAMBA_USE_CONDA_FORGE 176 | echo 177 | echo Now you can: 178 | echo 179 | echo ' * Add `xbin` dir to the top of your system shell path:' 180 | echo 181 | echo " echo 'export PATH=${TARGET_DIR}/xbin:\$PATH' >> ~/.zshrc" 182 | echo " echo 'export PATH=${TARGET_DIR}/xbin:\$PATH' >> ~/.bashrc" 183 | echo ' # Restart session and run xonsh.' 184 | echo 185 | echo " * Or run xonsh manually by path from any place:" 186 | echo 187 | echo " ${TARGET_DIR}/xbin/xonsh" 188 | echo 189 | --------------------------------------------------------------------------------