Skills2026年5月13日·1 分钟阅读

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.

Agent 就绪

这个资产可以被 Agent 直接读取和安装

TokRepo 同时提供通用 CLI 命令、安装契约、metadata JSON、按适配器生成的安装计划和原始内容链接,方便 Agent 判断适配度、风险和下一步动作。

Needs Confirmation · 64/100策略:需确认
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Xonsh Overview
通用 CLI 安装命令
npx tokrepo install 42c0deca-4ee7-11f1-9bc6-00163e2b0d79

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

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产