A command line tool to access the system clipboard from anywhere using the ANSI OSC52 sequence.
System clipboard access includes writing (i.e. copy) and reading (i.e. paste), even while logged into a remote machine via ssh.
❯ echo -n asdf | osc copy
# String 'asdf' copied to clipboard
❯ osc paste
asdf
❯ osc copy /dev/null
# Clipboard cleared
Reads or writes the system clipboard using the ANSI OSC52 escape sequence.
Usage:
osc [command]
Available Commands:
completion Generate the autocompletion script for the specified shell
copy Copies input to the system clipboard
help Help about any command
paste Outputs system clipboard contents to stdout
version Outputs version information
Flags:
-c, --clipboard string target clipboard, can be empty or one or more of c, p, q, s, or 0-7 (default "c")
-d, --device string use specific tty device
-h, --help help for osc
-l, --log string write logs to file
-t, --timeout float tty read timeout in seconds (default 5)
-v, --verbose verbose logging
Use "osc [command] --help" for more information about a command.
OSC52 is overall widely supported, but clipboard read operation is less widely supported than write.
Terminal | Terminal OS | Shell OS | Copy | Paste | Notes |
---|---|---|---|---|---|
alacritty 0.13.1 | macOS | linux | ✓ | ✓ | Paste support requires setting terminal.osc52 to CopyPaste or OnlyPaste |
alacritty 0.13.1 | macOS | macOS | ✓ | ✓ | Paste support requires setting terminal.osc52 to CopyPaste or OnlyPaste |
alacritty 0.13.2 | Windows | linux | ✓ | ✗ | |
alacritty 0.13.2 | Windows | Windows | ✓ | ✗ | |
kitty 0.29.0 | macOS | linux | ✓ | ✓ | Prompts for access |
kitty 0.29.0 | macOS | macOS | ✓ | ✓ | Prompts for access |
windows terminal v1.17.11461.0 | Windows | Windows | ✓ | ✗ | |
windows terminal v1.17.11461.0 | Windows | linux | ✓ | ✗ | |
mintty 3.7.6 | Windows | Windows | ✓ | ✗ | Paste support: #13 |
mintty 3.7.6 | Windows | linux | ✓ | ✓ | Configure AllowSetSelection , AllowPasteSelection to true for copy and paste respectively.Must use cygwin openssh, native ssh.exe for windows causes issues. |
iterm2 | macOS | linux | ✓ | ✓ | Paste requires version 3.5.0. Prompts for access. |
iterm2 | macOS | macOS | ✓ | ✓ | Paste requires version 3.5.0. Prompts for access. |
hterm | ChromeOS | linux | ✓ | ✗ |
Using alacritty as the terminal:
Terminal Multiplexer | Copy | Paste | Notes |
---|---|---|---|
screen 4.09.00 | ✓ | ✓ | |
zellij 0.37.2 | ✓ | ✗ | Paste not supported: zellij-org/zellij#2647 |
tmux 3.3 | ✓ | ✓ | allow-passthrough (for copy) and set-clipboard (for paste) should be enabled |
Download the latest binary from GitHub.
osc is a stand-alone binary. Once downloaded, copy it to a location you can run executables from (ie: /usr/local/bin/
), and set the permissions accordingly:
chmod a+x /usr/local/bin/osc
go install -v github.com/theimpostor/osc@latest
This will install the latest version of osc to $GOPATH/bin
. To find out where $GOPATH
is, run go env GOPATH
osc can be used as the clipboard provider for Neovim:
vim.cmd([[
let g:clipboard = {
\ 'name': 'osc-copy',
\ 'copy': {
\ '+': 'osc copy',
\ '*': 'osc copy',
\ },
\ 'paste': {
\ '+': 'osc paste',
\ '*': 'osc paste',
\ },
\ 'cache_enabled': 0,
\ }
]])
N.B. Neovim 0.10 introduced native support for OSC52, so this may not be needed. See the Neovim documentation.
- ojroques/vim-ocsyank - inspiration and introduction to OSC52
- rumpelsepp/oscclip - working python implementation
- gdamore/tcell - terminal handling