Home

Awesome

shcopy

<p> <a href="https://github.com/aymanbagabas/shcopy/actions"><img src="https://github.com/aymanbagabas/shcopy/workflows/build/badge.svg" alt="Build Status"></a> <a href="https://github.com/aymanbagabas/shcopy/releases"><img src="https://img.shields.io/github/release/aymanbagabas/shcopy.svg" alt="Latest Release"></a> </p>

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

Nix NUR

nix-shell -p nur.repos.aymanbagabas.shcopy

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:

TerminalOSC52 support
Alacrittyyes
footyes
GNOME Terminal (and other VTE-based terminals)not yet
hterm (Chromebook)yes
iTerm2yes
kittyyes
Konsolenot yet
QTerminalnot yet
screenyes
styes (but needs to be enabled, see here)
Terminal.appno, but see workaround
tmuxyes
Windows Terminalyes
rxvtyes (to be confirmed)
urxvtyes (with a script, see here)
xterm.js (Hyper terminal)not yet
weztermyes

Tmux

To use shcopy within a tmux session, make sure that the outer terminal supports OSC 52, and use one of the following options:

  1. Configure tmux to allow programs to access the clipboard (recommended). The tmux set-clipboard option was added in tmux 1.5 with a default of on; the default was changed to external when external was added in tmux 2.6. Setting set-clipboard to on allows external programs in tmux to access the clipboard. To enable this option, add set -s set-clipboard on to your tmux config.

  2. Use --term tmux option to force shcopy to work with tmux. This option requires the allow-passthrough option to be enabled in tmux. Starting with tmux 3.3a, the allow-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 enabled allow-passthrough in tmux. Add the following to your tmux config to enable passthrough set -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.

Footnotes

  1. Originally copied from vim-oscyank