Skip to content

Copy with pbcopy on a Mac outside SSH - #11

Merged
gnocent merged 1 commit into
mainfrom
feat/mac-pbcopy
Oct 29, 2026
Merged

gnocent merged 1 commit into
mainfrom
feat/mac-pbcopy

Conversation

@gnocent

@gnocent gnocent commented Oct 29, 2026

Copy link
Copy Markdown
Owner

F2 (copy the result) and F9 (copy as cURL) went only through the terminal (OSC 52), which macOS Terminal ignores: nothing reached the clipboard there.

What changes

  • On a Mac, outside SSH (none of SSH_CONNECTION, SSH_CLIENT, SSH_TTY set), the copy goes through pbcopy: it works in any terminal, macOS Terminal included, and the status bar confirms it without its "(OSC 52 — requires a compatible terminal)" reservation.
  • Elsewhere, or if pbcopy fails, the copy goes through the terminal, as before.
  • Through SSH, pbcopy is never used: it would fill the remote Mac's pasteboard, not the user's.

pbcopy runs under LC_ALL=en_US.UTF-8: under a locale that isn't UTF-8, anything but ASCII would arrive garbled.

Tests

  • TestLocalPasteboard: which systems and sessions get pbcopy.
  • TestCopyGoesToThePasteboard, TestCopyFallsBackOnTheTerminal: F2 and F9 with a fake pasteboard, and the fallback.
  • TestPbcopyKeepsUnicode (macOS only): the real pbcopy, with accented text under a non-UTF-8 locale, read back with pbpaste; it puts the pasteboard's previous text back. The macOS job of this PR is its first run: it hasn't run anywhere else.

The ui tests leave the pasteboard out (TestMain): on a Mac they would otherwise replace what the developer had copied.

🤖 Generated with Claude Code

F2 and F9 copied only through the terminal (OSC 52), which macOS
Terminal ignores: nothing reached the clipboard there. On a Mac the
program runs on directly (none of SSH_CONNECTION, SSH_CLIENT, SSH_TTY
set), they now go through pbcopy, which works in any terminal and
confirms the copy: the status bar drops its "(OSC 52 — requires a
compatible terminal)" reservation. Should pbcopy fail, the copy goes
through the terminal, as elsewhere. Through SSH, pbcopy would fill the
remote Mac's pasteboard, so the terminal stays the only way.

pbcopy reads its input in the locale's encoding: it is run under
LC_ALL=en_US.UTF-8, or anything but ASCII would arrive garbled under a
locale that isn't UTF-8. TestPbcopyKeepsUnicode checks that on macOS,
against the real pasteboard, whose text it puts back.

The ui tests leave the pasteboard out (TestMain): on a Mac they would
otherwise replace what the developer had copied, and couldn't check
what goes to the terminal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gnocent
gnocent merged commit 1f55779 into main Oct 29, 2026
4 checks passed
@gnocent
gnocent deleted the feat/mac-pbcopy branch October 29, 2026 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant