Shell Copy is a simple utility that copies text to the clipboard from anywhere using ANSI OSC52 sequence. It works with local terminals (/dev/tty*) and remote terminals (SSH, Telnet).
Think of this as a tool like xclip
or pbcopy
but also works over SSH.
# Copy text to clipboard
shcopy "Hello World"
# Copy text to primary clipboard (X11)
shcopy -p "Hello World"
# Copy command output to clipboard
echo -n "Hello World" | shcopy
# Copy file content to clipboard
shcopy < file.txt
# Copy from stdin until EOF
# Ctrl+D to finish
shcopy
# Need help?
shcopy --help
go install github.com/aymanbagabas/shcopy@latest
brew install aymanbagabas/tap/shcopy
echo 'deb [trusted=yes] https://repo.aymanbagabas.com/apt/ /' | sudo tee /etc/apt/sources.list.d/aymanbagabas.list
sudo apt update && sudo apt install shcopy
echo '[aymanbagabas]
name=Ayman Bagabas
baseurl=https://repo.aymanbagabas.com/yum/
enabled=1
gpgcheck=0' | sudo tee /etc/yum.repos.d/aymanbagabas.repo
sudo yum install shcopy
yay -S shcopy-bin
nix-shell -p nur.repos.aymanbagabas.shcopy
scoop bucket add aymanbagabas https://github.com/aymanbagabas/scoop-bucket.git
scoop install aymanbagabas/shcopy
You can also download the latest binaries and packages from the releases page.
This is a non-exhaustive list of the status of popular terminal emulators regarding OSC52 1:
Terminal | OSC52 support |
---|---|
Alacritty | yes |
foot | yes |
GNOME Terminal (and other VTE-based terminals) | not yet |
hterm (Chromebook) | yes |
iTerm2 | yes |
kitty | yes |
Konsole | not yet |
QTerminal | not yet |
screen | yes |
st | yes (but needs to be enabled, see here) |
Terminal.app | no, but see workaround |
tmux | yes |
Windows Terminal | yes |
rxvt | yes (to be confirmed) |
urxvt | yes (with a script, see here) |
xterm.js (Hyper terminal) | not yet |
wezterm | yes |
To use shcopy within a tmux session, make sure that the outer terminal supports OSC 52, and use one of the following options:
-
Configure tmux to allow programs to access the clipboard (recommended). The tmux
set-clipboard
option was added in tmux 1.5 with a default ofon
; the default was changed toexternal
whenexternal
was added in tmux 2.6. Settingset-clipboard
toon
allows external programs in tmux to access the clipboard. To enable this option, addset -s set-clipboard on
to your tmux config. -
Use
--term tmux
option to force shcopy to work with tmux. This option requires theallow-passthrough
option to be enabled in tmux. Starting with tmux 3.3a, theallow-passthrough
option is no longer enabled by default. This option allows tmux to pass an ANSI escape sequence to the outer terminal by wrapping it in another special tmux escape sequence. This means the--term tmux
option won't work unless you're running an older version of tmux or you have enabledallow-passthrough
in tmux. Add the following to your tmux config to enable passthroughset -g allow-passthrough on
.
Refer to https://github.com/tmux/tmux/wiki/Clipboard for more info.
This project is built on top of go-osc52, based on vim-oscyank.
Footnotes
-
Originally copied from vim-oscyank β©