1
0
Fork 0
mirror of synced 2026-12-06 18:12:25 +00:00
No description
  • Go 98.6%
  • Makefile 1.4%
Find a file
Parker Wahle f837bb4185
Pick the platform's clipboard tool instead of hardcoding pbcopy
Linux terminals without OSC 52 (VTE: GNOME Terminal, Ptyxis) get the same
treatment Terminal.app does: wl-copy under Wayland, xclip or xsel under X11,
clip.exe on WSL and termux-clipboard-set on Termux. The tool is looked up on
every copy.

The module path is github.com/regulad/osc52pty so that this fork can be
go-installed directly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 10:07:23 -05:00
.bumpversion.cfg Bump version: 0.1.3 → 0.2.0 2026-09-04 14:00:06 +08:00
.gitignore Add CI config 2020-10-01 17:43:36 +08:00
.travis.yml Add CI config 2020-10-01 17:43:36 +08:00
go.mod Pick the platform's clipboard tool instead of hardcoding pbcopy 2026-11-24 10:07:23 -05:00
go.sum Add CI config 2020-10-01 17:43:36 +08:00
LICENSE Add license 2020-10-01 20:26:46 +08:00
Makefile Add CI config 2020-10-01 17:43:36 +08:00
osc52pty.go Add tests 2020-10-01 17:38:06 +08:00
oscexecutor.go Pick the platform's clipboard tool instead of hardcoding pbcopy 2026-11-24 10:07:23 -05:00
oscexecutor_test.go Pick the platform's clipboard tool instead of hardcoding pbcopy 2026-11-24 10:07:23 -05:00
parser.go Add tests 2020-10-01 17:38:06 +08:00
parser_test.go Add tests 2020-10-01 17:38:06 +08:00
README.md Pick the platform's clipboard tool instead of hardcoding pbcopy 2026-11-24 10:07:23 -05:00
shell.go Fix bug 2020-10-03 11:25:09 +08:00
shell_test.go Add tests 2020-10-01 17:38:06 +08:00

osc52pty

Build Status Coverage Status

osc52pty recognizes OSC 52 sequences and pipes the content to the platform clipboard tool: pbcopy on macOS, clip.exe on WSL, termux-clipboard-set on Termux, else wl-copy under Wayland or xclip/xsel under X11.

If you're a Mac user who loves Terminal.app, you must be envious of iTerm2 users who can easily send a text to local clipboard from a remote side.

How the magic works? OSC 52 is one of Xterm Control Sequences, which is designated for clipboard setting. Once a terminal supporting OSC 52 catches a text in the form of OSC 52 from the output, instead of printing the text onto the screen, it decodes the text first and then sends the content to the system clipboard.

Although Terminal.app do NOT support OSC 52, here is the workaround for it.

Installation

Go toolchain is required.

go install github.com/regulad/osc52pty@master

Now you got the binary:

ls -lh "$(go env GOPATH)/bin/osc52pty"

Usage

Launch a shell with osc52pty to get OSC 52 supported:

osc52pty bash

Within the shell launched, send a OSC 52 sequence to testify:

printf "\e]52;c;%s\a" "$(echo -n 'THE TEXT TO COPY' | openssl base64 -A)"

Now the system clipboard is set to THE TEXT TO COPY.

Note: If you're going to send a OSC 52 sequence through TMUX, use this instead:

printf "\ePtmux;\e\e]52;c;%s\a\e\\" "$(echo -n 'THE TEXT TO COPY' | openssl base64 -A)"

BTW, TMUX's clipboard can play well with the OSC 52, search set-clipboard in man tmux for more details.

See also