shell-integration
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseShell Integration
Shell集成
Overview
概述
Shell integration covers the APIs and patterns for building tools that extend or interact with Unix shells. This includes completion systems, prompt hooks, key bindings, terminal control, and plugin distribution across Zsh, Bash, and Fish.
When to use: Building CLI tool completions, shell plugins, prompt customizations, terminal UI, dotfile managers, installation scripts, or native binary wrappers.
When NOT to use: General-purpose scripting unrelated to shell extension (use POSIX scripting reference for standalone scripts), GUI applications, or web server development.
Shell集成涵盖了用于构建扩展或与Unix Shell交互的工具的API与模式。这包括补全系统、提示符钩子、按键绑定、终端控制以及跨Zsh、Bash和Fish的插件分发。
适用场景:构建CLI工具补全、Shell插件、提示符自定义、终端UI、dotfile管理器、安装脚本或原生二进制包装器。
不适用场景:与Shell扩展无关的通用脚本编写(独立脚本请使用POSIX脚本参考)、GUI应用或Web服务器开发。
Quick Reference
快速参考
| Pattern | Shell | Key Points |
|---|---|---|
| Completion function | Zsh | |
| Completion function | Bash | |
| Completion function | Fish | |
| ZLE widget | Zsh | |
| Prompt hook | Zsh | |
| Prompt hook | Bash | |
| Event handler | Fish | |
| Abbreviation | Fish | |
| Parameter expansion | Zsh | |
| Terminal control | All | ANSI/CSI escape sequences, |
| Signal handling | All | |
| Process management | All | Job control ( |
| Plugin installation | All | Sourcing strategies, version detection, |
| 模式 | Shell | 核心要点 |
|---|---|---|
| 补全函数 | Zsh | |
| 补全函数 | Bash | |
| 补全函数 | Fish | |
| ZLE组件 | Zsh | |
| 提示符钩子 | Zsh | 通过 |
| 提示符钩子 | Bash | |
| 事件处理器 | Fish | |
| 缩写 | Fish | |
| 参数展开 | Zsh | |
| 终端控制 | 所有Shell | ANSI/CSI转义序列、 |
| 信号处理 | 所有Shell | |
| 进程管理 | 所有Shell | 作业控制( |
| 插件安装 | 所有Shell | 源码加载策略、版本检测、 |
Common Mistakes
常见错误
| Mistake | Correct Pattern |
|---|---|
Using | Use |
Modifying | Append with |
| Defining Fish event handlers in lazy-loaded functions | Place event handlers in config.fish or source them explicitly |
| Hardcoding terminal capabilities | Query via |
Missing | Always set local options to avoid polluting caller environment |
Using | Use |
Not quoting | Always use |
Assuming | Target POSIX sh for portable scripts, test with |
Using | Use |
Ignoring | Always set |
| 错误 | 正确做法 |
|---|---|
可移植场景下使用 | 使用 |
在Bash中用 | 使用 |
| 在延迟加载的函数中定义Fish事件处理器 | 将事件处理器放在config.fish中或显式加载它们 |
| 硬编码终端功能 | 通过 |
Zsh函数中缺少 | 始终设置本地选项,避免污染调用者的环境 |
使用 | 使用 |
包装器脚本中未引用 | 始终使用 |
假设 | 针对POSIX sh编写可移植脚本,使用 |
POSIX脚本中使用 | 使用 |
忽略 | 始终设置 |
Delegation
任务分工
- Completion testing: Use agent to verify completions interactively
Explore - Script review: Use agent for cross-shell compatibility audits
Task - Code review: Delegate to agent
code-reviewer
If theskill is available, delegate native binary compilation patterns to it. Shell wrappers often invoke Rust-compiled binaries for performance-critical operations. If therustskill is available, delegate modern CLI utility patterns to it. Many shell plugins wrap tools likecli-power-tools,fd, andripgrep.fzf
- 补全测试:使用Agent交互式验证补全功能
Explore - 脚本审查:使用Agent进行跨Shell兼容性审计
Task - 代码审查:委托给Agent
code-reviewer
若技能可用,将原生二进制文件编译模式的相关工作委托给它。Shell包装器通常会调用Rust编译的二进制文件来处理性能关键型操作。 若rust技能可用,将现代CLI工具模式的相关工作委托给它。许多Shell插件会包装cli-power-tools、fd和ripgrep等工具。fzf
References
参考资料
- Zsh integration: ZLE, completions, hooks, parameter expansion
- Bash integration: readline, completions, PROMPT_COMMAND, shopt
- Fish integration: completions, events, abbreviations, functions
- Terminal control: ANSI/CSI sequences, tput, stty, capabilities
- POSIX scripting: portable patterns, signal handling, process management
- Plugin distribution: installation scripts, dotfile management, version detection
- Zsh集成:ZLE、补全、钩子、参数展开
- Bash集成:readline、补全、PROMPT_COMMAND、shopt
- Fish集成:补全、事件、缩写、函数
- 终端控制:ANSI/CSI序列、tput、stty、终端功能
- POSIX脚本编写:可移植模式、信号处理、进程管理
- 插件分发:安装脚本、dotfile管理、版本检测