shcopy
shcopy copied to clipboard
📋 Copy text to your system clipboard locally and remotely using ANSI OSC52 sequence
shcopy
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.
Example
# 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
Installation
Go Install
go install github.com/aymanbagabas/shcopy@latest
Homebrew
brew install aymanbagabas/tap/shcopy
Debian/Ubuntu
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
Fedora
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
Arch Linux
yay -S shcopy-bin
Scoop (Windows)
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.
Supported Terminals
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 |
[^1]: Originally copied from vim-oscyank
Tmux
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-clipboardoption was added in tmux 1.5 with a default ofon; the default was changed toexternalwhenexternalwas added in tmux 2.6. Settingset-clipboardtoonallows external programs in tmux to access the clipboard. To enable this option, addset -s set-clipboard onto your tmux config. -
Use
--term tmuxoption to force shcopy to work with tmux. This option requires theallow-passthroughoption to be enabled in tmux. Starting with tmux 3.3a, theallow-passthroughoption 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 tmuxoption won't work unless you're running an older version of tmux or you have enabledallow-passthroughin 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.
Credits
This project is built on top of go-osc52, based on vim-oscyank.