ff4e18ca8b
- tty: fix isStdoutTTY to use fstat first, fall back to TERM heuristic - git: fix commit regex to handle root-commit output format - git: fix parseNameStatus to handle edge cases (empty lines, missing tabs) - ai: fix readStream to cancel reader instead of releaseLock - cli: remove dead code resolveFlagName function - clipboard: fix inconsistent indentation Co-Authored-By: Claude <noreply@anthropic.com>
29 lines
655 B
TypeScript
29 lines
655 B
TypeScript
export async function copyToClipboard(text: string): Promise<boolean> {
|
|
const commands: string[][] = [];
|
|
|
|
if (process.platform === "darwin") {
|
|
commands.push(["pbcopy"]);
|
|
} else if (process.platform === "linux") {
|
|
commands.push(["xclip", "-selection", "clipboard"]);
|
|
commands.push(["xsel", "--clipboard", "--input"]);
|
|
}
|
|
|
|
for (const cmd of commands) {
|
|
try {
|
|
const proc = Bun.spawn(cmd, {
|
|
stdin: "pipe",
|
|
stdout: "ignore",
|
|
stderr: "ignore",
|
|
});
|
|
proc.stdin.write(text);
|
|
proc.stdin.end();
|
|
const exitCode = await proc.exited;
|
|
if (exitCode === 0) return true;
|
|
} catch {
|
|
// Try next command
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|