|
| 1 | +--- |
| 2 | +title: Command Options |
| 3 | +description: Full reference for RunOptions — configure timeout, environment, prompt detection, and more. |
| 4 | +--- |
| 5 | + |
| 6 | +## RunOptions |
| 7 | + |
| 8 | +All command execution methods (`$`, `terminal.run()`) accept an options object: |
| 9 | + |
| 10 | +```ts |
| 11 | +interface RunOptions { |
| 12 | + timeout?: number; |
| 13 | + env?: Record<string, string>; |
| 14 | + cwd?: string; |
| 15 | + interactive?: boolean; |
| 16 | + silent?: boolean; |
| 17 | + typingSpeed?: number; |
| 18 | + pauseAfter?: number; |
| 19 | + pauseBefore?: number; |
| 20 | + promptDetection?: 'auto' | 'osc133' | 'sentinel' | 'regex' | 'none'; |
| 21 | +} |
| 22 | +``` |
| 23 | + |
| 24 | +## Option Reference |
| 25 | + |
| 26 | +### timeout |
| 27 | + |
| 28 | +Command timeout in milliseconds. If the command doesn't complete within this time, it is killed. |
| 29 | + |
| 30 | +- **Default**: `300000` (5 minutes) |
| 31 | +- **Example**: `$({ timeout: 60_000 })\`long-running-cmd\`` |
| 32 | + |
| 33 | +### env |
| 34 | + |
| 35 | +Additional environment variables for the command. Merged with the current environment. |
| 36 | + |
| 37 | +```ts |
| 38 | +await $({ env: { NODE_ENV: 'test', DEBUG: '1' } })`node app.js`; |
| 39 | +``` |
| 40 | + |
| 41 | +### cwd |
| 42 | + |
| 43 | +Working directory for the command. |
| 44 | + |
| 45 | +```ts |
| 46 | +await $({ cwd: '/tmp/my-project' })`npm test`; |
| 47 | +``` |
| 48 | + |
| 49 | +### interactive |
| 50 | + |
| 51 | +Enable PTY mode with `expect`/`send` control for interactive commands. |
| 52 | + |
| 53 | +- **Default**: `false` |
| 54 | +- **Example**: `$({ interactive: true })\`python3\`` |
| 55 | + |
| 56 | +When enabled, the returned `PTYProcess` provides `expect()`, `send()`, `sendRaw()`, `interrupt()`, and `wait()` methods. |
| 57 | + |
| 58 | +### silent |
| 59 | + |
| 60 | +Force `Bun.spawn` even in PTY or recording mode. Use this when you need: |
| 61 | +- Reliable exit codes |
| 62 | +- Clean JSON output (no terminal escape sequences) |
| 63 | +- Separate stdout/stderr streams |
| 64 | + |
| 65 | +- **Default**: `false` |
| 66 | +- **Example**: `$({ silent: true })\`kubectl get pod -o json\`` |
| 67 | + |
| 68 | +### typingSpeed |
| 69 | + |
| 70 | +Controls character typing speed during recording mode. Each character is typed with this delay between keystrokes. |
| 71 | + |
| 72 | +- **Default**: `80` (ms per character) |
| 73 | +- **`0`**: Instant typing (no animation) |
| 74 | +- **Example**: `$({ typingSpeed: 40 })\`echo "fast typing"\`` |
| 75 | + |
| 76 | +Only affects recording mode. Ignored in other modes. |
| 77 | + |
| 78 | +### pauseAfter |
| 79 | + |
| 80 | +Pause after the command completes during recording mode. Useful for letting the viewer see the output before the next command. |
| 81 | + |
| 82 | +- **Default**: none |
| 83 | +- **Example**: `$({ pauseAfter: 2000 })\`echo "wait for it..."\`` |
| 84 | + |
| 85 | +Only affects recording mode. |
| 86 | + |
| 87 | +### pauseBefore |
| 88 | + |
| 89 | +Pause before the command starts during recording mode. |
| 90 | + |
| 91 | +- **Default**: none |
| 92 | +- **Example**: `$({ pauseBefore: 1000 })\`echo "dramatic pause"\`` |
| 93 | + |
| 94 | +Only affects recording mode. |
| 95 | + |
| 96 | +### promptDetection |
| 97 | + |
| 98 | +Override prompt detection strategy for this command. |
| 99 | + |
| 100 | +| Value | Description | |
| 101 | +| --- | --- | |
| 102 | +| `'auto'` | Best available method (default) | |
| 103 | +| `'osc133'` | Force OSC 133 detection only | |
| 104 | +| `'sentinel'` | Force sentinel marker detection | |
| 105 | +| `'regex'` | Force regex-based detection | |
| 106 | +| `'none'` | Skip prompt detection entirely | |
| 107 | + |
| 108 | +Use `'none'` for long-running or streaming commands where prompt detection is not applicable: |
| 109 | + |
| 110 | +```ts |
| 111 | +await $({ promptDetection: 'none' })`tail -f /var/log/syslog`; |
| 112 | +``` |
| 113 | + |
| 114 | +## Usage Examples |
| 115 | + |
| 116 | +```ts |
| 117 | +// Simple command with timeout |
| 118 | +await $({ timeout: 5000 })`echo hello`; |
| 119 | + |
| 120 | +// Silent mode for reliable JSON parsing |
| 121 | +const result = await $({ silent: true })`kubectl get pods -o json`; |
| 122 | +const pods = JSON.parse(result.stdout); |
| 123 | + |
| 124 | +// Interactive command |
| 125 | +const proc = $({ interactive: true, timeout: 30_000 })`python3`; |
| 126 | +await proc.expect('>>>'); |
| 127 | +await proc.send('exit()\n'); |
| 128 | + |
| 129 | +// Recording with typing animation |
| 130 | +await $({ typingSpeed: 40, pauseAfter: 1000 })`ls -la`; |
| 131 | + |
| 132 | +// Custom environment and working directory |
| 133 | +await $({ env: { PORT: '3000' }, cwd: '/app' })`npm start`; |
| 134 | +``` |
0 commit comments