(args: string[])
| 1178 | * This is called early in cli.tsx before loading the full CLI. |
| 1179 | */ |
| 1180 | export async function execIntoTmuxWorktree(args: string[]): Promise<{ |
| 1181 | handled: boolean |
| 1182 | error?: string |
| 1183 | }> { |
| 1184 | // Check platform - tmux doesn't work on Windows |
| 1185 | if (process.platform === 'win32') { |
| 1186 | return { |
| 1187 | handled: false, |
| 1188 | error: 'Error: --tmux is not supported on Windows', |
| 1189 | } |
| 1190 | } |
| 1191 | |
| 1192 | // Check if tmux is available |
| 1193 | const tmuxCheck = spawnSync('tmux', ['-V'], { encoding: 'utf-8' }) |
| 1194 | if (tmuxCheck.status !== 0) { |
| 1195 | const installHint = |
| 1196 | process.platform === 'darwin' |
| 1197 | ? 'Install tmux with: brew install tmux' |
| 1198 | : 'Install tmux with: sudo apt install tmux' |
| 1199 | return { |
| 1200 | handled: false, |
| 1201 | error: `Error: tmux is not installed. ${installHint}`, |
| 1202 | } |
| 1203 | } |
| 1204 | |
| 1205 | // Parse worktree name and tmux mode from args |
| 1206 | let worktreeName: string | undefined |
| 1207 | let forceClassicTmux = false |
| 1208 | for (let i = 0; i < args.length; i++) { |
| 1209 | const arg = args[i] |
| 1210 | if (!arg) continue |
| 1211 | if (arg === '-w' || arg === '--worktree') { |
| 1212 | // Check if next arg exists and isn't another flag |
| 1213 | const next = args[i + 1] |
| 1214 | if (next && !next.startsWith('-')) { |
| 1215 | worktreeName = next |
| 1216 | } |
| 1217 | } else if (arg.startsWith('--worktree=')) { |
| 1218 | worktreeName = arg.slice('--worktree='.length) |
| 1219 | } else if (arg === '--tmux=classic') { |
| 1220 | forceClassicTmux = true |
| 1221 | } |
| 1222 | } |
| 1223 | |
| 1224 | // Check if worktree name is a PR reference |
| 1225 | let prNumber: number | null = null |
| 1226 | if (worktreeName) { |
| 1227 | prNumber = parsePRReference(worktreeName) |
| 1228 | if (prNumber !== null) { |
| 1229 | worktreeName = `pr-${prNumber}` |
| 1230 | } |
| 1231 | } |
| 1232 | |
| 1233 | // Generate a slug if no name provided |
| 1234 | if (!worktreeName) { |
| 1235 | const adjectives = ['swift', 'bright', 'calm', 'keen', 'bold'] |
| 1236 | const nouns = ['fox', 'owl', 'elm', 'oak', 'ray'] |
| 1237 | const adj = adjectives[Math.floor(Math.random() * adjectives.length)] |
no test coverage detected