pbcopy
is a well-known MacOSX tool that copy data to the clipboard.
It's very useful, but available only in your local machine, not in remote machines.
Fortunately, with OSC52 escape sequence, we can access the local machine clipboard via a remote machine.
I prepared a simple perl script that is pbcopy
for remote machines.
-
First, make sure you use iTerm2 version 3.0.0 or later.
-
Copy
pbcopy
to a directory where$PATH
is set.[local] $ ssh remote [remote] $ wget https://raw.githubusercontent.com/skaji/remote-pbcopy-iterm2/master/pbcopy [remote] $ chmod +x pbcopy [remote] $ mv pbcopy /path/to/bin/
-
Check "Allow clipboard access to terminal apps" in iTerm2 Preferences:
Just like the normal pbcopy
:
[local] $ ssh remote
[remote] $ data | pbcopy
[remote] $ exit
[local] $ pbpaste
Sun Jan 18 20:28:03 JST 2015
Currently iTerm2 does not allow OSC 52 read access for security reasons. But we can just use command+V key to paste content from clipboard.
If you want to save the content of clipboard to a remote file, try this:
[remote] cat > out.txt
# press command+V to paste content of clipboard,
# and press control+D which indicats EOF
For OSC52
- http://doda.b.sourceforge.jp/2011/12/15/tmux-set-clipboard/
- http://qiita.com/kefir_/items/1f635fe66b778932e278
- http://qiita.com/kefir_/items/515ed5264fce40dec522
- https://chromium.googlesource.com/apps/libapps/+/HEAD/hterm/etc/osc52.vim
- https://chromium.googlesource.com/apps/libapps/+/HEAD/hterm/etc/osc52.el
- https://chromium.googlesource.com/apps/libapps/+/HEAD/hterm/etc/osc52.sh
Shoichi Kaji
This software is licensed under the same terms as Perl.