xonsh: Python-powered Shell

0.22.8 · active · verified Thu Apr 16

xonsh (pronounced 'consh') is a modern, full-featured, and cross-platform shell language and command prompt powered by Python. It seamlessly integrates Python 3 with shell functionality, allowing users to mix Python code and shell commands. The current version is 0.22.8, and it maintains a regular release cadence, supporting the latest minor Python versions (currently Python >=3.11).

Common errors

Warnings

Install

Imports

Quickstart

After installing, simply type `xonsh` in your terminal to start the shell. The quickstart demonstrates how to declare Python variables, use them in shell commands via Python substitution (`@(variable)`), execute loops that mix both modes, and interact with environment variables and subprocess outputs. This code snippet shows Python syntax that would typically be placed in a `.xonshrc` file or run directly in the xonsh prompt, illustrating the core hybrid nature of the shell.

import os

# To run xonsh, simply execute 'xonsh' in your terminal after installation.
# This example demonstrates mixing Python and shell commands within a .xonshrc file or interactively.

# Python mode: Assign a variable
name = 'xonsh_user'

# Subprocess mode: Echo the variable using Python substitution
print(f"echo Hello, @(name)!")

# Mixing Python and shell for a loop
for i in range(3):
    print(f"echo Loop iteration: @(i)")

# Accessing environment variables (Python style)
path_var = os.environ.get('PATH', '')
print(f"Current PATH has {len(path_var.split(os.pathsep))} entries.")

# Running a shell command and capturing its output (subprocess style)
output = $(ls -l)
print(f"'ls -l' command output length: {len(output)}")

view raw JSON →