-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f89f7df
Showing
3 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# remote pbcopy for iTerm2 | ||
|
||
`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. | ||
|
||
## Install | ||
|
||
First install the iTerm2 which | ||
[removes the limit for OSC 52](https://code.google.com/p/iterm2/issues/detail?id=1428) from: | ||
|
||
http://iterm2.com/downloads.html (maybe naightly builds) | ||
|
||
Then just copy `pbcopy` to a directory where `$PATH` is set. | ||
|
||
[remote] $ wget https://raw.githubusercontent.com/shoichikaji/remote-pbcopy-iterm2/master/pbcopy | ||
[remote] $ chmod +x pbcopy | ||
[remote] $ mv pbcopy /path/to/bin/ | ||
|
||
And make sure to check "Allow clipboard access to terminal apps" in iTerm2 Preferences: | ||
|
||
 | ||
|
||
## Usage | ||
|
||
Just as the ordinal `pbcopy`: | ||
|
||
[remote] $ data | pbcopy | ||
|
||
[local] $ pbpaste | ||
Sun Jan 18 20:28:03 JST 2015 | ||
|
||
## See also | ||
|
||
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 | ||
|
||
For iTerm2's "The issue with OSC 52 only reading the first 1024 chars has been fixed": | ||
|
||
* https://code.google.com/p/iterm2/issues/detail?id=1428 | ||
|
||
## Author | ||
|
||
Shoichi Kaji |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#!/usr/bin/env perl | ||
use strict; | ||
use warnings; | ||
use MIME::Base64 qw(encode_base64); | ||
|
||
my $input = do { local $/; <> } || ""; | ||
$input =~ s/\n+\z//sm; | ||
$input or exit; | ||
|
||
my $b = "\\"; # 1 backslash, not 2 | ||
# escape sequences taken from http://qiita.com/kefir_/items/515ed5264fce40dec522 | ||
my %format = ( | ||
normal => "\e]52;;%s\e$b", | ||
tmux => "\ePtmux;\e\e]52;;%s\e\e$b$b\e$b", | ||
screen => "\eP\e]52;;%s\x07\e$b", | ||
); | ||
|
||
my $format = sub { | ||
if (my $tmux = $ENV{TMUX}) { | ||
# check tmux -CC | ||
(undef, my $pid) = split /,/, $tmux, 3; | ||
if ($pid and open my $fh, "<", "/proc/$pid/cmdline") { # works only in linux | ||
(undef, my $option) = split /\0/, scalar(<$fh>), 3; | ||
if ($option && $option eq "-CC") { | ||
return $format{normal}; | ||
} | ||
} | ||
$format{tmux}; | ||
} elsif ( ($ENV{TERM} || "") eq "screen" ) { | ||
$format{screen}; | ||
} else { | ||
$format{normal}; | ||
} | ||
}->(); | ||
|
||
printf $format, encode_base64($input, ""); | ||
|
||
__END__ | ||
=head1 NAME | ||
pbcopy - remote pbcopy for iTerm2 | ||
=head1 SYNOPSIS | ||
[remote] $ echo "copy to clipboard from remote!" | pbcopy | ||
[local] $ pbcopy | ||
copy to clipboard from remote! | ||
=head1 SEE ALSO | ||
=over 4 | ||
=item * http://doda.b.sourceforge.jp/2011/12/15/tmux-set-clipboard/ | ||
=item * http://qiita.com/kefir_/items/1f635fe66b778932e278 | ||
=item * http://qiita.com/kefir_/items/515ed5264fce40dec522 | ||
=back | ||
=head1 AUTHOR | ||
Shoichi Kaji | ||
=cut |