# Xonsh — Python-Powered Cross-Platform Shell > A shell language and command prompt that combines Python with Bash-like syntax, letting you mix shell commands and Python expressions seamlessly. ## Install Save in your project root: # Xonsh — Python-Powered Cross-Platform Shell ## Quick Use ```bash pip install xonsh[full] xonsh # Now you can run shell commands and Python interchangeably ls -la len([f for f in $(ls).split() if f.endswith(".py")]) ``` ## Introduction Xonsh is a Python-powered, cross-platform shell that blends the expressiveness of Python with the convenience of traditional Unix shell syntax. It parses commands contextually: lines that look like shell commands run as subprocesses, while Python expressions are evaluated directly, giving you a single environment for scripting and interactive use. ## What Xonsh Does - Runs standard shell commands (ls, git, curl) alongside Python expressions in one prompt - Provides tab completion for file paths, Python objects, environment variables, and man pages - Supports customizable prompts with Git status, virtualenv info, and user-defined fields - Includes an extensible plugin system (xontribs) for additional functionality - Works on Linux, macOS, and Windows without separate configuration per platform ## Architecture Overview Xonsh uses a two-pass parser that first tries to interpret input as Python. If that fails, it falls back to subprocess mode, splitting the line into a command and arguments. Environment variables are shared between both modes through a special Env mapping. The shell is built on top of CPython and can import any installed Python package directly in the prompt. Xontribs extend the shell at startup via entry points. ## Self-Hosting & Configuration - Install via pip, conda, or system package managers (apt, brew, pacman) - Create a ~/.xonshrc file for startup configuration using standard Python syntax - Set environment variables with $VAR = "value" using shell-style dollar-sign notation - Install xontribs for features like autojump, Docker completion, or Jupyter kernel support - Configure the prompt format using $PROMPT with built-in fields or custom callables ## Key Features - Seamless mode switching between Python and subprocess execution in a single line - Rich tab completion powered by Python introspection and man page parsing - History backend supports JSON, SQLite, or custom storage for searchable command history - Built-in glob expressions and regular expression path matching for file operations - Scripting in .xsh files combines shell pipelines with Python control flow and data structures ## Comparison with Similar Tools - **Bash/Zsh** — traditional shells with extensive ecosystem but limited scripting ergonomics compared to Python - **Fish** — user-friendly with good defaults, but uses its own scripting language rather than Python - **Nushell** — structured data shell with tables and pipelines, but not Python-compatible - **IPython** — interactive Python with shell magic commands, but not designed as a login shell ## FAQ **Q: Can I use Xonsh as my default login shell?** A: Yes. Add the xonsh path to /etc/shells and use chsh to set it. Many users run it daily as their primary shell. **Q: Does Xonsh support Bash scripts?** A: Not directly. Xonsh has its own syntax. You can call bash scripts as subprocesses, but .bashrc files are not sourced. **Q: How fast is Xonsh compared to Bash?** A: Startup is slower due to Python initialization. For interactive use the difference is minor, but for running thousands of short scripts, Bash is faster. **Q: Can I use pip packages in my shell?** A: Yes. Any Python package installed in the same environment is importable directly in the Xonsh prompt or .xsh scripts. ## Sources - https://github.com/xonsh/xonsh - https://xon.sh --- Source: https://tokrepo.com/en/workflows/asset-42c0deca Author: AI Open Source