← 返回 Skills 市场
65
总下载
0
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install zx
功能描述
Comprehensive guide for writing shell scripts with Google zx — a tool for writing better scripts using JavaScript/TypeScript. Use when writing, debugging, or...
使用说明 (SKILL.md)
\r \r
Zx — Write Better Shell Scripts with JavaScript\r
\r
Overview\r
\r
zx is Google's tool for writing shell scripts in JavaScript/TypeScript. It wraps child_process, auto-escapes arguments, and provides sensible defaults — giving you the power of the JavaScript ecosystem in your scripts.\r
\r
#!/usr/bin/env zx\r
\r
await $`cat package.json | grep name`\r
\r
const branch = await $`git branch --show-current`\r
await $`dep deploy --branch=${branch}`\r
\r
const name = 'foo & bar'\r
await $`mkdir /tmp/${name}` // No quotes needed — auto-escaped\r
```\r
\r
Bash is great for simple tasks, but when scripts grow complex, a full programming language helps. zx adds helpful wrappers around `child_process`, escapes arguments, and gives sensible defaults. **Think: bash + JavaScript in one script.**\r
\r
## Triggers\r
\r
Also triggers when users ask about running shell commands in JavaScript, converting bash scripts to zx, executing remote scripts, Markdown scripts, or TypeScript shell scripts.\r
\r
## Quick Start\r
\r
```bash\r
npm install zx\r
```\r
\r
Write scripts as `.mjs` files (supports top-level `await`). Add `#!/usr/bin/env zx` shebang or run via CLI:\r
\r
```bash\r
zx ./script.mjs # Direct execution\r
npx zx ./script.mjs # Via npx\r
node --import zx/globals # As Node.js loader\r
```\r
\r
All functions (`$`, `cd`, `fetch`, etc.) are globally available in zx scripts without imports. For explicit imports (better VS Code autocomplete):\r
\r
```js\r
import 'zx/globals'\r
```\r
\r
## Core Concepts\r
\r
### `` $`command` `` — Execute Shell Commands\r
\r
The tagged template literal is the heart of zx. Everything in `${...}` is auto-escaped and quoted.\r
\r
```js\r
// Async (standard) — returns ProcessPromise\r
const output = await $`ls -la`\r
\r
// Sync variant — returns ProcessOutput directly\r
const dir = $.sync`pwd`\r
\r
// Arrays are flattened\r
const flags = ['--oneline', '--decorate', '--color']\r
await $`git log ${flags}`\r
\r
// Non-zero exit codes throw ProcessOutput\r
try {\r
await $`exit 1`\r
} catch (p) {\r
console.log(`Exit: ${p.exitCode}, Error: ${p.stderr}`)\r
}\r
```\r
\r
### Preset Configuration with `$({...})`\r
\r
Create custom `$` instances with preset options — chainable and composable:\r
\r
```js\r
const $$ = $({ verbose: false, env: { NODE_ENV: 'production' } })\r
const pwd = $$.sync`pwd`\r
\r
// Presets are chainable\r
const $1 = $({ nothrow: true })\r
const $2 = $1({ sync: true }) // Both nothrow + sync applied\r
```\r
\r
### ProcessPromise & ProcessOutput\r
\r
```\r
$`cmd` ProcessPromise (extends Promise)\r
├── .pipe() Stream piping\r
├── .kill() Terminate process\r
├── .text() Output as string\r
├── .json() Output as parsed JSON\r
├── .lines() Output split by lines\r
├── .nothrow() Suppress errors for this command\r
├── .quiet() Suppress output for this command\r
├── .timeout() Auto-kill after duration\r
├── .stdio() Configure I/O\r
├── .exitCode Promise\x3Cexit code>\r
├── .stdout Readable stream\r
├── .stderr Readable stream\r
├── .stdin Writable stream\r
├── .pid / .cmd Process metadata\r
└── await → ProcessOutput\r
├── .stdout string\r
├── .stderr string\r
├── .exitCode number\r
├── .signal string|null\r
├── .text() / .json() / .lines() / .buffer() / .blob()\r
└── .ok boolean (when nothrow)\r
```\r
\r
## Decision Tree\r
\r
When writing zx scripts, use this decision tree:\r
\r
| Goal | Approach |\r
|------|----------|\r
| Run a command | `` await $`cmd` `` |\r
| Run synchronously | `` $.sync`cmd` `` |\r
| Pipe output | `` .pipe($`next`) `` / `` .pipe('file.txt') `` |\r
| Handle errors gracefully | `` $({nothrow: true}) `` / `` .nothrow() `` |\r
| Set timeout | `` $({timeout: '30s'}) `` / `` .timeout('30s') `` |\r
| Parse JSON output | `` (await $`cmd`).json() `` |\r
| Real-time streaming | `` for await (const line of $`cmd`) `` |\r
| Retry on failure | `` retry(5, () => $`cmd`) `` |\r
| User prompt | `` question('Name: ') `` |\r
| Progress indicator | `` await spinner('Working...', () => $`cmd`) `` |\r
| Change directory | `` cd('/path') `` or `` within(() => { $.cwd = '/tmp' }) `` |\r
| Temp files/dirs | `` tmpfile() `` / `` tmpdir() `` |\r
| Parse CLI args | `` argv.flag `` or `` minimist(process.argv.slice(2)) `` |\r
| Load .env file | `` dotenv.config('.env') `` |\r
\r
## Writing Effective zx Scripts\r
\r
### Parallel Execution\r
\r
```js\r
const results = await Promise.all([\r
$`sleep 1; echo 1`,\r
$`sleep 2; echo 2`,\r
$`sleep 3; echo 3`,\r
])\r
```\r
\r
### Error Handling with nothrow\r
\r
```js\r
$.nothrow = true\r
\r
const repos = ['zx', 'webpod']\r
const clones = repos.map(n => $`git clone https://github.com/google/${n}`)\r
\r
const results = await Promise.all(clones)\r
const errors = results.filter(o => !o.ok).map(o => o.stderr.trim())\r
console.log('Errors:', errors.join('\
'))\r
```\r
\r
### Stream Piping\r
\r
```js\r
// Chain commands like bash pipes\r
const greeting = await $`printf "hello"`\r
.pipe($`awk '{printf $1", world!"}'`)\r
.pipe($`tr '[a-z]' '[A-Z]'`)\r
\r
// Pipe to file\r
await $`echo "Hello!"`.pipe('/tmp/output.txt')\r
\r
// Real-time output to terminal\r
await $`echo 1; sleep 1; echo 2; sleep 1; echo 3`.pipe(process.stdout)\r
```\r
\r
### Stream Splitting & Merging\r
\r
```js\r
// Split one source to multiple consumers\r
const p = $`some-command`\r
const [o1, o2] = await Promise.all([\r
p.pipe`log`,\r
p.pipe`extract`,\r
])\r
\r
// Merge multiple sources\r
const $h = $({ halt: true })\r
const p1 = $`echo foo`\r
const p2 = $h`echo a && sleep 0.1 && echo b`\r
const p3 = $h`echo c && sleep 0.1 && echo d`\r
const cat = $h`cat`\r
p1.pipe(cat); p2.pipe(cat); p3.pipe(cat)\r
await cat.run()\r
```\r
\r
### Output Formatters\r
\r
```js\r
const p = $`echo '{"foo":"bar"}\
line2'`\r
\r
await p.json() // { foo: 'bar' }\r
await p.lines() // ['{"foo":"bar"}', 'line2']\r
await p.text() // '{"foo":"bar"}\
line2\
'\r
```\r
\r
### Async Iteration\r
\r
```js\r
for await (const line of $`git log --oneline --max-count=5`) {\r
console.log(line)\r
}\r
```\r
\r
## Shell Configuration\r
\r
zx defaults to bash. Switch shells as needed:\r
\r
```js\r
import { useBash, usePowerShell, usePwsh } from 'zx'\r
\r
usePowerShell() // PowerShell.exe\r
usePwsh() // PowerShell v7+\r
useBash() // Back to bash\r
\r
// Manual override\r
$.shell = '/bin/zsh'\r
```\r
\r
On Windows, consider using WSL or Git Bash for bash support, or switch to PowerShell via `usePowerShell()`.\r
\r
## Built-in Helpers Summary\r
\r
| Helper | Purpose | Example |\r
|--------|---------|---------|\r
| `cd()` | Change directory | `cd('/tmp')` |\r
| `fetch()` | HTTP requests, supports `.pipe()` | `fetch('https://api.example.com')` |\r
| `question()` | Interactive user input | `question('Name: ')` |\r
| `sleep()` | Delay execution | `await sleep(1000)` |\r
| `echo()` | Print to stdout | `` echo`Status: ${p}` `` |\r
| `stdin()` | Read stdin | `JSON.parse(await stdin())` |\r
| `within()` | Isolated async config context | `within(() => { $.cwd = '/tmp' })` |\r
| `retry()` | Retry with delay/backoff | `retry(5, () => $`curl url`)` |\r
| `spinner()` | CLI progress indicator | `await spinner(() => $`long-cmd`)` |\r
| `glob()` | File glob matching (globby) | `glob('**/*.js')` |\r
| `which()` | Find executable path | `await which('node')` |\r
| `ps` | Cross-platform process list | `ps.lookup({ command: 'node' })` |\r
| `tmpdir()` | Temp directory | `tmpdir('sub')` |\r
| `tmpfile()` | Temp file | `tmpfile('f.txt', 'content')` |\r
| `argv` | Parsed CLI arguments | `argv.verbose` |\r
| `dotenv` | .env file loading | `dotenv.config('.env')` |\r
\r
**Exposed npm packages:** `chalk` (colors), `fs` (fs-extra), `os`, `path`, `YAML` (yaml), `minimist`.\r
\r
## Resources\r
\r
- **[references/api.md](references/api.md)** — Full API reference: `$` options, `cd()`, `fetch()`, `question()`, `sleep()`, `echo()`, `stdin()`, `within()`, `retry()`, `spinner()`, `glob()`, `which()`, `ps`, `kill()`, `tmpdir()`, `tmpfile()`, `minimist`, `argv`, `chalk`, `fs`, `os`, `path`, `YAML`, `dotenv`, `quote()`, `useBash()`, `usePowerShell()`, `usePwsh()`\r
- **[references/configuration.md](references/configuration.md)** — All `$.options`: `shell`, `prefix`, `postfix`, `quote`, `verbose`, `quiet`, `env`, `cwd`, `timeout`, `nothrow`, `detached`, `preferLocal`, `spawn`, `kill`, `log`, `input`, `signal`, `stdio`, `halt`, `delimiter`, `defaults`\r
- **[references/cli.md](references/cli.md)** — CLI usage: flags, env vars, Markdown scripts, remote scripts, stdin execution, REPL mode\r
- **[references/process.md](references/process.md)** — ProcessPromise/ProcessOutput lifecycle, piping, killing, aborting, output formatters, stream handling\r
安全使用建议
This skill appears to be a benign zx reference. Install it if you want the agent to help write zx scripts, but remember that zx scripts are shell scripts with full local command power. Review commands, avoid untrusted remote scripts, and pin packages when using npx or auto-install features.
功能分析
Type: OpenClaw Skill
Name: zx
Version: 1.0.0
The skill bundle provides a comprehensive guide for using Google's 'zx' library, which enables an AI agent to execute shell commands, manage processes, and perform network requests. While the content is aligned with its stated purpose as a developer tool and lacks evidence of intentional malice or prompt injection, it explicitly instructs the agent on how to use high-risk capabilities like arbitrary shell execution (`$`), filesystem access (`fs-extra`), and network communication (`fetch`). These capabilities are documented across SKILL.md and multiple reference files (e.g., api.md, cli.md, process.md), making the bundle high-risk in an autonomous agent context.
能力评估
Purpose & Capability
The skill is coherently focused on writing and debugging zx shell scripts. Shell command execution is inherently powerful, but it is the central, disclosed purpose of zx.
Instruction Scope
The instructions include examples for running commands, piping streams, installing dependencies, and executing remote scripts. These are reference examples rather than hidden or automatic actions.
Install Mechanism
The skill itself has no install spec and no code files, but its documentation advises npm/npx usage and zx auto-install options; users should pin versions and use trusted package sources.
Credentials
The references cover environment variables, cwd, shell selection, dotenv files, and process controls, which are proportionate for a shell-scripting guide and do not show credential exfiltration or hidden access.
Persistence & Privilege
No artifact shows background persistence, privilege escalation, credential requirements, or autonomous long-running behavior by the skill itself.
如何使用
- 确保已安装 OpenClaw(本地或 Docker 部署)
- 在对话框中输入安装命令:
/install zx - 安装完成后,直接呼叫该 Skill 的名称或使用
/zx触发 - 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
Initial release of zx skill — a guide for shell scripting using Google zx.
- Provides comprehensive documentation and usage patterns for zx in JavaScript/TypeScript scripts.
- Covers core concepts: the $ command, piping, ProcessPromise/ProcessOutput APIs, option presets, and CLI usage.
- Includes quick start instructions and a decision tree for common scripting tasks.
- Documents built-in helpers and best practices for writing, debugging, and refactoring zx scripts.
- Clarifies the scope: for shell scripting with zx, not for unrelated Node.js questions.
元数据
常见问题
zx 是什么?
Comprehensive guide for writing shell scripts with Google zx — a tool for writing better scripts using JavaScript/TypeScript. Use when writing, debugging, or... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 65 次。
如何安装 zx?
在 OpenClaw 或 Claude Code 对话框中运行命令「/install zx」即可一键安装,无需额外配置。
zx 是免费的吗?
是的,zx 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。
zx 支持哪些平台?
zx 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。
谁开发了 zx?
由 OpenLark(@openlark)开发并维护,当前版本 v1.0.0。
推荐 Skills