Skip to content

rguziy/2clip

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

📋 2clip.sh

Copy file contents or command output to your clipboard over SSH via OSC 52 — no daemons, no port forwarding, no nonsense.

⚙️ How it works

OSC 52 is a terminal escape sequence that instructs your terminal emulator to place data into the system clipboard. This works over SSH without any additional tools, daemons, or port forwarding — the terminal receives the escape sequence and handles the clipboard access locally on your machine.

🖥️ Requirements

Your terminal emulator must support OSC 52. Standard PuTTY does not support it.

Recommended alternatives:

  • 🪟 KiTTY — a PuTTY fork with OSC 52 support (Windows)
  • 🚀 Alacritty — cross-platform, OSC 52 enabled by default
  • 🌊 WezTerm — cross-platform, OSC 52 enabled by default
  • 🍎 iTerm2 — macOS, OSC 52 enabled by default
  • 🐧 foot — Linux/Wayland

📦 Installation

curl -O https://raw.githubusercontent.com/rguziy/2clip/master/2clip.sh
chmod +x 2clip.sh
sudo mv 2clip.sh /usr/local/bin/2clip

Or clone the repo:

git clone https://github.com/rguziy/2clip.git
chmod +x 2clip/2clip.sh
sudo ln -s "$PWD/2clip/2clip.sh" /usr/local/bin/2clip

🚀 Usage

📄 Copy a file:

2clip file.txt

🔗 Copy command output (pipe / stdin):

ls -la | 2clip
cat /etc/hosts | 2clip
grep "error" app.log | 2clip

⚡ Copy command output (inline via -c):

2clip -c "ps aux | grep nginx"
2clip -c "cat file.txt | sort | uniq"

🪟 tmux configuration

tmux intercepts terminal escape sequences by default, which breaks OSC 52 passthrough. Add the following to your ~/.tmux.conf:

# Use 256-color terminal
set -g default-terminal "screen-256color"

# Enable true color and OSC 52 clipboard passthrough
set -as terminal-overrides ',xterm-256color:Tc:Ms'
set -s set-clipboard on

After editing, reload the config:

tmux source-file ~/.tmux.conf

⌨️ Optional: vi-style copy mode bindings

If you use tmux copy mode, you can bind y to copy the selection to clipboard:

# Use vi-style keybindings in copy mode
setw -g mode-keys vi

# Press 'y' in copy mode to copy selection and exit
bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel

📄 License

MIT

About

Copy file contents or command output to your clipboard over SSH via OSC 52 — no daemons, no port forwarding, no nonsense.

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages