LinuxCommandLibrary

xonsh

Run Python-compatible shell commands

TLDR

Start an interactive shell session

$ xonsh
copy

Execute a single command and then exit
$ xonsh -c "[command]"
copy

Run commands from a script file and then exit
$ xonsh [path/to/script_file.xonsh]
copy

Define environment variables for the shell process
$ xonsh -D[name1]=[value1] -D[name2]=[value2]
copy

Load the specified .xonsh or .json configuration files
$ xonsh --rc [path/to/file1.xonsh] [path/to/file2.json]
copy

Skip loading the .xonshrc configuration file
$ xonsh --no-rc
copy

SYNOPSIS

xonsh [options] [script [arg ...]]
xonsh [options]

PARAMETERS

-h, --help
    Displays the help message and exits, detailing command-line options.

-V, --version
    Shows the xonsh version information and exits.

-c COMMAND
    Executes the specified COMMAND string. Any provided script will be ignored.

-D KEY=VAL
    Defines a xonsh environment variable for the current session. Can be used multiple times.

-i
    Forces interactive mode, even if a script is provided or stdin is not a TTY.

-l
    Starts xonsh as a login shell, loading system and user profile files (like .profile or .bash_profile) before .xonshrc.

--rc {always,on-error,never}
    Controls when the run control file (typically ~/.xonshrc) is loaded: 'always' (default), 'on-error' (only on startup errors), or 'never'.

--shell-type {prompt,readline,best}
    Selects the interactive shell user interface. 'prompt' is minimal, 'readline' uses GNU readline, and 'best' (default) attempts to use the most capable available.

script [arg ...]
    Executes the specified xonsh script file, passing any subsequent arguments to it.

DESCRIPTION

xonsh is a unique shell that seamlessly blends the best features of traditional Unix shells with the power and flexibility of Python. It allows users to execute shell commands (e.g., ls -l) and Python code (e.g., [x for x in range(10)]) directly within the same command line.

This hybrid approach enables advanced scripting, data manipulation, and customization by leveraging Python's rich ecosystem of libraries and data structures. xonsh supports familiar shell functionalities like piping, redirections, job control, aliases, and environment variables, alongside a programmable interface. It is cross-platform, compatible with Linux, macOS, and Windows, offering a modern and consistent command-line experience.

CAVEATS

While highly versatile, xonsh may present a steeper learning curve for users who are not familiar with Python, as its configuration and advanced scripting heavily rely on Python syntax. Its performance for very simple, repetitive tasks might be marginally slower than traditional shells like Bash or Zsh due to the overhead of the Python runtime.

CONFIGURATION

xonsh is extensively customizable via its run control file, typically named ~/.xonshrc. This file is a standard Python script, allowing users to define custom aliases, functions, environment variables, and import Python modules to tailor their shell environment to their specific workflow and preferences.

EXTENSIBILITY

The shell's functionality can be extended through 'xontribs' (xonsh contributions), which are Python packages designed to add new features, themes, or integrations. This modular design allows users to easily enhance their shell experience with a wide array of community-developed add-ons.

SEAMLESS PYTHON INTEGRATION

A core strength of xonsh is its ability to seamlessly execute Python code. Users can directly manipulate Python variables and data structures, call Python functions, and import Python modules alongside traditional shell commands, enabling powerful and complex scripting capabilities without switching environments.

HISTORY

xonsh was initially conceived and developed by Anthony Scopatz, with its first significant public release in 2014. The project aimed to create a shell that could bridge the gap between traditional Unix shell capabilities and the expressive power of Python, addressing the need for more sophisticated scripting and automation in command-line environments. Over the years, it has matured through active community contributions, evolving into a robust and cross-platform shell that provides a unique blend of shell and programming language features.

SEE ALSO

bash(1), zsh(1), fish(1), python(1)

Copied to clipboard