(text: string)
| 136 | * outside tmux, DCS-wrapped inside). |
| 137 | */ |
| 138 | export async function setClipboard(text: string): Promise<string> { |
| 139 | const b64 = Buffer.from(text, 'utf8').toString('base64') |
| 140 | const raw = osc(OSC.CLIPBOARD, 'c', b64) |
| 141 | |
| 142 | // Native safety net — fire FIRST, before the tmux await, so a quick |
| 143 | // focus-switch after selecting doesn't race pbcopy. Previously this ran |
| 144 | // AFTER awaiting tmux load-buffer, adding ~50-100ms of subprocess latency |
| 145 | // before pbcopy even started — fast cmd+tab → paste would beat it |
| 146 | // (https://anthropic.slack.com/archives/C07VBSHV7EV/p1773943921788829). |
| 147 | // Gated on SSH_CONNECTION (not SSH_TTY) since tmux panes inherit SSH_TTY |
| 148 | // forever but SSH_CONNECTION is in tmux's default update-environment and |
| 149 | // clears on local attach. Fire-and-forget. |
| 150 | if (!process.env['SSH_CONNECTION']) copyNative(text) |
| 151 | |
| 152 | const tmuxBufferLoaded = await tmuxLoadBuffer(text) |
| 153 | |
| 154 | // Inner OSC uses BEL directly (not osc()) — ST's ESC would need doubling |
| 155 | // too, and BEL works everywhere for OSC 52. |
| 156 | if (tmuxBufferLoaded) return tmuxPassthrough(`${ESC}]52;c;${b64}${BEL}`) |
| 157 | return raw |
| 158 | } |
| 159 | |
| 160 | // Linux clipboard tool: undefined = not yet probed, null = none available. |
| 161 | // Probe order: wl-copy (Wayland) → xclip (X11) → xsel (X11 fallback). |
no test coverage detected