| 15 | } |
| 16 | |
| 17 | function detectProvider(): ClipboardProvider | undefined { |
| 18 | const os = platform(); |
| 19 | if (os === "darwin") { |
| 20 | return { cmd: "pbcopy", args: [] }; |
| 21 | } |
| 22 | if (os === "win32") { |
| 23 | return { cmd: "clip.exe", args: [] }; |
| 24 | } |
| 25 | // Linux / BSD — pick the first tool that's on PATH. |
| 26 | // WSL exposes clip.exe too; prefer it so copies land in the Windows |
| 27 | // clipboard where the user actually sees them. |
| 28 | const candidates: ClipboardProvider[] = [ |
| 29 | { cmd: "clip.exe", args: [] }, |
| 30 | { cmd: "wl-copy", args: [] }, |
| 31 | { cmd: "xclip", args: ["-selection", "clipboard"] }, |
| 32 | { cmd: "xsel", args: ["--clipboard", "--input"] }, |
| 33 | ]; |
| 34 | const cmd = process.platform === "win32" ? "where" : "which"; |
| 35 | for (const p of candidates) { |
| 36 | const result = spawnSync(cmd, [p.cmd], { stdio: "ignore" }); |
| 37 | if (result.status === 0) return p; |
| 38 | } |
| 39 | return undefined; |
| 40 | } |
| 41 | |
| 42 | let cachedProvider: ClipboardProvider | undefined | null = null; |
| 43 | |