(text: string)
| 162 | * outside tmux, DCS-wrapped inside). |
| 163 | */ |
| 164 | export async function setClipboard(text: string): Promise<string> { |
| 165 | const b64 = Buffer.from(text, 'utf8').toString('base64') |
| 166 | const raw = osc(OSC.CLIPBOARD, 'c', b64) |
| 167 | |
| 168 | // Native safety net — fire FIRST, before the tmux await, so a quick |
| 169 | // focus-switch after selecting doesn't race pbcopy. Previously this ran |
| 170 | // AFTER awaiting tmux load-buffer, adding ~50-100ms of subprocess latency |
| 171 | // before pbcopy even started — fast cmd+tab → paste would beat it |
| 172 | // (https://anthropic.slack.com/archives/C07VBSHV7EV/p1773943921788829). |
| 173 | // Gated on SSH_CONNECTION (not SSH_TTY) since tmux panes inherit SSH_TTY |
| 174 | // forever but SSH_CONNECTION is in tmux's default update-environment and |
| 175 | // clears on local attach. Fire-and-forget. |
| 176 | if (!process.env['SSH_CONNECTION']) copyNative(text) |
| 177 | |
| 178 | const tmuxBufferLoaded = await tmuxLoadBuffer(text) |
| 179 | |
| 180 | // Inner OSC uses BEL directly (not osc()) — ST's ESC would need doubling |
| 181 | // too, and BEL works everywhere for OSC 52. |
| 182 | if (tmuxBufferLoaded) return tmuxPassthrough(`${ESC}]52;c;${b64}${BEL}`) |
| 183 | return raw |
| 184 | } |
| 185 | |
| 186 | // Linux clipboard tool: undefined = not yet probed, null = none available. |
| 187 | // Probe order: wl-copy (Wayland) → xclip (X11) → xsel (X11 fallback). |
no test coverage detected