Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

https://github.com/xonsh/xonsh/wiki/Cheatsheet

Tricks and Traps

  1. While $() in xonsh works similar to $() in (all variants of) shell, it cannot be used in the middle of argument of a shell command. Please refer to issue 1022 and issue 3290 for more details. My suggestion is to stick to xonsh as much as possible (as Python is much better than shell) unless you encounter the above issues.

  2. xonsh messes up console flush sometimes. Please refer to issue 3320 for more details.

  3. source sources in a xonsh script. source-bash sources in a Bash script.

    https://xon.sh/aliases.html#source-bash

    xonsh/xonsh#2978

Python Evaluation

Python Evalation with @()

The code below prints 1 2 3 in xonsh.

x = [1, 2, 3]
echo @(x)

Python Evalation with f-string.

The Python variales are casted to string directly. For example, the code below prints [1, 2, 3] in xonsh.

x = [1, 2, 3]
echo f'{x}'

Force (Shell) Subprocess

  1. use os.system or subprocess.run

  2. wrap the command in $(). Notice that $() cannot be used in the middle of arguments currently.

  3. wrap the command in $[]

  4. for some commands, you just need to put part of it into single/double quotes. For example, xonsh fails to recognize pip3 install dask[complete] as a shell command while it recognize pip3 install "dask[complete]" as a shell command.

Background Mode for Subprocess

xonsh/xonsh#1477

References

Bash to Xonsh Translation Guide¶

Run Control File

Updating and customizing xonsh

Environment Variables

Xonribs

Environment Variables

xonsh/xonsh#1477

https://stackoverflow.com/questions/39724184/how-to-write-a-multi-command-alias-in-xonsh/39761905#39761905